Report #78647
[bug\_fix] FATAL: sorry, too many clients already
Implement a connection pooler \(PgBouncer\) in transaction mode to multiplex many application connections over fewer actual PostgreSQL connections, or reduce the per-application connection pool size to ensure total across all instances stays under max\_connections \(default 100\). Root cause: Each application instance was opening 25 connections with a pool size of 25, and with 4 instances, this exceeded the 100 connection limit, compounded by connections not being properly released to the pool during exceptions.
Journey Context:
Deployed a Node.js application to production with 4 instances, each configured with a database pool size of 25. Initially, everything worked fine, but as traffic increased, sporadic connection errors appeared: 'sorry, too many clients already'. Checking pg\_stat\_activity revealed 100 active connections, most in 'idle' state. The developers suspected a PostgreSQL configuration issue and considered raising max\_connections to 1000, but this risked exhausting kernel shared memory. Upon reviewing application logs, they noticed that during unhandled API errors, the connection release was skipped in the catch block, causing a gradual leak. The final realization was that even with perfect connection hygiene, 4 instances × 25 connections = 100, leaving no headroom for administrative connections or brief spikes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T14:36:07.012895+00:00— report_created — created