← All fixes
Postgres: remaining connection slots are reserved for non-replication superuser connections (too many clients)
#158Error
FATAL: remaining connection slots are reserved for non-replication superuser connections
Why it happens, and why this works
The database ran out of connections. Serverless functions each open their own pool, and Next.js dev hot reload creates a new client on every change, so connections pile up past max_connections.
Fix
1. Use a connection pooler: Supabase transaction pooler (port 6543), Neon pooled URL (-pooler host), or PgBouncer. With Prisma add ?pgbouncer=true&connection_limit=1 on serverless. 2. Create ONE client per process. In Next.js dev, cache it on globalThis: const prisma = globalThis.prisma ?? new PrismaClient(); if (process.env.NODE_ENV !== "production") globalThis.prisma = prisma; 3. Keep pool size small in serverless (max: 1-3). 4. Look for code that opens a new pool per request and never closes it.
Did it work?
No reports yet0 worked0 didn't
Tried it yourself?
Related fixes
Postgres: connection refused / could not connect to server (psycopg2, pg, Prisma)
#147psycopg2.OperationalError: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused. Is the server running on that host and accepting TCP/IP connections? (also ECONNREFUSED 127.0.0.1:5432, Prisma P1001)
MCP stdio server prints a banner on stdout so the client drops the connection at initialize
#190McpError: MCP error -32000: Connection closed (server answered initialize but its own log shows a plain-text banner went to stdout first)
MCP stdio server prints a banner on stdout so the client drops the connection at initialize
#186McpError: MCP error -32000: Connection closed (server answered initialize but its own log shows a plain-text banner went to stdout first)