Provides solutions for Prisma connection pool errors (P2024) common in serverless platforms.
Install
mkdir -p .claude/skills/prisma-connection-pool-exhaustion && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/3800" && unzip -o skill.zip -d .claude/skills/prisma-connection-pool-exhaustion && rm skill.zipInstalls to .claude/skills/prisma-connection-pool-exhaustion
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Fix Prisma "Too many connections" and connection pool exhaustion errors in
serverless environments (Vercel, AWS Lambda, Netlify). Use when: (1) Error
"P2024: Timed out fetching a new connection from the pool", (2) PostgreSQL
"too many connections for role", (3) Database works locally but fails in
production serverless, (4) Intermittent database timeouts under load.Key capabilities
- →Diagnose P2024 connection timeout root causes
- →Recommend connection pooler implementation
- →Provide schema configuration for Prisma limits
- →Debug database connection spikes in serverless environments
How it works
Matches environment-specific error patterns against known serverless database connection limits to suggest configuration fixes.
Inputs & outputs
When to use prisma-connection-pool-exhaustion
- →Resolving P2024 connection timeout errors
- →Scaling Prisma for serverless production
- →Fixing database connection spikes
About this skill
Prisma Connection Pool Exhaustion in Serverless
Problem
Serverless functions create a new Prisma client instance on each cold start. Each instance opens multiple database connections (default: 5 per instance). With many concurrent requests, this quickly exhausts the database's connection limit (often 20-100 for managed databases).
Context / Trigger Conditions
This skill applies when you see:
P2024: Timed out fetching a new connection from the connection pool- PostgreSQL:
FATAL: too many connections for role "username" - MySQL:
Too many connections - Works fine locally with
npm run devbut fails in production - Errors appear during traffic spikes, then resolve
- Database dashboard shows connections at or near limit
Environment indicators:
- Deploying to Vercel, AWS Lambda, Netlify Functions, or similar
- Using Prisma with PostgreSQL, MySQL, or another connection-based database
- Database is managed (PlanetScale, Supabase, Neon, RDS, etc.)
Solution
Step 1: Use Connection Pooling Service
The recommended solution is to use a connection pooler like PgBouncer or Prisma Accelerate, which sits between your serverless functions and the database.
For Supabase:
# .env
# Use the pooled connection string (port 6543, not 5432)
DATABASE_URL="postgresql://user:[email protected]:6543/postgres?pgbouncer=true"
For Neon:
# .env
DATABASE_URL="postgresql://user:[email protected]/dbname?sslmode=require"
# Neon has built-in pooling
For Prisma Accelerate:
npx prisma generate --accelerate
Step 2: Configure Prisma Connection Limits
In your schema.prisma:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
// Limit connections per Prisma instance
relationMode = "prisma"
}
In your connection URL or Prisma client:
// lib/prisma.ts
import { PrismaClient } from '@prisma/client'
const globalForPrisma = global as unknown as { prisma: PrismaClient }
export const prisma = globalForPrisma.prisma || new PrismaClient({
datasources: {
db: {
url: process.env.DATABASE_URL + '?connection_limit=1'
}
}
})
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
Step 3: Singleton Pattern (Development)
Prevent hot-reload from creating new clients:
// lib/prisma.ts
import { PrismaClient } from '@prisma/client'
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined
}
export const prisma = globalForPrisma.prisma ?? new PrismaClient()
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
Step 4: URL Parameters
Add these to your connection string:
?connection_limit=1&pool_timeout=20&connect_timeout=10
connection_limit=1: One connection per serverless instancepool_timeout=20: Wait up to 20s for available connectionconnect_timeout=10: Fail fast if can't connect in 10s
Verification
After applying fixes:
- Deploy to production
- Run a load test:
npx autocannon -c 100 -d 30 https://your-app.com/api/test - Check database dashboard—connections should stay within limits
- No more P2024 errors in logs
Example
Before (error under load):
[ERROR] PrismaClientKnownRequestError:
Invalid `prisma.user.findMany()` invocation:
Timed out fetching a new connection from the connection pool.
After (with connection pooling):
# Using Supabase pooler URL
DATABASE_URL="postgresql://[email protected]:6543/postgres?pgbouncer=true&connection_limit=1"
Database connections stable at 10-15 even under heavy load.
Notes
- Different managed databases have different pooling solutions—check your provider's docs
- PlanetScale (MySQL) uses a different architecture and doesn't have this issue
connection_limit=1is aggressive; start there and increase if you see latency- The singleton pattern only helps in development; in production serverless, each instance is isolated
- If using Prisma with Next.js API routes, each route invocation may be a separate serverless function
- Consider Prisma Accelerate for built-in caching + pooling: https://www.prisma.io/accelerate
When not to use it
- →Debugging client-side network connectivity issues
- →Development environments without database load
Prerequisites
Limitations
- →External database limits still apply
- →Requires infrastructure adjustments outside of the code
How it compares
It provides environment-specific connection pooling advice rather than general database troubleshooting.
Compared to similar skills
prisma-connection-pool-exhaustion side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| prisma-connection-pool-exhaustion (this skill) | 1 | 6mo | Review | Intermediate |
| hiddenroom-supabase | 0 | 1mo | No flags | Intermediate |
| backend-patterns | 0 | 1mo | No flags | Advanced |
| web-server-architecture | 0 | 3mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by blader
View all by blader →You might also like
hiddenroom-supabase
cuvo1903-ctrl
Hidden Room Supabase backend skill for migrations, generated database types, Edge Functions, RLS policies, auth/profile sync, storage buckets, Stripe integration, cloud_jobs, and database documentation. Use when editing supabase/migrations, supabase/functions, database.types.ts, or Supabase-backed f
backend-patterns
chenqin231
Backend architecture patterns, API design, database optimization, and server-side best practices for Node.js, Express, and Next.js API routes.
web-server-architecture
develsvai
`web/src/server/**`의 router, service, 공통 계층을 건드릴 때 사용하는 스킬이다. tRPC router와 service 책임 분리, 도메인 구조, Prisma 사용 경계를 맞춘다.
sql-optimization-patterns
wshobson
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.
drizzle-orm
EpicenterHQ
Drizzle ORM patterns for type branding and custom types. Use when working with Drizzle column definitions, branded types, or custom type conversions.
bullmq-specialist
davila7
BullMQ expert for Redis-backed job queues, background processing, and reliable async execution in Node.js/TypeScript applications. Use when: bullmq, bull queue, redis queue, background job, job queue.