🔧 Unbreak My AppAll fixesFix KitsSponsor

Fixes › Performance

Postgres: too many connections / remaining connection slots are reserved

Cursorv0Replit

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

  1. Use Supabase's pooled connection string (Supavisor, transaction mode, port 6543) for serverless.
  2. With Prisma, use the pooled URL and add pgbouncer=true; keep a DIRECT_URL for migrations.
  3. Reuse one client per instance (global singleton in dev).
  4. 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

Want the full checklist for this area? Get a Fix Kit ($29)

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.