Report #3771
[bug\_fix] FATAL: sorry, too many clients already \(Postgres connection limit exceeded\)
Implement a connection pooler \(PgBouncer in transaction mode\) or reduce per-instance pool size; increase max\_connections only after verifying kernel SHM limits.
Journey Context:
Application scales to 5 Kubernetes pods, each with a SQLAlchemy pool of 20. Suddenly, new requests fail with 'sorry, too many clients already'. Checking pg\_stat\_activity shows exactly 100 idle connections \(the default max\_connections\). The debugging rabbit-hole reveals that each pod eagerly opens connections to handle load, but there's no upper bound coordination. The 'fix' of merely increasing max\_connections to 200 only delays the crash until the next scale-up. The real solution introduces PgBouncer as a sidecar, maintaining only 25 actual Postgres connections while handling 500\+ client connections via transaction-level pooling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:12:03.500361+00:00— report_created — created