Two problems stacking up.
- Port 5432 on the pooler host is session mode: each client holds a database connection for as long as it's connected. Serverless functions spin up many instances, each holds one or more, and you hit the pooler's client limit fast. Switch the runtime URL to transaction mode (port 6543) and add
?pgbouncer=true&connection_limit=1for Prisma. new PrismaClient()in every route file means every route module has its own pool. Make one shared instance:
// lib/db.ts
import { PrismaClient } from '@prisma/client'
const g = globalThis as unknown as { prisma?: PrismaClient }
export const prisma = g.prisma ?? new PrismaClient()
if (process.env.NODE_ENV !== 'production') g.prisma = prismaKeep directUrl on the session/direct connection for prisma migrate.
300 concurrent visitors is well within what a free project can serve once connections are pooled. The limit you hit was config, not size.
pooler.supabase.com) ordb.<ref>.supabase.co? deploydan · editednew PrismaClient()per route thing. sophie_l · edited