prisma: Error: P1002 database server was reached but timed out

Bug description

I was running prisma migrate dev and ran into this error.

Error: P1002

The database server at `xx.xx.xx.xx`:`5432` was reached but timed out.

Please try again.

Please make sure your database server is running at `xx.xx.xx.xx`:`5432`.

I’m not using pgBouncer. This is my connection string: postgres://<XXXXXXXXXX>/defaultdb?connection_limit=3&connection_timeout=30&pool_timeout=30

I looked at #6053

How to reproduce

This is a random error.

Expected behavior

Primsa migrate happens as expected

Prisma information

Environment & setup

  • OS: Mac OS 10.15.7
  • Database: Postgres
  • Node.js version: 15.14.0
  • Prisma version:
prisma               : 2.21.2
@prisma/client       : 2.21.2
Current platform     : darwin
Query Engine         : query-engine e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : e421996c87d5f3c8f7eeadd502d4ad402c89464d
Studio               : 0.371.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 7
  • Comments: 26 (9 by maintainers)

Most upvoted comments

Resolved by enable PRISMA_SCHEMA_DISABLE_ADVISORY_LOCK. Guess it is a network issue

can you explain more ?

Resolved by enable PRISMA_SCHEMA_DISABLE_ADVISORY_LOCK. Guess it is a network issue

I’m getting this with npx prisma migrate dev. This just started happening to me after stepping away from the project for like a month, I was using Prisma for.

$ DEBUG=* npx prisma migrate dev
  prisma:engines  binaries to download libquery-engine, migration-engine +0ms
  prisma:get-platform  Found distro info:
{
  "targetDistro": "musl",
  "familyDistro": "alpine",
  "originalDistro": "alpine"
} +0ms
  prisma:get-platform  Command "uname -m" successfully returned "x86_64
" +11ms
  prisma:get-platform  Don't know any platform-specific paths for "alpine" on x64 (x86_64) +0ms
  prisma:get-platform  Falling back to "ldconfig" and other generic paths +0ms
  prisma:get-platform  Command "ls /lib | grep libssl | grep -v "libssl.so.0"" successfully returned "libssl.so.1.1
" +25ms
  prisma:get-platform  Found libssl.so file using "ldconfig" or other generic paths: libssl.so.1.1
 +0ms
  prisma:get-platform  Found distro info:
{
  "targetDistro": "musl",
  "familyDistro": "alpine",
  "originalDistro": "alpine"
} +2ms
  prisma:get-platform  Command "uname -m" successfully returned "x86_64
" +5ms
  prisma:get-platform  Don't know any platform-specific paths for "alpine" on x64 (x86_64) +1ms
  prisma:get-platform  Falling back to "ldconfig" and other generic paths +0ms
  prisma:get-platform  Command "ls /lib | grep libssl | grep -v "libssl.so.0"" successfully returned "libssl.so.1.1
" +21ms
  prisma:get-platform  Found libssl.so file using "ldconfig" or other generic paths: libssl.so.1.1
 +0ms
  prisma:get-platform  Found distro info:
{
  "targetDistro": "musl",
  "familyDistro": "alpine",
  "originalDistro": "alpine"
} +1ms
  prisma:get-platform  Command "uname -m" successfully returned "x86_64
" +5ms
  prisma:get-platform  Don't know any platform-specific paths for "alpine" on x64 (x86_64) +0ms
  prisma:get-platform  Falling back to "ldconfig" and other generic paths +1ms
  prisma:get-platform  Command "ls /lib | grep libssl | grep -v "libssl.so.0"" successfully returned "libssl.so.1.1
" +22ms
  prisma:get-platform  Found libssl.so file using "ldconfig" or other generic paths: libssl.so.1.1
 +0ms
  prisma:cache-dir  The following error is being caught and just there for debugging: +0ms
  prisma:cache-dir  [Error: EACCES: permission denied, mkdir '/root/.cache/prisma/master/8fde8fef4033376662cad983758335009d522acb/linux-musl'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/root/.cache/prisma/master/8fde8fef4033376662cad983758335009d522acb/linux-musl'
} +0ms
  prisma:cache-dir  The following error is being caught and just there for debugging: +3ms
  prisma:cache-dir  [Error: EACCES: permission denied, mkdir '/root/.cache/prisma/master/8fde8fef4033376662cad983758335009d522acb/linux-musl'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/root/.cache/prisma/master/8fde8fef4033376662cad983758335009d522acb/linux-musl'
} +0ms
  prisma:get-platform  Found distro info:
{
  "targetDistro": "musl",
  "familyDistro": "alpine",
  "originalDistro": "alpine"
} +22ms
  prisma:get-platform  Command "uname -m" successfully returned "x86_64
" +6ms
  prisma:get-platform  Don't know any platform-specific paths for "alpine" on x64 (x86_64) +0ms
  prisma:get-platform  Falling back to "ldconfig" and other generic paths +0ms
  prisma:get-platform  Command "ls /lib | grep libssl | grep -v "libssl.so.0"" successfully returned "libssl.so.1.1
