Report #25421
[bug\_fix] FATAL: sorry, too many clients already
Implement PgBouncer in transaction pooling mode or increase max\_connections \(limited by kernel SHMMAX\), but fundamentally the app must close connections properly or use a pool. Root cause is each backend process consumes ~2-10MB shared memory; exhausting max\_connections \(default 100\) blocks new TCP handshakes.
Journey Context:
Production API starts returning 500s at 09:00 UTC daily. Logs show "FATAL: sorry, too many clients already". Checking pg\_stat\_activity reveals 97 idle connections from a stale Celery worker pool that wasn't terminated during a hot-reload. The application used SQLAlchemy with pool\_size=20 but max\_overflow=0, and gunicorn max\_requests=1000 with 8 workers, but warm shutdowns weren't closing connections before forking new workers, leaking connections until the 100 connection hard limit was hit.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T21:04:38.379056+00:00— report_created — created