Report #94380
[bug\_fix] FATAL: sorry, too many clients already
Implement PgBouncer in transaction pooling mode between the application and PostgreSQL, or reduce per-instance connection pool sizes to 2-5 and ensure proper connection cleanup in finally blocks. Do not simply raise max\_connections; this only delays the issue and increases memory usage.
Journey Context:
Developer sees intermittent 500s in a Node.js/Express API deployed on AWS ECS. Logs show 'too many clients' errors. Checking RDS Performance Insights reveals 100 active connections \(the default max\_connections\). The developer realizes there are only 10 ECS tasks, but each task initializes a connection pool of size 20, totaling 200 demanded connections. During rolling deployments, old tasks hold connections while new tasks spawn, exceeding the limit. Additionally, error handlers in the code are missing client.end\(\) calls, causing connections to leak when exceptions occur. The developer initially tries raising max\_connections to 200, but this consumes excessive memory \(shared\_buffers per connection\) and hits AWS RDS instance limits. The correct solution is implementing PgBouncer in transaction mode, which multiplexes hundreds of application connections onto a handful of actual PostgreSQL connections.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:00:09.918276+00:00— report_created — created