Skip to content
Latchkey

Prisma "P1001: Can't reach database server" (service not up) in CI

P1001 means Prisma opened a socket to the host and port in your connection string and got no answer. In CI this is almost always a database service container that has not finished starting, or a wrong host.

What this error means

A migrate or query step fails with "P1001: Can't reach database server at localhost:5432", intermittently on fast runners and reliably when the DB service is misconfigured.

Prisma
Error: P1001: Can't reach database server at `localhost`:`5432`

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

Common causes

The database service is not ready yet

The Postgres/MySQL service container is still starting when Prisma connects, so the port is not yet accepting connections.

A wrong host or port in DATABASE_URL

The URL points at a host the runner cannot reach, such as the wrong service name or a container-only hostname.

How to fix it

Add a health check and wait

  1. Add a health check to the service so the job waits for it.
  2. Or poll the port before running Prisma.
  3. Only run migrate/query once the DB is accepting connections.
.github/workflows/ci.yml
services:
  postgres:
    image: postgres:16
    env: { POSTGRES_PASSWORD: postgres }
    options: >-
      --health-cmd="pg_isready" --health-interval=5s --health-timeout=5s --health-retries=10

Use the correct host for the runner

For a GitHub Actions service container, connect over localhost with the mapped port, not the service name.

Terminal
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/app

How to prevent it

  • Gate Prisma steps on a database health check.
  • Verify the host/port match how the service is exposed to the runner.
  • Retry the connection briefly for slow-starting services.

Related guides

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