I have a Next.js project where I'm using Prisma to read from Postgresql.
I have code like:
const rows = await prisma.receipts.findMany({
where: {
action_receipts: {
// https://www.prisma.io/docs/concepts/components/prisma-client/filtering-and-sorting#filter-on-relations
signer_account_id: {
equals: accountName,
},
},
},
orderBy: {
included_in_block_timestamp: 'desc',
},
take: 2,
});
I'm often getting errors like:
error: PrismaClientUnknownRequestError:
Invalid `prisma.receipts.findMany()` invocation:
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(480), routine: Some("StorePreparedStatement") }) }) })
(Sometimes instead of "s0" it says something else though, such as "s8".)
What does this mean, and how can I avoid it?
It seems like the problem often goes away if I stop my local server and wait a minute and then start again via yarn dev and then try my Prisma query again. But I'm oblivious to the root cause, which I want to identify and solve.
I restarted the project on superbase and it worked.
Go to the settings on the supabase project file and click on restart project

In my case I was using database pooling (on Supabase) but not including the directUrl property in the Prisma schema, like:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
Everything worked without this until I came to do a migration (when updating a Vercel deployment where changes had been made to the Prisma schema).
In .env I added:
# PostgreSQL connection string used for migrations
DIRECT_URL="postgres://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres"
In addition to:
# PostgreSQL connection string with Supavisor config — used by Prisma Client
DATABASE_URL="postgres://postgres.[YOUR-PROJECT-ID]:[YOUR-PASSWORD]@aws-0-[REGION].pooler.supabase.com:6543/postgres?pgbouncer=true&connection_limit=1"
(Obviously Supabase-specific!)
Then I ran npx prisma db push locally and redeployed on Vercel (via GitHub) and voila.
(This info was on https://supabase.com/partners/integrations/prisma, although the page seems to have vanished in the last few hours.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With