PostgreSQL error: FATAL: sorry, too many clients already
This is a server-wide connection limit, distinct from the per-role "too many connections for role" error — the entire database instance has hit its max_connections ceiling from all roles combined. It's the same root fix as the per-role version: use a connection pooler in serverless environments, and make sure you're not creating a new PrismaClient per request.
What causes this error
PostgreSQL's max_connections setting caps how many client connections the entire server instance will accept, across every database and every role combined — this is a hard ceiling set at the server level, separate from any per-user connection limits.
The Fix
The fix is the same underlying pattern as the per-role connection limit issue: use a pooled connection string in serverless environments, and ensure only one Prisma Client instance exists per process (a singleton), not one created fresh on every request.
# Use the pooled endpoint, not the direct one
DATABASE_URL="postgresql://user:pass@ep-xxxx-pooler.neon.tech/db"If you're on a self-hosted Postgres instance and genuinely need more connections rather than pooling, max_connections can be raised in postgresql.conf — but this trades off against memory usage per connection, so pooling is usually the better fix even then.
Common causes / variations
- Multiple separate services/functions all connecting directly without pooling
- A connection leak — code that opens connections but never closes them on error paths
- Running local development and a deployed environment against the same free-tier database simultaneously
Related errors
See also: too many connections for role, PrismaClientInitializationError.
Comments
Loading comments...