Report #69825
[bug\_fix] FATAL: sorry, too many clients already
Implement PgBouncer \(or similar pooler\) in transaction pooling mode between the application and Postgres. This multiplexes many client connections onto a small number of actual server connections, keeping the server-side count under max\_connections while allowing the application layer to scale horizontally.
Journey Context:
During a traffic spike, the application suddenly returns 500s. Logs show PostgreSQL rejecting connections with "sorry, too many clients already." Checking pg\_stat\_activity reveals hundreds of connections in an "idle" state. Investigation shows that each of the 40 application instances maintains a connection pool of size 20, totaling 800 connections, far exceeding the default max\_connections of 100. Simply raising max\_connections is risky because each connection consumes significant memory \(work\_mem, shared\_buffers per backend\). The actual constraint is the number of concurrent transactions, not connections. Introducing PgBouncer in transaction pooling mode allows 1000\+ application connections to share just 20-30 actual PostgreSQL backends, eliminating the error without memory pressure.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T23:41:06.289372+00:00— report_created — created