FluentDBFluentDB
PostgreSQL errors

PostgreSQL: sorry, too many clients already

FATALSQLSTATE 53300too_many_connections
FATAL: sorry, too many clients already

Every allowed connection slot is in use, so Postgres rejected a new one. You have reached max_connections. The durable fix is to put a connection pooler in front of Postgres rather than opening a connection per request.

What this error means

Postgres allocates a fixed number of connection slots at startup (max_connections, default 100). Each connection also costs memory, so the number is deliberately bounded. When every slot is taken, new connections get this FATAL error.

This is almost always a symptom of an application that opens connections faster than it closes them, or one that opens a fresh connection per request instead of reusing a pool.

How to fix it

01

The app opens a connection per request

Put a pooler like PgBouncer in front of Postgres in transaction mode, and cap the pool below max_connections. This is the recommended fix and scales far better than raising the limit.

02

You need headroom right now

Raise max_connections and restart Postgres. This costs memory per slot, so treat it as a stopgap, not a solution.

sql
ALTER SYSTEM SET max_connections = 200;
-- then restart Postgres
03

Idle connections are piling up

See who is connected, and terminate idle sessions to recover slots immediately.

sql
SELECT pid, usename, state
FROM pg_stat_activity
WHERE state = 'idle'
ORDER BY state_change;

-- terminate a specific one:
SELECT pg_terminate_backend(<pid>);

How to avoid it next time

  • Always run application traffic through a pooler; do not let each worker hold its own long-lived connection.
  • Set a sane maximum pool size in your app that stays comfortably under the server limit.

Frequently asked questions

Should I just increase max_connections?

Rarely as the first move. Each connection consumes memory, so a high max_connections can starve the server. A pooler lets thousands of app clients share a small number of real Postgres connections.

What is the difference from 'too many connections for role'?

This error means the whole server hit max_connections. 'Too many connections for role' means a per-role CONNECTION LIMIT was hit while the server still had free slots.

Stop struggling with SQL

Use FluentDB, the AI database client for macOS.