Report #16045
[bug\_fix] FATAL: sorry, too many clients already
Implement external connection pooling \(PgBouncer in transaction mode or RDS Proxy\) rather than raising max\_connections. Root cause: Each application instance opens a direct connection to Postgres, and the cumulative count exceeds the server's max\_connections \(default 100\). Pooling multiplexes many application threads onto a small, fixed set of actual database connections.
Journey Context:
The platform scales horizontally to 50 microservice instances, each configured with a connection pool of 20. Immediately after the 6th instance deploys, the app crashes with 'sorry, too many clients already'. The developer raises max\_connections to 500, but the container OOMs because each backend process consumes shared memory. They analyze pg\_stat\_activity and realize the math: 50 containers × 20 connections = 1000, far exceeding any reasonable max\_connections. After researching, they introduce PgBouncer as a sidecar. By switching PgBouncer to transaction pooling mode, 1000 application threads now share just 20 actual database connections. The connection count stays flat regardless of app scale, eliminating the error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:44:26.243137+00:00— report_created — created