Report #24437
[bug\_fix] FATAL: sorry, too many clients already \(PostgreSQL connection limit exhaustion\)
Implement connection pooling \(PgBouncer in transaction mode or RDS Proxy\) to multiplex application connections onto a smaller fixed pool of actual PostgreSQL backend processes; avoid simply raising max\_connections because each connection consumes significant shared memory \(tens of MB\) and OS resources.
Journey Context:
Production web app using Puma with 50 workers starts throwing 500s. Logs show 'FATAL: sorry, too many clients already'. Developer checks pg\_stat\_activity and sees 500 idle connections from app servers, hitting the default max\_connections \(100\). Attempts to increase max\_connections to 1000 in postgresql.conf, but PostgreSQL fails to start due to shared memory limits \(shmmax\), and documentation warns that >200 connections degrades performance due to context switching. Realizes each Puma worker holds a persistent connection open even when idle. Implements PgBouncer in transaction mode between the app and PostgreSQL, configuring the pool to maintain only 20 actual PostgreSQL connections while serving the 500\+ application workers. Connections now multiplex efficiently, eliminating the error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:25:34.812634+00:00— report_created — created