Supabase “too many connections” – Postgres slots, Supavisor limits and serverless pools

By Abheesht Tripathi · Published

FATAL: remaining connection slots are reserved for non-replication superuser connections
FATAL: sorry, too many clients already  (code 53300)
Max client connections reached  (Supavisor)

Two different limits

Postgres has a fixed number of connection slots, set by your compute size. When they are used up you get remaining connection slots are reserved … (Postgres 16 and later word it … reserved for roles with the SUPERUSER attribute) or sorry, too many clients already.

Supavisor, Supabase's connection pooler, also has a client limit per compute size. Exceeding it gives Max client connections reached. Both usually have the same root cause: many app instances, each opening its own pool.

Note: supabase-js does not open database connections. It talks HTTP to the Data API, which has its own small pool. This problem comes from ORMs and drivers (Prisma, Drizzle, node-postgres, postgres.js, SQLAlchemy) connecting directly.

Step 1: see who holds the connections

select usename, application_name, client_addr, state, count(*)
from pg_stat_activity
group by 1, 2, 3, 4
order by 5 desc;

show max_connections;

Lots of idle connections from one app means pools that are too big or never closed. Supavisor errors show up in the dashboard's Pooler logs.

Step 2: use the right connection string

From Supabase's connection guide:

postgresql://postgres.<project-ref>:<password>@<pooler-host>:6543/postgres

Copy the pooler host from the Connect dialog; it can't be guessed from the region.

Step 3: turn off prepared statements in transaction mode

The shared pooler doesn't support prepared statements in transaction mode. Turn them off in your driver:

// postgres.js / Drizzle
const sql = postgres(process.env.DATABASE_URL, { prepare: false });

# Prisma: pooled URL for the app, direct URL for migrations
DATABASE_URL="postgresql://postgres.<ref>:<password>@<pooler-host>:6543/postgres?pgbouncer=true&connection_limit=1"
DIRECT_URL="postgresql://postgres.<ref>:<password>@<pooler-host>:5432/postgres"

Step 4: keep each pool small

// node-postgres, created once at module level
import pg from 'pg';
export const pool = new pg.Pool({
  connectionString: process.env.DATABASE_URL,
  max: 3,
  idleTimeoutMillis: 10_000,
});

Emergency: free slots now

select pg_terminate_backend(pid)
from pg_stat_activity
where state = 'idle'
  and state_change < now() - interval '10 minutes'
  and pid <> pg_backend_pid();

This only buys time. If the connection count climbs back, the pools are still too large. Upgrade compute only after pooling is right; otherwise the bigger limit fills up the same way.

How to verify

Rerun the pg_stat_activity query under normal load and during a traffic spike. The total should stay well below max_connections, and the app's connections should come through the pooler, not as hundreds of direct idle sessions.

Related guides

More in Postgres errors and performance · all guides