FluentDBFluentDB
PostgreSQL errors

PostgreSQL: too many connections for role

FATALSQLSTATE 53300too_many_connections
FATAL: too many connections for role "<role>"

A per-role connection limit was reached, even though the server as a whole may still have free slots. Raise or clear the role's CONNECTION LIMIT, or pool connections so the role stays under it.

What this error means

Postgres lets you cap how many concurrent connections a specific role may hold with ALTER ROLE ... CONNECTION LIMIT. When the role hits that cap, further connections for it are refused with this FATAL error.

Unlike 'too many clients already', the whole server is not necessarily full; only this role's budget is spent, usually because of a connection leak or an undersized pool.

How to fix it

01

The role limit is too low

Raise it, or set -1 for no per-role limit.

sql
ALTER ROLE app_user CONNECTION LIMIT 50;
-- or unlimited:
ALTER ROLE app_user CONNECTION LIMIT -1;
02

Connections are leaking

See how many the role holds right now, and terminate stragglers.

sql
SELECT count(*) FROM pg_stat_activity WHERE usename = 'app_user';
03

The app opens too many connections

Put a pooler in front of Postgres and cap the pool below the role's limit.

How to avoid it next time

  • Run traffic through a pooler and set the pool size below the role's CONNECTION LIMIT.
  • Pick a CONNECTION LIMIT deliberately, matched to how many connections the role should ever need.

Frequently asked questions

How is this different from 'too many clients already'?

That error means the whole server hit max_connections. This one means a per-role or per-database CONNECTION LIMIT was hit while the server may still have room.

How do I remove the limit?

ALTER ROLE app_user CONNECTION LIMIT -1; removes the per-role cap.

Stop struggling with SQL

Use FluentDB, the AI database client for macOS.