Skip to content
Latchkey

Prisma "P1001: Can't reach database server" in CI

Prisma could not open a connection to the database host before its connect timeout while running in CI. The migration engine never reached the server - a connectivity issue, usually a service container that has not finished starting.

What this error means

prisma migrate deploy aborts immediately with P1001, naming the host and port. It typically passes on retry once the database service is accepting connections.

prisma
Error: P1001: Can't reach database server at `db`:`5432`

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

Common causes

Database service not ready

The database is a service container still booting when Prisma connects, so the connection cannot complete in time.

Transient network blip

A brief connectivity or DNS hiccup can stop the connection from completing inside the connect timeout.

Wrong host/port

If the host or port in DATABASE_URL is wrong for the CI network, every attempt fails the same way.

How to fix it

Wait for readiness before migrating

Block on the database accepting connections rather than racing it.

Terminal
until pg_isready -h "$DB_HOST" -p "$DB_PORT"; do sleep 1; done
npx prisma migrate deploy

Use a service healthcheck

.github/workflows/ci.yml
services:
  db:
    image: postgres:16
    env: { POSTGRES_PASSWORD: postgres }
    options: >-
      --health-cmd "pg_isready -U postgres"
      --health-interval 5s --health-retries 10

How to prevent it

  • Gate migrate steps on pg_isready/healthcheck, not a fixed sleep.
  • Keep DATABASE_URL host/port in sync with the CI network.
  • On managed runners (Latchkey), self-healing auto-retries transient failures, and a database slow to accept connections is a classic transient case.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →