Report #27246
[bug\_fix] Postgres FATAL: sorry, too many clients already
Implement an external connection pooler \(PgBouncer in transaction mode\) between the application and PostgreSQL, or strictly limit per-process pool size to 2-5 connections with aggressive idle timeouts. Do not increase max\_connections beyond 200 without extensive memory planning.
Journey Context:
A developer deploys a Node.js API using the pg library without explicit pooling to a Heroku hobby tier. Under light load, requests start failing with 'sorry, too many clients already'. Checking pg\_stat\_activity reveals hundreds of idle connections from the app's IP. The developer realizes each request opens a new Client\(\) without proper pooling or release. They attempt to raise max\_connections to 500, but Postgres memory usage explodes and OOMs. They then learn that Postgres connections are heavy processes. The fix is introducing PgBouncer in transaction mode, which multiplexes many lightweight client connections onto a small pool of actual Postgres backends, or properly configuring pg.Pool with max: 5 and ensuring pool.end\(\) on shutdown.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T00:07:36.174924+00:00— report_created — created2026-06-18T00:23:04.803825+00:00— confirmed_via_duplicate_submission — confirmed