prisma: mainnet.db.explorer.indexer.near.dev: `db error: ERROR: prepared statement "s0" does not exist`
Bug description
Error: Error in connector: Error querying the database: Error querying the database: Error querying the database: db error: ERROR: prepared statement “s0” does not exist
How to reproduce
INDEXER_DATABASE_URL=“postgresql://public_readonly:nearprotocol@mainnet.db.explorer.indexer.near.dev/mainnet_explorer?schema=public” DEBUG=prisma:* npx prisma db pull
Expected behavior
schema.prisma
should be updated from the Postgresql database instead of throwing an error.
Prisma information
schema.prisma:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("INDEXER_DATABASE_URL")
}
Environment & setup
- OS: MacOS
- Database: PostgreSQL
- Node.js version: 16.x
Prisma Version
prisma : 3.9.2
@prisma/client : 3.9.2
Current platform : darwin
Query Engine (Node-API) : libquery-engine bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/prisma/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/prisma/node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/prisma/node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/prisma/node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : bcc2ff906db47790ee902e7bbc76d7ffb1893009
Studio : 0.457.0
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 4
- Comments: 49 (12 by maintainers)
Someone else somewhere might have this issue after doing what I did… Here’s how to fix this if you did what I did:
The way that the Supabase
Settings
>Database
page is laid out, if you scroll a bit too fast you’ll skip theConnection string
section completely and see aConnection string
field inside theConnection Pooling Custom Configuration
section. This is not the connection string you are looking for. Make the Obi-Wan motion with you hand nowConnection Pooling connection string is a DIFFERENT connection string. Head to the right section, click on
Nodejs
and copy the hidden connection string that you ARE looking for.You’re welcome. 😉
The one who is struggling with Supabase connection pooling. Please use this way your database url
DATABASE_URL="postgres://postgres.[reference-id]:[Your Password]@aws-0-ap-southeast-1.pooler.supabase.com"
Thank you
Configure your schema.prisma this way:
With this setup directUrl is used for migrations and push, and url is used for queries. Then set the environment variables like this:
Here is the supabase UI for generating the URLs.
Is this a connection pooled connection string (e.g. PgBouncer)? If so, you might need to enable PgBouncer mode by adding
&pgbouncer=true
to it.Using Prisma’s
directUrl
option solved this issue for me (docs).Example:
Prisma will use the
directUrl
connections for push and migrations (docs), and theurl
for queries.Note for anyone using Supabase: there are 2 connection string URLs on the settings page - one with connection pooling, and one without.
I use supabase and got this error after running prisma migration. For me worked using regular database url, not the one for connection pooling.
Noob here,first time using prisma for a tutorial,but in my case i had to connect a Supabase project with a Postgress table created in Prisma , and i received the same error: Error: Migration engine error: db error: ERROR: prepared statement “s0” does not exist
The solution for me was changing the port in my DATABASE_URL from 6534 to the default 5432 , for example:
DATABASE_URL=“postgres://postgres.qbpjsltnktlwrvpjlmbe:Ndy2SbkwvwqwfqfqwdqfEjLOiU@aws-0-eu-central-1.pooler.supabase.com:5432/postgres”
thanks
It’s strange, after generate schema and client from near-indexer-for-explorer, it throw error when use rawQuery.
But it’s fine when use the db of the testnet
postgresql://public_readonly:nearprotocol@testnet.db.explorer.indexer.near.dev/testnet_explorer?schema=public
.&pgbouncer=true
doesn’t help.I was having the same issue. Just search for “Prepared statements error” on this link. That explains why you will need to add
?pgbouncer=true&connection_limit=1
at the end of the connection string@cdgn-coding For me I have to use connection type session for both otherwise it does not work and I get the same error as OP. Have you faced the same issue or does the Transaction connection type work for you for queries?
I don’t think this is accurate https://supabase.com/docs/guides/database/connecting-to-postgres#supavisor-vs-pgbouncer
just got the same error but made it work with these env variables:
please note that port is different in the
DIRECT_URL
Interesting, when you point to the actual instance the
pgbouncer=true
should not be needed for Migrations. But good it works for you.@janpio Thank you for the quick response. Unfortunately,
&pgbouncer=true
does not help.On https://supabase.com/partners/integrations/prisma:
Supabase tells you that Pgbouncer is being deprecated…which makes you think that you should remove this line.
But Prisma is looking for
?pgbouncer=true
to let it know it should not use prepared statements. This is where the confusion comes from.?pgbouncer=true
is not being used by the Supabase database, its just being read by Prisma.I also had success using Supabase’s non-connection-pooling connection string on port
:5432
.I had same issue. Just select Nodejs option in Connection string menu (for all those who are dealing with js or ts.
Similar to before @Papillon6814, if you get this error it means you are probably doing something to a connection pooled (behind PgBouncer) connection string that does not work like - it seems - using
db push
. To rundb push
you need to provide Prisma a direct connection string, for example viadirectUrl
: https://www.prisma.io/docs/guides/performance-and-optimization/connection-management#external-connection-poolers Vercel Postgres for example provides different connection strings for usage indirectUrl
andurl
- where theurl
one already haspgbouncer=true
at the end.