Report #54262
[bug\_fix] FATAL: sorry, too many clients already
Implement a connection pooler \(PgBouncer in transaction mode\) between the application and PostgreSQL, or reduce the per-process connection pool size to ensure the aggregate does not exceed max\_connections; only increase max\_connections as a last resort with proportional increases to shared\_buffers and kernel SHMMAX.
Journey Context:
The application performs flawlessly in local development with a single Gunicorn worker, but immediately after deploying to production with 20 workers, it intermittently crashes with 'sorry, too many clients already' under moderate load. Inspecting pg\_stat\_activity reveals 200 idle connections originating from the app, exhausting the default max\_connections of 100. Realizing that each worker initializes a connection pool of 10 direct connections to PostgreSQL, the aggregate demand far outstrips supply. Introducing PgBouncer in transaction mode multiplexes hundreds of client connections onto a stable pool of 20 actual PostgreSQL connections, resolving the saturation without requiring risky increases to 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-19T21:34:40.325035+00:00— report_created — created