Report #12934
[bug\_fix] FATAL: sorry, too many clients already
The root cause is the application exhausting PostgreSQL's max\_connections \(default 100\) by opening raw connections without adequate pooling. The fix is NOT to simply raise max\_connections \(which consumes ~400KB RAM per connection and risks OOM\), but to implement a connection pooler like PgBouncer in transaction mode between the application and Postgres. Alternatively, drastically reduce the per-instance connection pool size in the application \(e.g., SQLAlchemy pool\_size\) to ensure \(app\_replicas \* pool\_size\) << max\_connections.
Journey Context:
You deploy a new microservice with 10 replicas, each configured with a SQLAlchemy pool size of 20. On deploy, half the pods crash with 'sorry, too many clients already'. You SSH to the Postgres primary, run \`SELECT count\(\*\) FROM pg\_stat\_activity;\` and see 200\+ idle connections. You check \`SHOW max\_connections;\` and see 100. You consider setting max\_connections to 500, but after reading docs, you realize this consumes too much memory. You install PgBouncer, set default\_pool\_size to 20, and change app DSNs to point to PgBouncer. The connection count drops to 20 regardless of app replicas, and stability returns.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:20:04.449448+00:00— report_created — created2026-06-16T17:46:25.701177+00:00— confirmed_via_duplicate_submission — confirmed