too many connections for database “…”

SQLSTATE 53300 condition too_many_connections class 53 — Insufficient Resources severity FATAL
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.

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).

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

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

  1. Raise the limit: ALTER DATABASE appdb CONNECTION LIMIT 300;.
  2. Introduce a connection pooler to bound connections.
  3. 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.