Fixes › Performance
Postgres: too many connections / remaining connection slots are reserved
The error
FATAL: sorry, too many clients already / remaining connection slots are reserved
Why it happens
Serverless functions each open their own direct database connection, so traffic spikes exhaust Postgres's connection limit. ORMs like Prisma create a new pool per cold start.
How to fix it
- Use Supabase's pooled connection string (Supavisor, transaction mode, port 6543) for serverless.
- With Prisma, use the pooled URL and add pgbouncer=true; keep a DIRECT_URL for migrations.
- Reuse one client per instance (global singleton in dev).
- Or use supabase-js over HTTP, which doesn't hold Postgres connections.
Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)
We hit 'too many connections' on Supabase Postgres under load. Switch serverless code to the pooled connection string (transaction mode, port 6543), configure Prisma with pgbouncer=true and a separate DIRECT_URL for migrations, make the DB client a singleton, and list the env vars to update.
FAQ
Do I need a bigger plan?
Usually not; pooling fixes it.
Why separate DIRECT_URL?
Migrations need a direct session connection.
Related fixes
- App is slow: dozens of database calls per page (N+1 queries)
- Too many re-renders / useEffect infinite loop
- Supabase query returns an empty array (no error)
- new row violates row-level security policy for table
Want the full checklist for this area? Get a Fix Kit ($29)
Featured slot available: reach thousands of vibe coders. Sponsor this week →
Get one new fix a week
Free newsletter: the newest breakages in Lovable, Bolt, Cursor, Replit and v0 apps, with paste-in fixes.
We only use your email to send the newsletter. Unsubscribe any time. See privacy.