" +19ms
  prisma:get-platform  Found libssl.so file using "ldconfig" or other generic paths: libssl.so.1.1
 +0ms
  prisma:loadEnv  project root found at /var/www/api/package.json +0ms
  prisma:tryLoadEnv  Environment variables loaded from /var/www/api/.env +0ms
  prisma:getConfig  Using getConfig Wasm +0ms
  prisma:getConfig  config data retrieved without errors in getConfig Wasm +5ms
  prisma:loadEnv  project root found at /var/www/api/package.json +10ms
  prisma:tryLoadEnv  Environment variables loaded from /var/www/api/.env +10ms
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
  prisma:getConfig  Using getConfig Wasm +5ms
  prisma:getConfig  config data retrieved without errors in getConfig Wasm +4ms
Datasource "db": PostgreSQL database "nomads", schema "public" at "pgsql:5432"

  prisma:validate  Using validate Wasm +0ms
  prisma:getConfig  Using getConfig Wasm +6ms
  prisma:getConfig  config data retrieved without errors in getConfig Wasm +2ms
  prisma:getConfig  Using getConfig Wasm +0ms
  prisma:getConfig  config data retrieved without errors in getConfig Wasm +2ms
  prisma:get-platform  Found distro info:
{
  "targetDistro": "musl",
  "familyDistro": "alpine",
  "originalDistro": "alpine"
} +0ms
  prisma:get-platform  Command "uname -m" successfully returned "x86_64
" +7ms
  prisma:get-platform  Don't know any platform-specific paths for "alpine" on x64 (x86_64) +0ms
  prisma:get-platform  Falling back to "ldconfig" and other generic paths +0ms
  prisma:get-platform  Command "ls /lib | grep libssl | grep -v "libssl.so.0"" successfully returned "libssl.so.1.1
" +30ms
  prisma:get-platform  Found libssl.so file using "ldconfig" or other generic paths: libssl.so.1.1
 +1ms
  prisma:migrateEngine:rpc  starting migration engine with binary: /var/www/api/node_modules/@prisma/engines/migration-engine-linux-musl +0ms
  prisma:migrateEngine:rpc  SENDING RPC CALL {"id":1,"jsonrpc":"2.0","method":"devDiagnostic","params":{"migrationsDirectoryPath":"/var/www/api/prisma/migrations"}} +6ms
  prisma:migrateEngine:stderr  {"timestamp":"2023-03-02T21:22:03.215693893Z","level":"INFO","fields":{"message":"Starting migration engine RPC server","git_hash":"8fde8fef4033376662cad983758335009d522acb"},"target":"migration_engine"} +0ms
  prisma:migrate:dev  {
  devDiagnostic: '{\n  "action": {\n    "tag": "createMigration"\n  }\n}'
} +0ms
  prisma:migrateEngine:rpc  SENDING RPC CALL {"id":2,"jsonrpc":"2.0","method":"applyMigrations","params":{"migrationsDirectoryPath":"/var/www/api/prisma/migrations"}} +2s
  prisma:migrateEngine:rpc  {
  jsonrpc: '2.0',
  error: {
    code: 4466,
    message: 'An error happened. Check the data field for details.',
    data: {
      is_panic: false,
      message: 'The database server at `pgsql`:`5432` was reached but timed out.\n' +
        '\n' +
        'Please try again.\n' +
        '\n' +
        'Please make sure your database server is running at `pgsql`:`5432`.\n' +
        '\n' +
        'Context: Timed out trying to acquire a postgres advisory lock (SELECT pg_advisory_lock(72707369)). Elapsed: 10000ms. See https://pris.ly/d/migrate-advisory-locking for details.\n',
      meta: [Object],
      error_code: 'P1002'
    }
  },
  id: 2
} +10s
Error: Error: P1002

The database server at `pgsql`:`5432` was reached but timed out.

Please try again.

Please make sure your database server is running at `pgsql`:`5432`.

Context: Timed out trying to acquire a postgres advisory lock (SELECT pg_advisory_lock(72707369)). Elapsed: 10000ms. See https://pris.ly/d/migrate-advisory-locking for details.


    at Object.<anonymous> (/var/www/api/node_modules/prisma/build/index.js:94561:25)
    at MigrateEngine.handleResponse (/var/www/api/node_modules/prisma/build/index.js:94414:36)
    at LineStream2.<anonymous> (/var/www/api/node_modules/prisma/build/index.js:94514:16)
    at LineStream2.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at LineStream2._pushBuffer (/var/www/api/node_modules/prisma/build/index.js:94269:17)
    at LineStream2._transform (/var/www/api/node_modules/prisma/build/index.js:94263:8)
    at Transform._write (node:internal/streams/transform:175:8)
error Command failed with exit code 1.

It originally popped up in 4.8.0 but upgrading @prisma/client@4.11.0 doesn’t seem to help. This is all running inside a docker setup which you can see here.

Notably, prisma seems to be fine otherwise. I can query and update records via code. Just running migrations is not finding the database. It’s using the same env variables as the code.

@janpio I am running npx prisma migrate dev and I expected it to just add a uniqueness constraint to an existing field in a table.

same