Report #89897
[bug\_fix] FATAL: sorry, too many clients already \(SQLSTATE 53300\)
Implement external connection pooling \(PgBouncer in transaction mode\) or carefully increase max\_connections. The root cause is unbounded client connections \(often from connection leaks or horizontal scaling\) exhausting PostgreSQL's backend process limit \(default 100\), where each connection consumes significant shared memory.
Journey Context:
A production deploy with 20 Kubernetes pods begins throwing 500s immediately. Logs reveal 'sorry, too many clients already'. Investigating pg\_stat\_activity shows 100 connections, most idle from previous pod instances that didn't close properly. Each app instance configured for 10 connections, requiring 200 total, but max\_connections is 100. Raising the limit risks shared memory exhaustion and kernel limits. The working fix installs PgBouncer as a sidecar, configured for transaction pooling with default\_pool\_size=20. Now 200 app instances share just 20 actual Postgres connections. Errors cease because PgBouncer multiplexes application connections onto a bounded set of database backends without exhausting the server's max\_connections limit.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T09:29:12.371821+00:00— report_created — created