I have 500 connection in my 3 node PostgreSQL cluster. But sometimes I found error like "too many clients already" Why it show too many client connection? How does it calculate too many client connection? RAM=8GB CPU=8 SWAP=16GB max_connection=500 but most of the time active connection is like 10-13. Idle connection like 480 to 490 and others 5 connection.

As per my understanding if active_connection+idle_connecton+other_reserve_connection>500 then it show too many client connection. If I am wrong please correct me.

In that case instantly how can I solve it? Should I try below command to terminate current idle process?

SELECT pg_terminate_backend(pid) FROM pg_stat_activity
WHERE datname = 'databasename'
AND pid <> pg_backend_pid()
AND state in ('idle'); 

Is there any better solution than that? If you have any other way to solve this issue please lest me know. Need expert opinion. Thanks In Advance.

  • error message is: too many client connection Commented Sep 18, 2022 at 17:26
  • That is not an error message PostgreSQL will generate. It must be coming from your client.
    – jjanes
    Commented Sep 18, 2022 at 18:51
  • Use a connection pool and define its size limit much smaller than that. Commented Sep 19, 2022 at 4:16
  • Yes I am using pgpool. It is about 400(num_init_children) but what should be the amount. Is there any formula such as 80% of max_connection of database? If I set idle_in_transaction_session_timeout=2min at database is there any benefit to get ride from this issue? Commented Sep 19, 2022 at 9:12


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.