PostgreSQL 53300: too many connections
The server has reached max_connections and refuses new sessions. Usually a connection leak or pools that together open more connections than allowed.
- SQLSTATE
53300- Name
too_many_connections- Category
- Insufficient Resources
What it means
PostgreSQL runs one server process per connection and caps the total with max_connections (100 by default). When every slot is taken, a new connection fails with 53300 before it can log in.
A few slots are kept back for superusers (superuser_reserved_connections, 3 by default) and, on PostgreSQL 16 and later, for roles in pg_use_reserved_connections. Ordinary roles then see remaining connection slots are reserved for roles with the SUPERUSER attribute (the wording varies by version) with the same code. A role or database can also have its own CONNECTION LIMIT, which fails with too many connections for role "app".
Common causes
- An application leaks connections: it opens them and never closes or returns them to the pool.
- Several app instances, each with its own pool, add up to more than
max_connections. - Many sessions sitting
idle in transaction, holding slots and locks. - A traffic spike, or a job that opens one connection per task.
How to fix it
-
See who is connected and what they are doing (connect as a superuser, who can still get in).
SELECT usename, application_name, client_addr, state, count(*) FROM pg_stat_activity GROUP BY 1, 2, 3, 4 ORDER BY count(*) DESC;
-
End sessions that are stuck idle in a transaction or that belong to a runaway client.
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE state = 'idle in transaction' AND state_change < now() - interval '10 minutes';
-
Fix the leak or shrink the pools so their total stays under the limit, and put a pooler such as PgBouncer in front of many small clients.
-
Have the server end abandoned sessions automatically.
ALTER SYSTEM SET idle_in_transaction_session_timeout = '5min'; SELECT pg_reload_conf();
-
Raise
max_connectionsonly if the server has the memory for it; it needs a restart.ALTER SYSTEM SET max_connections = 200; -- takes effect after restart
Questions
How many connections can PostgreSQL handle?
The default max_connections is 100. Each connection is a separate process with its own memory, so hundreds of mostly idle connections are better served by a connection pooler than by a very high max_connections.
Related errors
57P03cannot connect now25P03idle-in-transaction session timeout28000invalid authorization specification1040MySQL: Too many connectionsORA-00018Oracle: maximum number of sessions exceededORA-00020Oracle: maximum number of processes exceeded
More insufficient resources errors
The code and message text are from the PostgreSQL documentation, Appendix A: PostgreSQL Error Codes. Browse the full PostgreSQL error list or search every database error.
Work on PostgreSQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for PostgreSQL and the other databases you use.