PostgreSQL · error reference
PostgreSQL: sorry, too many clients already
FATAL: sorry, too many clients already
Every connection slot is taken. Usually not by work, but by idle connections that application pools opened and never gave back.
What the database is telling you
SQLSTATE 53300 (too_many_connections). The server has max_connections slots (100 by default), a few reserved for superusers; once the rest are used, new connections are refused with this message, or with "remaining connection slots are reserved for non-replication superuser connections" when only the reserved ones are left. Each PostgreSQL connection is a process with its own memory, which is why the limit is low.
Why it shows up in a migration
A migration opens connections of its own — often several, to copy tables in parallel — on top of everything the application already holds. A server running near its limit tips over the moment the migration starts.
Common causes
- Application connection pools sized for peak load holding idle connections.
- Connections left "idle in transaction" by code that never committed.
- Several services, cron jobs or serverless functions each opening their own connections.
- max_connections set low for the server size, or a managed plan with a small connection cap.
How to fix it
- 1
See who holds the connections and in what state.
SELECT usename, application_name, state, count(*) FROM pg_stat_activity GROUP BY 1, 2, 3 ORDER BY 4 DESC;
- 2
End connections that have sat idle for ten minutes (needs a superuser or pg_signal_backend).
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE state = 'idle' AND state_change < now() - interval '10 minutes';
- 3
Stop the leak at the source: time out sessions idle inside a transaction.
ALTER SYSTEM SET idle_in_transaction_session_timeout = '5min'; SELECT pg_reload_conf();
- 4
Put a pooler (PgBouncer, or your provider's) in front of the database rather than raising max_connections — each extra slot costs memory on every connection.
What DBShifts does about it
Connection diagnosis reports this as the database being out of connection slots, with the hint to free some or raise the limit. Airlock keeps one pooled connector per connection, closes it after five idle minutes, and stops trying for a cool-down when connections keep failing, instead of piling more on.
Connection diagnosis · gateway connection pool
Connecting a database?
Add the database to DBShifts and the connection is tested on the spot. If it fails, you get which of these errors it is and what to change — not the driver's raw message. Once it connects, browse it, migrate it, or let an AI agent read it through the gateway with sensitive columns masked.