Fix guides / Prisma + Supabase: P1001 "Can't reach database server"
How to fix Prisma P1001 "Can't reach database server" with Supabase
Your app runs locally, then the deployed version fails with PrismaClientInitializationError: Can't reach database server at `db.abcd.supabase.co:5432` (error code P1001). Or it works for a while and then throws prepared statement "s0" already exists or runs out of connections. All three come from the same place: the connection string.
Why it happens
- The direct host is IPv6 only. Supabase's direct connection,
db.<project-ref>.supabase.co:5432, resolves to IPv6 unless you pay for the IPv4 add-on. Many hosts, including Vercel serverless functions and some CI runners, only speak IPv4, so they never reach it. - Serverless needs a pooler. Every function instance opens its own connections. Without the pooler you hit the connection limit under light traffic.
- The transaction pooler needs a flag. Port 6543 runs in transaction mode, which does not support prepared statements. Prisma uses them unless you tell it not to, which causes the "prepared statement already exists" error.
- The project is paused. Free Supabase projects pause after a period of inactivity, and a paused database gives the same P1001.
Step 1: copy the pooler strings
In the Supabase dashboard, click Connect at the top of the project and open the connection string options. Copy the Transaction pooler string (port 6543) and the Session pooler string (port 5432). Both use a host like aws-0-<region>.pooler.supabase.com and a username like postgres.<project-ref>.
Step 2: use two URLs in Prisma
// schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
# Used by the app at runtime (transaction pooler) DATABASE_URL="postgresql://postgres.abcd:[PASSWORD]@aws-0-us-east-1.pooler.supabase.com:6543/postgres?pgbouncer=true&connection_limit=1" # Used by prisma migrate and db push (session pooler) DIRECT_URL="postgresql://postgres.abcd:[PASSWORD]@aws-0-us-east-1.pooler.supabase.com:5432/postgres"
pgbouncer=true turns off prepared statements, and connection_limit=1 keeps each serverless instance from grabbing a pile of connections. Migrations go through directUrl because they need a session connection.
Step 3: set them where the app runs
Add both variables in your host's settings (Vercel Project Settings, then Environment Variables, or Replit Secrets) and redeploy. A local .env file is not uploaded. If your password contains characters like @, #, or /, URL encode them or reset the password to letters and numbers.
Step 4: rule out a paused project
Open the project in the Supabase dashboard. If it says paused, restore it and wait a minute before retrying.
Check the fix
npx prisma db pullornpx prisma migrate deployconnects from your machine.- The deployed route that queries the database returns data, and the function logs show no P1001.
- Refresh the page a few dozen times: no prepared statement or too many connections errors.
Quick Fix, $49Full Rescue, $149Ask first
Last updated 2026-10-22.