prepared statement \"s0\" already exists
See original GitHub issueBug description
I’m connecting to Supabase with their connection pooling enabled and I’m seeing the following 500
errors after multiple refreshes of the same page, until eventually it forces me to have to restart my server.
Supabase Connection Pooling
Connection String (Pool Mode = Transaction):
postgres://postgres:[YOUR-PASSWORD]@[host].supabase.co:6543/postgres
With Supabase’s connection pooling I still see the 500
error that is shown below.
Prisma PGBouncer
Connection String:
"postgresql://postgres:[PASSWORD]@[HOST].supabase.co:5432/postgres?pgbouncer=true"
With Prisma’s PG Bouncer I am still getting the same error after multiple refreshes of the same page. This is very problematic because very quickly I am getting these errors. Even when testing locally.
Error:
"PrismaClientUnknownRequestError: Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(
DbError { severity: \"ERROR\", parsed_severity: Some(Error), code: SqlState(\"42P05\"),
message: \"prepared statement \\"s0\\" already exists\", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some(\"prepare.c\"), line: Some(447), routine: Some(\"StorePreparedStatement\")
}) }) })\n}"
How to reproduce
Expected behavior
Prisma queries should be executed normally when connected to a pgbouncer pool or to supabase’s connection pooling.
Prisma information
"@prisma/client": "^3.5.0",
Environment & setup
- OS: Mac OS 12.0.1
- Database: PostgreSQL 12
- Node.js version: v16.3.0
Prisma Version
3.5.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (8 by maintainers)
Top GitHub Comments
@woniesong92 I just encountered this same issue and stumbled upon this issue via googling the error
What I’ve found is, if you’ve ever accidentally connected to the without
?pgbouncer=true
added to the connection string, you will keep getting this error (even after adding?pgbouncer=true
) until you restart the Supabase project.TL;RD; Never connect to Supabase without
?pgbouncer=true
. If you do by accident, restart the Supabase project.This problem turned out to ultimately be caused by usage of a pooled connection string (port
6543
at Supabase) without supplyingpgbouncer=true
. When that was added, the error went away.But the cause for this is a bit more complicated: @juanzgc has a Next.js app where he is using a
.env.local
file. When using the Prisma CLI, only the.env
file is loaded, and not the.env.local
. Hence Juan created a.env
with a copy of the database. Then he later messed around with things, and thinking that Prisma would only use.env
, only addedpgbouncer=true
to the connection string there. But his Next.js app on startup loads both.env.local
and.env
, which meant that Prisma in the end was not using the value from.env
but.env.local
instead - which was missing thepgbouncer=true
. The weird thing now is that if you only have a.env.local
file, Prisma still complains about an env var not being set when running queries inside the Next.js app, although that clearly loaded the env var when starting. This is what caused him to be in this weird position where it was easy to get this wrong.