too many clients already, remaining slots reserved for superuser
I have a production deployment where I'm facing this issue. I ran
SELECT count(*) FROM pg_stat_activity and noticed that there are indeed 100 connections which is the max. However, I noticed most of them are idle. Temporarily I've increased the max_connections to 500. I have couple of questions to which I'm not getting straightforward answers:- Why are there so many idle connections? I understand if there are many active connections. But why idle?
- If there are that many idle connections, shouldn't the connection pool of postgres.js kick in as it says here (https://github.com/porsager/postgres?tab=readme-ov-file#the-connection-pool) that the previous open connection will be used? So my understanding is that the idle connections will be made active with the new queries. Why isn't that happening?
- Will I have to manually set the
idle_timeoutandmax_lifetimevalues to lower and optimal values for my use case to get rid of idle connections? - Along with the increasing
max_connections, should I increase anything else? Do I need something likepg_bouncerand how would that help?
GitHub
Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare - porsager/postgres