Report #39481
[bug\_fix] FATAL: sorry, too many clients already \(Postgres connection limit exceeded\)
Implement PgBouncer in transaction pooling mode to multiplex many application connections over fewer actual Postgres connections, OR properly configure connection pool size \(setting max pool size lower than max\_connections / num\_instances\) with aggressive idle timeout and ensuring connections are released back to pool.
Journey Context:
Developer deploys a Node.js app with 4 workers, each creating a connection pool of size 10. Postgres max\_connections is set to 100. Under load, they start seeing intermittent "sorry, too many clients already" errors. Checking pg\_stat\_activity reveals hundreds of idle connections from analytics tools and zombie connections from previous deploys that weren't properly closed. Initially they consider raising max\_connections, but the docs warn about shared memory exhaustion. They realize the app isn't releasing connections back to the pool on exceptions—connections are leaked until they hit the limit. The rabbit hole leads to discovering that transaction-level connection pooling \(PgBouncer\) is the standard solution for high-concurrency apps, allowing hundreds of app connections to share a much smaller pool of actual Postgres backends.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:44:39.214645+00:00— report_created — created