Next.js Discord

Discord Forum

SUPABASE + PRISMA + NEXT: FATAL: no more connections allowed (max_client_conn)

Unanswered
House Wren posted this in #help-forum
Open in Discord
House WrenOP
I get this error with Nextjs + prisma + supabase even after I set up pgbouncer and I can see pgbouncer running from supabase sql editor the error :
Error querying the database: db error: FATAL: no more connections allowed (max_client_conn)
.env
DATABASE_URL="postgres://postgres:[password]@[username]:6543/postgres?pgbouncer=true"
DIRECT_URL="postgresql://postgres:[password]@[username]:5432/postgres"
prisma.schem file
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl= env("DIRECT_URL")
}

is this a bug with supabase? is there a fix for it? thank you in advance

update: I got this error which there are only 13 connections to my database

16 Replies

House WrenOP
pls help :\
House WrenOP
also I fount this flag on top on my supabase dashboard
you might want to ask Supabase Discord community. and you might want to clarify where to host Next.js
House WrenOP
didn't know they had one
I just joined and asked
House WrenOP
it feels like nobody have ever solved this problem, I posted on prisma discord, NEXTJS help and general channels and Supabase no seems to to know why eventhough I'm not the only one facing this problem
https://github.com/supabase/supabase/issues/8985
this issue was opened a year ago
do you host Next.js on serverless platform such as Vercel or Cloudflare? Since pgBouncer is designed to solve issue related to serverless by having connection pooling in the server side(Supabase side).
if you host it on VPS such as AWS, you do not need it by having pooling on PRISMA side. (Im not sure this as i have not yet tried it)
besides that, Supabase is working on Supervisor, anyway connection pooling on serverles is challenging.
https://supabase.com/blog/supavisor-1-million
here's the code
for now if you are starting a new project either don't use prisma or don't use supabase they are not working right together
if you host it on Vercel, you can use Vercel Postgres(Neon). Vercel modified db driver to use WebSocket. anyway, db connection pool won't work in serverless, instead use db side pooling mechanism such as pgBouncer, Supavaisor along with WebSocket or tcp socket.
https://neon.tech/blog/serverless-driver-for-postgres
House WrenOP
I'm using pgBouncer already