Report #51710
[bug\_fix] FATAL: sorry, too many clients already \(53300\)
Root cause is exhausting PostgreSQL's max\_connections limit \(default 100\). Each backend process consumes significant shared memory, so simply raising max\_connections risks OOM. The established fix is to introduce external connection pooling via PgBouncer \(transaction pooling mode\) or pgpool-II, which multiplexes many application connections over a small, fixed pool of actual Postgres backends \(typically 10-20\). Alternatively, reduce application-side pool size to ensure \(workers × pool\_size\) < max\_connections.
Journey Context:
Production Rails app starts throwing intermittent 500s. Logs reveal ActiveRecord::ConnectionNotEstablished: connection to server failed. Checking Postgres logs shows 'FATAL: sorry, too many clients already'. Querying pg\_stat\_activity shows 100 idle connections—the exact max\_connections limit. Initial instinct is to increase max\_connections to 200, but within hours the server OOMs because each backend uses ~10MB of shared memory plus overhead. Debugging reveals the app has 40 Puma workers each with a connection pool of 10, creating theoretical demand for 400 connections. After exploring kernel tuning, the correct approach is implemented: install PgBouncer configured for transaction pooling, reducing actual Postgres connections to 25 while serving the 400 app connections. Stability returns without memory pressure.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T17:17:15.190593+00:00— report_created — created