Skip to main content
Database & ORM · Developer Error Resolution Lab

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.

Triggered Error Message:

PostgresError: prepared statement "s0" already exists (code: "42P05")

Customize Solution for Your Environment
// 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)?
Serverless functions use port `6543` (transaction pooler) to prevent connection exhaustion, while `prisma migrate` requires session-level advisory locks available only on port `5432`.
DEVSECOPS & CI/CD PARTNER2 Slots Open

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.

Browse All 54 Guides