I have written a java code for bulk insertion. I'm using the copy command for importing and creating different connection objects for different tables, but while executing, the program it is throwing the following errors:

FATAL: connection limit exceeded for non-superusers
  • 2
    My bet is that you are not closing the connections properly from within your Java code. – a_horse_with_no_name Nov 27 '12 at 10:16
  • Are you by chance creating a new connection for every insert? – lawl0r Nov 27 '12 at 10:17

You have exceeded the connection limit of PostgreSQL server. There are some reserved connection for Super user.

To increase the connection limit you have to change the postgresql.conf (default 100) it is located on your PostgreSQL data directory.

cat postgresql.conf | grep max_connection max_connections = 100
        # (change requires restart)
# Note:  Increasing max_connections costs ~400 bytes of shared memory per
# max_locks_per_transaction * (max_connections + max_prepared_transactions)

Increase the limit and restart the PostgreSQL instance.

Warning: increasing the connection limit will affect the memory.

try optimizing connection using connection pooling either in application or db layer. on PostgreSQL you can use Pgpool2.

  • Or you can try killing the connections. – Noumenon Jul 21 '17 at 21:12

Are you using a connection pool? Check if connections are closed properly in your code. This should be done in a try-finally block:

Connection connection = dataSource.getConnection();
try {
    ....
}
finally {
    connection.close();
}

If you really need a large amount of connections, set the max_connections-property in postres accordingly.

Documentation

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.