Fix Prisma & Drizzle Error: 'prepared statement "s0" already exists' (Postgres Error 42P05 on Port 6543)
Configure Prisma, Drizzle, and `postgres.js` for Supabase Supavisor / PgBouncer transaction mode pooling on port 6543.
PostgresError: prepared statement "s0" already exists (code: "42P05")
// prisma/schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL") // port 6543 with ?pgbouncer=true
directUrl = env("DIRECT_URL") // port 5432 for prisma migrate
}Root Cause & Mechanism Analysis
Why does this error occur?
Port `6543` in Supabase (and PgBouncer in `transaction` pool mode) shares backend PostgreSQL connections across clients per transaction. Named prepared statements (`s0`, `s1`) created by Prisma or `postgres-js` collide across pooled connections unless disabled with `?pgbouncer=true` or `prepare: false`.
Frequently Asked Questions
Why do I need both `DATABASE_URL` (6543) and `DIRECT_URL` (5432)?
Need Zero-Knowledge .env Secret Sync Across Your Engineering Team?
Explore Castov Env Vault for client-side AES-256-GCM encrypted environment sharing, or sponsor this engineering hub.
Related Developer Error Solutions
Browse All 54 GuidesPostgreSQL: Remaining Connection Slots Reserved
Resolve PostgreSQL connection exhaustion caused by connection leaks or missing pooling with PgBouncer / Prisma Accelerate.
Postgres 42501: new row violates row-level security policy
Resolve PostgreSQL and Supabase Row-Level Security (RLS) INSERT/UPDATE permission errors with proper auth.uid() policies.
Next.js Hydration Failed
Resolve Next.js React hydration mismatch errors caused by browser-only APIs (window, localStorage), timestamps, or invalid HTML nesting.
CORS 'Access-Control-Allow-Origin' Missing
Resolve browser cross-origin resource sharing errors by configuring backend HTTP headers and handling preflight OPTIONS requests.