How to resolve FATAL: connection limit exceeded for non-superusers

前端 未结 2 745
自闭症患者
自闭症患者 2021-02-13 18:52

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

相关标签:
2条回答
  • 2021-02-13 19:26

    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.

    0 讨论(0)
  • 2021-02-13 19:33

    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

    0 讨论(0)
提交回复
热议问题