Cookbook recipe

Fix “too many clients already”

Applies to PostgreSQL 13–17 Last reviewed May 2026 Grounded in source
Estimated investigation4 min

Scenario

New connections fail with FATAL: sorry, too many clients already. You hit max_connections. Diagnose it See who is connected and what they are doing: SELECT state, count(*) FROM pg_stat_activity GROUP BY state; SELECT pid, state, query_start,…

Investigation Path

New connections fail with FATAL: sorry, too many clients already. You hit max_connections.

Diagnose it

See who is connected and what they are doing:

SELECT state, count(*) FROM pg_stat_activity GROUP BY state;
SELECT pid, state, query_start, left(query,60)
FROM pg_stat_activity WHERE state <> 'idle' ORDER BY query_start;

Why it happens

Every slot up to max_connections is in use — often by idle or idle-in-transaction connections that an app forgot to release, or simply too many direct app connections.

This is a Pro lesson

Get every Learning Pathway and cookbook recipe — grounded in PostgreSQL source code, with diagnostics, fixes, and prevention for each topic.

Continue this lesson to learn:

  • How to fix it
  • Prevent it next time
  • Related & next steps
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Career Impact

This scenario builds production judgment and operational confidence under pressure.

Open Career Dashboard →

Keep going

Related & next steps

Was this helpful?

← All cookbook recipes