PostgreSQL error: too many connections for role
You've hit your database's connection limit — extremely common in serverless environments (Vercel functions, Lambda) where each invocation can open a new connection. Use a connection pooler (Neon's pooled connection string, or PgBouncer) instead of connecting directly.
What causes this error
Traditional servers keep one long-lived pool of database connections. Serverless functions don't work that way — every cold start can open a fresh connection, and without pooling you can exhaust your database's max connections (often just 20-100 on free tiers) within seconds of moderate traffic.
The Fix
Use your provider's pooled connection string. On Neon, this means using the endpoint with -pooler in the hostname instead of the direct connection string:
# Direct (don't use this in serverless)
DATABASE_URL="postgresql://user:pass@ep-xxxx.neon.tech/db"
# Pooled (use this in serverless functions)
DATABASE_URL="postgresql://user:pass@ep-xxxx-pooler.neon.tech/db"Also make sure you're using a single Prisma Client instance (singleton pattern), not creating a new one per request.
Common causes / variations
- Deploying an Express API as individual serverless functions without pooling
- Creating `new PrismaClient()` inside a request handler instead of reusing a singleton
- Running load tests against a free-tier database with a low connection cap
Related errors
See also: relation does not exist, PrismaClientInitializationError.
Comments
Loading comments...