Back to troubleshooting
troubleshooting#postgres#database#scaling

PostgreSQL: Too Many Connections

The classic Postgres scaling wall — and how PgBouncer solves it.

Jane Contributor August 2, 2026 6 views

Problem

Application errors with `FATAL: sorry, too many clients already` under load.

Step-by-step Solution

  1. 1Check current limit: `SHOW max_connections;` (default 100).
  2. 2See who's connected: `SELECT usename, state, count(*) FROM pg_stat_activity GROUP BY 1,2;`.
  3. 3Kill idle-in-transaction sessions older than 5 minutes with `pg_terminate_backend()`.
  4. 4Introduce **PgBouncer** in transaction pooling mode — one physical connection serves many clients.
  5. 5Set app-side pool size (e.g., HikariCP maximumPoolSize) to a small number like 10–20 per instance.
  6. 6Add `idle_in_transaction_session_timeout = '5min'` to `postgresql.conf`.
  7. 7Monitor with `pg_stat_activity` and alert when connection usage exceeds 70% of the cap.

See problem and step-by-step solution above.

Keep reading

You may also like

Discussion (0)

No comments yet. Be the first to weigh in.

Leave a comment

Comments are reviewed before appearing.