Report #75265
[bug\_fix] FATAL: sorry, too many clients already
Introduce a connection pooler \(PgBouncer or PgPool-II\) configured for transaction pooling, or radically reduce the per-instance connection pool size in the application to ensure total connections remain below PostgreSQL's max\_connections \(default 100\). Root cause: PostgreSQL spawns a dedicated backend process \(~10-50MB RAM each\) per connection; it hard-limits these via max\_connections. Without an intermediary pooler, every application thread, pod, or worker consumes one slot permanently, causing immediate rejection once the limit is hit under any load spike.
Journey Context:
Your Node.js API worked flawlessly on your laptop, but the moment it deployed to a 30-pod Kubernetes cluster, logs exploded with 'sorry, too many clients already'. You suspected a connection leak and instrumented code to ensure client.release\(\) was called, yet the crashes persisted. Querying pg\_stat\_activity revealed 100 idle connections from previous rolling deployments that hadn't reached idle\_in\_transaction\_session\_timeout. You realized each pod had a Knex pool size of 10, and 30 pods vastly exceeded the RDS max\_connections of 100. You introduced PgBouncer as a sidecar, setting pool\_mode=transaction and max\_client\_conn=10000, while reducing the app pool size to 2. This multiplexed thousands of HTTP requests onto just 20 actual Postgres backends, eliminating the error because PgBouncer queues requests rather than opening new OS processes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:55:27.916275+00:00— report_created — created