umami icon indicating copy to clipboard operation
umami copied to clipboard

Schema Engine Error: db error: prepared statement "s0" does not exist

Open shailendrakashyap opened this issue 7 months ago • 10 comments

Describe the Bug

I am facing this unknown issue while deploying to Vercel.

Error: Schema engine error: 23:18:04.355 db error: ERROR: prepared statement "s0" does not exist 23:18:04.355 23:18:04.355 23:18:04.375 error Command failed with exit code 1.

Database

PostgreSQL

Relevant log output

[23:16:28.325] Running build in Washington, D.C., USA (East) – iad1
[23:16:28.432] Cloning github.com/shailendrakashyap/analytics (Branch: main, Commit: db20730)
[23:16:28.800] Previous build cache not available
[23:16:28.986] Cloning completed: 553.587ms
[23:16:29.421] Running "vercel build"
[23:16:29.946] Vercel CLI 32.6.1
[23:16:30.490] Installing dependencies...
[23:16:30.847] yarn install v1.22.17
[23:16:30.976] [1/4] Resolving packages...
[23:16:31.421] [2/4] Fetching packages...
[23:17:27.537] warning [email protected]: The engine "pnpm" appears to be invalid.
[23:17:27.571] [3/4] Linking dependencies...
[23:17:27.574] warning " > @umami/[email protected]" has incorrect peer dependency "@prisma/client@^4.8.0".
[23:17:27.599] warning " > [email protected]" has incorrect peer dependency "react@^16.8.0 || 17.x".
[23:17:27.599] warning " > [email protected]" has incorrect peer dependency "react-dom@^16.8.0 || 17.x".
[23:17:27.599] warning " > [email protected]" has unmet peer dependency "prop-types@^15.7.2".
[23:17:27.617] warning " > [email protected]" has incorrect peer dependency "rollup@^2.0.0".
[23:17:27.618] warning " > [email protected]" has incorrect peer dependency "stylelint@>= 11.x < 15".
[23:17:27.618] warning " > [email protected]" has incorrect peer dependency "stylelint@^14.10.0".
[23:17:27.657] warning Workspaces can only be enabled in private projects.
[23:17:48.017] [4/4] Building fresh packages...
[23:17:52.831] $ node -e "if (process.env.NODE_ENV !== 'production'){process.exit(1)} " || husky install
[23:17:52.975] husky - Git hooks installed
[23:17:52.997] Done in 82.16s.
[23:17:53.050] Detected Next.js version: 13.5.6
[23:17:53.052] Running "yarn run build"
[23:17:53.249] yarn run v1.22.17
[23:17:53.321] $ npm-run-all check-env build-db check-db build-tracker build-geo build-app
[23:17:53.735] $ node scripts/check-env.js
[23:17:54.079] $ npm-run-all copy-db-files build-db-client
[23:17:54.476] $ node scripts/copy-db-files.js
[23:17:54.625] Database type detected: postgresql
[23:17:54.633] Copied /vercel/path0/db/postgresql to /vercel/path0/prisma
[23:17:54.894] $ prisma generate
[23:17:55.568] Prisma schema loaded from prisma/schema.prisma
[23:17:56.291] 
[23:17:56.292] ✔ Generated Prisma Client (v5.3.1) to ./node_modules/@prisma/client in 208ms
[23:17:56.292] 
[23:17:56.292] Start using Prisma Client in Node.js (See: https://pris.ly/d/client)
[23:17:56.292] 
[23:17:56.292] import { PrismaClient } from '@prisma/client'
[23:17:56.293] const prisma = new PrismaClient()
[23:17:56.293] ```
[23:17:56.293] or start using Prisma Client at the edge (See: https://pris.ly/d/accelerate)
[23:17:56.293] ```
[23:17:56.293] import { PrismaClient } from '@prisma/client/edge'
[23:17:56.293] const prisma = new PrismaClient()
[23:17:56.293] ```
[23:17:56.293] 
[23:17:56.294] See other ways of importing Prisma Client: http://pris.ly/d/importing-client
[23:17:56.294] 
[23:17:56.721] $ node scripts/check-db.js
[23:17:56.843] ✓ DATABASE_URL is defined.
[23:17:58.048] ✓ Database connection successful.
[23:18:00.166] ✓ Database version check successful.
[23:18:04.355] Error: Schema engine error:
[23:18:04.355] db error: ERROR: prepared statement "s0" does not exist
[23:18:04.355] 
[23:18:04.355] ✗ Command failed: prisma migrate deploy
[23:18:04.355] Error: Schema engine error:
[23:18:04.355] db error: ERROR: prepared statement "s0" does not exist
[23:18:04.355] 
[23:18:04.355] 
[23:18:04.375] error Command failed with exit code 1.
[23:18:04.378] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[23:18:04.407] ERROR: "check-db" exited with 1.
[23:18:04.425] error Command failed with exit code 1.
[23:18:04.426] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[23:18:04.456] Error: Command "yarn run build" exited with 1
[23:18:05.089]

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

shailendrakashyap avatar Dec 11 '23 17:12 shailendrakashyap

If you're using Neon, uncheck the pooled connection checkbox and copy the new url.

CodeWithShreyans avatar Dec 14 '23 19:12 CodeWithShreyans

I am using supabase.

shailendrakashyap avatar Dec 15 '23 04:12 shailendrakashyap

Maybe try disabling this then: https://supabase.com/docs/guides/database/connecting-to-postgres#connection-pooler

CodeWithShreyans avatar Dec 15 '23 07:12 CodeWithShreyans

We can connect to a database in two ways according to our needs.

"Direct Connection" : We should use this for tools which are always alive - usually installed on a long-running server, requiring constant connection. For Example, A database administrator, who works on it, or user who wants to query result regularly.

"Connection Pooler" : You should use this for connections which disconnect from the database frequently, like website analytics scripts, connecting users when they visit a page, and get disconected when they leave the page.

Why would you use a connection pool? You can use these simple questions to determine which connection method to use:

Are you connecting to a database and maintaining a connection? If yes, use a direct connection.

Are you connecting to your database and then disconnecting immediately (e.g. a serverless environment)? If yes, use a connection pool.

And in supabase we get URL for both the type connections, port 5432 for direct connections and port 6543 for connection pooling.

shailendrakashyap avatar Dec 15 '23 14:12 shailendrakashyap

Maybe my mistake was that I was using Connection Pooler URL. I rectified it, and now I am using direct connection.

But now I have a new errors showing up, and I am going to post a new issue.

Thanks for the help! @DestroyerXyz

shailendrakashyap avatar Dec 15 '23 14:12 shailendrakashyap

I am recieving a "405 Method Not Allowed" Response when clicking on login button.

shailendrakashyap avatar Dec 15 '23 14:12 shailendrakashyap

Check this: https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/databases-connections/pgbouncer#prisma-migrate-and-pgbouncer-workaround


So you can:

  1. Open this file in path: db\postgresql\schema.prisma
  2. Find this block of code:
    datasource db {
      provider     = "postgresql"
      url          = env("DATABASE_URL")
      relationMode = "prisma"
    }
    
  3. Add a line to support direct connect to database, just like this:
    datasource db {
      provider     = "postgresql"
      url          = env("DATABASE_URL")
      directUrl    = env("DATABASE_DIRECT_URL")`
      relationMode = "prisma"
    }
    
  4. Define your pgbouncer database link in the environment variable DATABASE_URL, and your direct database link in the environment variable DATABASE_DIRECT_URL.
  5. Completion of the migration.

cxplay avatar Jan 08 '24 11:01 cxplay

Has anyone else had this problem and solved it?

naodeng avatar Jan 09 '24 04:01 naodeng

I am using supabase.

I fixed it on my deployment by using the port 5432 instead of the default 6543; Supabase mentions you need to either use this different port OR use the Session pool mode if using prepared statements (which umami uses).

image image

bdsqqq avatar Jan 16 '24 11:01 bdsqqq

Has anyone else had this problem and solved it?

I solved it by using the Direct URL, and adding ?pgbouncer=true

image

From what I understand, though, this method is being deprecated.

After doing that, though, I had a bunch of other migration issues. Make sure to check your migrations logs, in the _prisma_migrations table.

candidexmedia avatar Jan 22 '24 04:01 candidexmedia