Report #26657
[bug\_fix] FATAL: sorry, too many clients already
Implement connection pooling using PgBouncer \(preferably in transaction mode\) or an application-side pool \(e.g., HikariCP, SQLAlchemy pool\). Do not simply raise max\_connections, as each connection forks a backend process consuming shared memory \(~10MB\+\), quickly exhausting kernel resources. The pool reuses a small, fixed number of physical connections across many application threads.
Journey Context:
Deployed a new microservice with 30 pods, each configured with a connection pool of size 10. Under moderate load, the application suddenly started throwing FATAL errors. Checking pg\_stat\_activity revealed 300\+ connections in idle state, many from old deployments that hadn't fully terminated. The default max\_connections was 100, so new pods were rejected. Increasing max\_connections to 500 was rejected by the OS due to shmmax limits. The real fix was introducing PgBouncer in transaction mode, reducing the active physical connections to 20 while supporting 1000\+ application threads.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:08:29.981152+00:00— report_created — created