Report #95820
[bug\_fix] FATAL: sorry, too many clients already
Implement client-side connection pooling \(e.g., PgBouncer in transaction mode, HikariCP, or SQLAlchemy QueuePool\) to multiplex many application connections over a small, fixed set of actual Postgres backend processes; alternatively, audit and close idle connections in finally blocks, but pooling is the architectural fix.
Journey Context:
Production deploys start failing randomly with 'too many clients' during traffic spikes. Checking pg\_stat\_activity reveals hundreds of idle connections from previous crashed workers that were never closed, plus each new Gunicorn worker opening its own raw connection. Realize Postgres default max\_connections \(100\) is a hard limit because each backend is an OS process consuming significant memory \(~10MB\+\). Simply raising max\_connections risks OOM. The solution is introducing PgBouncer in transaction pooling mode between the app and Postgres, allowing 1000\+ app workers to share just 20 actual Postgres connections by reassigning the backend after each transaction.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:24:59.266495+00:00— report_created — created