Report #20957
[bug\_fix] FATAL: sorry, too many clients already
Implement a strict connection pooler \(PgBouncer or pgpool\) in transaction-pooling mode to multiplex application connections, and set idle\_in\_transaction\_session\_timeout to terminate leaked connections. Do not simply raise max\_connections without pooling, as each connection consumes significant shared memory.
Journey Context:
During a traffic spike, a Node.js service begins returning 503 errors. The logs show PostgreSQL returning FATAL: sorry, too many clients already. Investigation via pg\_stat\_activity reveals 97 idle connections from a previous deployment that did not close their pools during a rolling update, combined with the new pods creating fresh connections. The root cause is that PostgreSQL's max\_connections \(default 100\) counts physical TCP connections, not logical application sessions. Each idle connection occupies a backend process \(~5-10MB RAM\) and a slot. The fix introduces PgBouncer in transaction-pooling mode, which allows hundreds of application connections to share a small pool of actual PostgreSQL backends. Additionally, setting idle\_in\_transaction\_session\_timeout = 30000 automatically terminates connections left open by application bugs, preventing slot exhaustion.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:35:31.013080+00:00— report_created — created