PostgreSQL 17.12Lab-verified · 2026-11-30

PostgreSQL 53300: too many connections for role

The role or database already has as many connections as its CONNECTION LIMIT allows.

PostgreSQL 17.12
53300: too many connections for role "app_user"

Jump to a cause

  1. 01The role has CONNECTION LIMIT and its sessions are all in use
  2. 02The database has CONNECTION LIMIT

Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-11-30 · container image postgres:17

SQLSTATE 53300 is too_many_connections. When a role or database has a CONNECTION LIMIT, the next connection over that limit fails at login with FATAL: too many connections for role "app_user" or FATAL: too many connections for database "shop".

We reproduced both on PostgreSQL 17 with two sessions: session A stays connected, session C shows the open connections in pg_stat_activity, and session B's new connection is refused. psql does not print the SQLSTATE for connection failures, so the server log line from the same moment is shown below the output. The same code is also used for sorry, too many clients already (server-wide max_connections), which is not reproduced on this page.

01The role has CONNECTION LIMIT and its sessions are all in use

app_user was created with CONNECTION LIMIT 1. While session A is connected, pg_stat_activity shows 1 connection for app_user, and session B is refused with too many connections for role "app_user". A connection pool or a few forgotten idle sessions reach the limit the same way.

Setup
Setuprun as postgres
CREATE DATABASE shop;
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026' CONNECTION LIMIT 1;
OUTPUT
CREATE DATABASE
CREATE ROLE
Reproduce3 sessions open at the same time (A, C, B), run in this order
Session Arun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shop
SELECT current_user, current_database();
OUTPUT
 current_user | current_database
--------------+------------------
 app_user     | shop
(1 row)
Session C · Checkrun as postgres
SELECT usename, datname, count(*) FROM pg_stat_activity WHERE usename = 'app_user' GROUP BY usename, datname;
OUTPUT
 usename  | datname | count
----------+---------+-------
 app_user | shop    |     1
(1 row)
Session Brun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shop
SELECT current_user, current_database();
OUTPUT
psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL:  too many connections for role "app_user"
SERVER LOG (same moment)
FATAL:  53300: too many connections for role "app_user"
Fixrun as postgres
SELECT rolname, rolconnlimit FROM pg_roles WHERE rolname = 'app_user';
OUTPUT
 rolname  | rolconnlimit
----------+--------------
 app_user |            1
(1 row)
Fixrun as postgres
ALTER ROLE app_user CONNECTION LIMIT 10;
OUTPUT
ALTER ROLE

pg_roles.rolconnlimit shows the limit (1, while -1 means no limit). After ALTER ROLE app_user CONNECTION LIMIT 10; both A and B connect and pg_stat_activity shows 2 connections.

After the fix3 sessions open at the same time (A, B, C), run in this order
Session Arun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shop
SELECT current_user, current_database();
OUTPUT
 current_user | current_database
--------------+------------------
 app_user     | shop
(1 row)
Session Brun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shop
SELECT current_user, current_database();
OUTPUT
 current_user | current_database
--------------+------------------
 app_user     | shop
(1 row)
Session C · Checkrun as postgres
SELECT usename, datname, count(*) FROM pg_stat_activity WHERE usename = 'app_user' GROUP BY usename, datname;
OUTPUT
 usename  | datname | count
----------+---------+-------
 app_user | shop    |     2
(1 row)

02The database has CONNECTION LIMIT

The role has no limit, but the database shop was created with CONNECTION LIMIT 1. The second connection fails with too many connections for database "shop"; the limit counts all users connected to that database.

Setup
Setuprun as postgres
CREATE ROLE app_user LOGIN PASSWORD 'Shop2026';
CREATE DATABASE shop CONNECTION LIMIT 1;
OUTPUT
CREATE ROLE
CREATE DATABASE
Reproduce3 sessions open at the same time (A, C, B), run in this order
Session Arun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shop
SELECT current_user, current_database();
OUTPUT
 current_user | current_database
--------------+------------------
 app_user     | shop
(1 row)
Session C · Checkrun as postgres
SELECT usename, datname, count(*) FROM pg_stat_activity WHERE usename = 'app_user' GROUP BY usename, datname;
OUTPUT
 usename  | datname | count
----------+---------+-------
 app_user | shop    |     1
(1 row)
Session Brun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shop
SELECT current_user, current_database();
OUTPUT
psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL:  too many connections for database "shop"
SERVER LOG (same moment)
FATAL:  53300: too many connections for database "shop"
Fixrun as postgres
SELECT datname, datconnlimit FROM pg_database WHERE datname = 'shop';
OUTPUT
 datname | datconnlimit
---------+--------------
 shop    |            1
(1 row)
Fixrun as postgres
ALTER DATABASE shop CONNECTION LIMIT 20;
OUTPUT
ALTER DATABASE

Check pg_database.datconnlimit, then raise it with ALTER DATABASE shop CONNECTION LIMIT 20;. Both sessions then connect.

After the fix3 sessions open at the same time (A, B, C), run in this order
Session Arun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shop
SELECT current_user, current_database();
OUTPUT
 current_user | current_database
--------------+------------------
 app_user     | shop
(1 row)
Session Brun as app_user
$ PGPASSWORD='Shop2026' psql -h 127.0.0.1 -U app_user -d shop
SELECT current_user, current_database();
OUTPUT
 current_user | current_database
--------------+------------------
 app_user     | shop
(1 row)
Session C · Checkrun as postgres
SELECT usename, datname, count(*) FROM pg_stat_activity WHERE usename = 'app_user' GROUP BY usename, datname;
OUTPUT
 usename  | datname | count
----------+---------+-------
 app_user | shop    |     2
(1 row)

FAQ

How do I fix too many connections for role in PostgreSQL?

Check the role's limit with SELECT rolname, rolconnlimit FROM pg_roles; and the current connections in pg_stat_activity. Close unused sessions or raise the limit with ALTER ROLE name CONNECTION LIMIT n; (-1 = no limit).

How do I see who is using the connections?

SELECT usename, datname, count(*) FROM pg_stat_activity GROUP BY usename, datname; shows connections per user and database, as in the check step on this page.

What is the difference between too many connections for role and for database?

The first is the role's CONNECTION LIMIT (pg_roles.rolconnlimit), the second is the database's (pg_database.datconnlimit). Both use SQLSTATE 53300; the message names which one was hit.

Is sorry, too many clients already the same error?

It has the same SQLSTATE 53300 but comes from the server-wide max_connections, not a role or database limit. That case is not reproduced on this page.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12