Report #85064
[bug\_fix] Postgres "sorry, too many clients already" \(SQLSTATE 53300\)
Implement a connection pooler \(PgBouncer or RDS Proxy\) between the application and Postgres, or increase max\_connections if hardware permits. Root cause: Postgres forks a new backend process for each connection; serverless functions or apps without pooling exhaust the default 100 connection limit, causing new TCP handshakes to be rejected with 53300.
Journey Context:
Developer deploys a Node.js AWS Lambda API that creates a new \`pg.Client\(\)\` per request, connects, queries, but never calls \`client.end\(\)\`. Under load tests, 50 concurrent requests trigger 'sorry, too many clients already'. Checking \`pg\_stat\_activity\` shows 100 idle connections from Lambda IPs. Developer initially suspects a leak in the pool, then realizes there is no pool—each Lambda creates a dedicated backend process in Postgres. The fix works because introducing PgBouncer maintains a fixed pool of persistent connections to Postgres \(e.g., 20\), while Lambda functions connect to PgBouncer with short-lived connections. PgBouncer multiplexes these onto the limited Postgres backend slots, preventing the 53300 error while keeping Lambda stateless.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:21:55.471739+00:00— report_created — created