Prisma Connection Pool Exhausted - Cannot Connect to Database
API requests start failing with 'too many connections' or 'connect ECONNREFUSED' errors. The database was working fine but suddenly stops accepting connections.
This typically happens under load or after the app has been running for a while, and restarting the app temporarily fixes it.
Error Messages You Might See
Common Causes
- Prisma Client not being reused across requests - creating new instances continuously
- Database connection pool size too small for concurrent requests
- Connections not being closed properly after queries
- Long-running queries holding connections idle
- Pool timeout set too low, causing connection exhaustion
How to Fix It
Create a singleton Prisma Client instance: export const prisma = new PrismaClient(); // import in routes
Configure connection pool in DATABASE_URL: postgresql://user:pass@host/db?schema=public&connection_limit=5
Add proper error handling and disconnect: process.on('SIGINT', async () => { await prisma.$disconnect(); })
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
What's the best way to use Prisma in serverless?
Create a singleton pattern with module-level instantiation to reuse connections across cold starts
What's a safe connection pool size?
For WebContainer: 2-3. For production: 10-20. Adjust based on concurrent users and query patterns
How do I debug connection issues?
Enable Prisma debug logging: DEBUG=prisma:* npm run dev