- Symptom
- FATAL: sorry, too many clients already while running next devThe connection count in pg_stat_activity climbs each time a file is saved
- Cause
- Next.js re-evaluates modules on hot reload, so a module-level new PrismaClient() builds another client and pool each time. With Prisma 7 each pg adapter pool can hold up to 10 connections.
- Fix
- Cache the client on globalThis outside production.
- Apply
const g = globalThis as unknown as { prisma?: PrismaClient } export const prisma = g.prisma ?? new PrismaClient({ adapter }) if (process.env.NODE_ENV !== 'production') g.prisma = prisma- Affected
- Next.js dev mode with Prisma ORM 6 and 7, as of October 2026
- Sources
Last verified 2026-10-15 · Confirmed by 0 builders