too many connections for database “…”
Symptoms
A database hit its per-database connection limit set by ALTER DATABASE … CONNECTION LIMIT. PostgreSQL refuses the new connection with SQLSTATE 53300 (too_many_connections).
- The database’s active connections reached its CONNECTION LIMIT.
- New connections to that database are rejected.
- Other databases may still accept connections.
What the server log shows
FATAL: too many connections for database "appdb"
Why PostgreSQL raises this — what the manual says
As the ALTER DATABASE reference (Parameters) explains:
The database has reached the maximum number of concurrent connections set by its CONNECTION LIMIT (ALTER DATABASE name CONNECTION LIMIT n); raise the limit or wait for open sessions to close.
Each database can carry a per-database cap on concurrent connections. When that database’s active connection count reaches the cap, PostgreSQL rejects further logins to it with 53300, regardless of the cluster-wide limit.
Common causes
- The database’s CONNECTION LIMIT is set too low.
- Connection leaks or too many concurrent clients.
- Multiple apps sharing one database without pooling.
Relevant GUC parameters
| Parameter | Default | Effect |
|---|---|---|
max_connections |
100 | Cluster-wide cap; the per-database limit applies on top of it. |
How to fix it
- Raise the limit:
ALTER DATABASE appdb CONNECTION LIMIT 300;. - Introduce a connection pooler to bound connections.
- Fix leaks and right-size pool sizes per service.
Diagnostic query
SELECT datname, datconnlimit FROM pg_database WHERE datname = 'appdb';
Compare against current connections: SELECT count(*) FROM pg_stat_activity WHERE datname = 'appdb';
Related & next steps
Reference: PostgreSQL 18 — ALTER DATABASE.