PrismaClientInitializationError: Can't reach database server at `db.example.com:5432`

Node.js · updated 2026-11-04

Thrown on the first query (or prisma.$connect()) when Prisma cannot connect. Error code P1001. The message names the host and port Prisma tried, which is usually enough to spot a wrong URL.

PrismaClientInitializationError:
Invalid `prisma.user.findMany()` invocation:

Can't reach database server at `db.example.com:5432`

Please make sure your database server is running at `db.example.com:5432`.
    at $n.handleRequestError (/app/node_modules/@prisma/client/runtime/library.js:121:7615) {
  clientVersion: '6.x',
  errorCode: 'P1001'
}

Quick fix

Check the host and port in the message against the DATABASE_URL you expect for this environment. Then test the path from the same machine (nc -vz host 5432). If the database is up and reachable, check that it accepts connections from this app (allowlists, VPC, SSL settings).

  1. Compare the host:port in the message with the DATABASE_URL for this environment.
  2. From the app host or container, run nc -vz <host> <port> to test the network path.
  3. Check the database is running and not paused (serverless databases can sleep).
  4. Check allowlists and VPC settings include the app's outbound address.
  5. For hosted Postgres that requires SSL, add ?sslmode=require to the URL.
bash
# Which URL is this environment using? (prints host only, not credentials)
node -e "const u=new URL(process.env.DATABASE_URL); console.log(u.hostname, u.port)"

# Can this machine reach it?
nc -vz db.example.com 5432

# Hosted Postgres that requires SSL
# DATABASE_URL="postgresql://user:pass@db.example.com:5432/app?sslmode=require"

Why it happens

The wrong DATABASE_URL for this environment

A localhost URL deployed to a server, a staging URL in production, or a missing variable so a default is used.

Network access blocked

Cloud databases often only accept connections from allowlisted IPs or a private network; serverless functions and new hosts are outside it.

The database is down, paused or restarting

Serverless and free-tier databases pause when idle and take time to wake; maintenance windows and restarts cause short bursts of this error.

Docker networking

Inside a container, localhost is the container itself. Use the database service name (db:5432) or host.docker.internal for a database on the host.

Other fixes

  • Raise connect_timeout in the URL for databases that wake from sleep slowly.
  • Use a connection pooler (PgBouncer, Prisma Accelerate) for serverless functions that open many short connections.

Same error, other wording

  • Error: P1001: Can't reach database server at `localhost`:`5432`
  • PrismaClientInitializationError: Timed out fetching a new connection from the connection pool.
  • Error: P1017: Server has closed the connection.

Let your coding agent catch the next one

Runheed records this error in production with the stack trace, the breadcrumbs before it and the agent session that shipped the code, and serves it to Claude Code, Cursor or any MCP client. With it connected, you can ask:

> Find the Prisma "Can't reach database server" errors in production, show me which host and port each one tried and when they cluster, and check the environment's DATABASE_URL and network access.

Plans from $29/moSee what your agent readsSee the setupCancel any time from the billing portal

Related errors

References: Prisma docs: error reference (P1001), Prisma docs: PostgreSQL connection URLs