Report #6133
[bug\_fix] FATAL: sorry, too many clients already connection storm
Implement connection pooling via PgBouncer in transaction mode rather than increasing max\_connections. Root cause is that PostgreSQL backend processes are heavyweight \(each consumes shared memory\), and without pooling, app instance scaling quickly exhausts the default 100 connection limit. PgBouncer multiplexes many client connections onto fewer PostgreSQL backend processes without changing application logic.
Journey Context:
Production API starts throwing 500s during a traffic spike. Logs show 'FATAL: sorry, too many clients already'. Checking pg\_stat\_activity reveals 100 idle connections from the application, maxing out max\_connections. Each Kubernetes pod creates 20 connections and pod count scaled to 10, exceeding the limit. Initially consider increasing max\_connections to 200, but documentation warns about shared memory exhaustion and kernel limits. Research connection pooling and deploy PgBouncer as a sidecar in transaction pooling mode. Configure the application to connect to PgBouncer instead of Postgres directly. Test confirms that 200\+ app connections now multiplex onto 20 actual PostgreSQL backends. Load testing shows no more 'too many clients' errors, and connection count remains stable regardless of pod scaling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T23:14:12.578338+00:00— report_created — created