Postgres error 53300: too many connections
sorry, too many clients already / remaining connection slots are reserved
The server has reached max_connections and refused a new connection.
Common causes
- Serverless functions or many app instances each opening their own pool.
- Connection leaks: connections taken from a pool and never returned.
- Idle sessions left open by tools and notebooks.
How to fix it
- Put a connection pooler in front of the database and connect through it, or use an HTTP driver from serverless code.
- Lower the pool size per instance; total = instances x pool size must stay under the limit.
- Find idle sessions: select pid, usename, application_name, state, state_change from pg_stat_activity order by state_change;
Through a REST API
PostgREST, the REST layer behind supabase-js and Scribase, answers HTTP 503 for this error and returns the SQLSTATE in the code field of the JSON error body. Through PostgREST this shows as 503.
Questions
What does Postgres error 53300 mean?
53300 is too_many_connections in class 53 (Insufficient Resources). The server has reached max_connections and refused a new connection.
How do I fix 53300?
Put a connection pooler in front of the database and connect through it, or use an HTTP driver from serverless code. Lower the pool size per instance; total = instances x pool size must stay under the limit. Find idle sessions: select pid, usename, application_name, state, state_change from pg_stat_activity order by state_change;
What HTTP status does a REST API return for 53300?
PostgREST, the REST layer behind supabase-js, answers 503.