Prisma P1001: Can't reach database server on deploy
THE SHORT ANSWER
P1001 means Prisma couldn't open a network connection to the host and port in DATABASE_URL: the hostname didn't resolve, nothing was listening, or a firewall dropped the connection. On deploy it is usually one of four things: prisma migrate deploy runs in the build step, where the database isn't reachable; DATABASE_URL still says localhost, which inside a container means the container itself; the variable is missing or different at build time and at runtime; or the database only accepts connections from a private network or allowlisted IPs. Prisma 7 adds two changes to check: the CLI reads the URL from prisma.config.ts and doesn't load .env by itself, and the app connects through a driver adapter whose pool and SSL settings come from the driver.
What does P1001 mean?
Prisma's error reference gives the message as:
Can't reach database server at `{database_host}`:`{database_port}` Please make sure your database server is running at `{database_host}`:`{database_port}`.The host and port in the message are the ones Prisma tried, so read them first. If they say localhost or 127.0.0.1 on a deployed app, that's your answer. If the host is empty, DATABASE_URL wasn't set or didn't parse.
P1001 is a network failure: Prisma never got as far as logging in. Its neighbours tell you how far it did get:
P1000: the server answered, but the username or password was wrong.P1011:Error opening a TLS connection.P1013:The provided database string is invalid.P2024: connected before, but timed out waiting for a free connection in the pool.
In Prisma 7 the app connects through a driver adapter. @prisma/adapter-pg maps the driver's ENOTFOUND (the hostname didn't resolve) and ECONNREFUSED (nothing listening) to the same “database not reachable” error, so check both DNS and the port.
Quick checklist
| When it fails | Likely cause | Fix |
|---|---|---|
During the build, on prisma migrate deploy | The build can't reach the database's private network | Run migrations when the app starts |
At runtime, host is localhost | A local DATABASE_URL reached production | Set the real URL on the host, or the Compose service name |
| At runtime, host looks wrong or empty | Variable missing, or a password with @ or # not encoded | Set it, and percent-encode the password |
| From your laptop or CI to a hosted database | The database only allows a private network or listed IPs | Use its public connection string, or allow the IP |
| After upgrading to Prisma 7 | .env no longer loaded, or SSL now verified | Load dotenv in prisma.config.ts; fix the certificate settings |
Are you running migrations during the build?
This is the one that catches people on container platforms. A build script like prisma migrate deploy && next build works on your laptop, where the database is local. On a host that builds your image in an isolated builder, the database is on a private network the build can't see, so its hostname doesn't resolve and the build stops with P1001.
Split the two jobs. prisma generate needs no database and belongs in the build. prisma migrate deploy needs the database and belongs right before the server starts:
"scripts": {
"build": "prisma generate && next build",
"start": "prisma migrate deploy && next start"
}Prisma's docs also point out that migrate deploy needs the prisma package at that moment. Platforms that prune devDependencies after the build remove it, so move prisma to dependencies.
Does DATABASE_URL still say localhost?
Inside a container, localhost is the container itself, not your machine and not the database. A DATABASE_URL copied from your .env fails in production even when the database is running fine somewhere else.
With Docker Compose, connect to the database by its service name. Prisma's own Docker guide names the Postgres service postgres_db and uses:
DATABASE_URL="postgresql://postgres:prisma@postgres_db:5432/postgres?schema=public"
On a hosting platform, use the connection string the platform gives you, set as an environment variable on the service. A committed .env with a localhost URL is less dangerous than it looks: dotenv “will never modify any environment variables that have already been set”, so a real variable on the host wins. It only bites when the host variable is missing.
One more way to get a wrong host: a password with special characters. Prisma's docs say you must percent-encode them, so p@$$w0rd becomes p%40%24%24w0rd. An unencoded @ ends the password early and Prisma tries to connect to whatever follows it.
What changed in Prisma 7?
Prisma 7 moved the connection URL out of schema.prisma. The CLI reads it from prisma.config.ts, and the upgrade guide says “environment variables are not loaded by default”. A URL that only lives in .env is invisible to migrate deploy unless the config loads it:
import "dotenv/config";
import { defineConfig } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: { path: "prisma/migrations" },
datasource: {
// process.env, not env(): see below
url: process.env.DATABASE_URL!,
},
});The env() helper from prisma/config throws when the variable isn't set, and every CLI command loads the config, including prisma generate, which doesn't need a database. A build without DATABASE_URL then fails with:
PrismaConfigEnvError: Cannot resolve environment variable: DATABASE_URL.
Prisma 7.0 and 7.1 print Missing required environment variable: DATABASE_URL instead. Prisma's docs suggest process.env when a command may run without the variable.
The other change is at runtime. Prisma 7 requires a driver adapter, so for Postgres you pass the URL to @prisma/adapter-pg, and the driver's own pool and SSL settings apply:
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "./generated/prisma/client";
const adapter = new PrismaPg({
connectionString: process.env.DATABASE_URL,
max: 10, // pool size (pg default: 10)
connectionTimeoutMillis: 5_000, // pg default 0 = wait forever
});
export const prisma = new PrismaClient({ adapter });| Prisma 6 | Prisma 7 | |
|---|---|---|
| CLI connection URL | url in the schema's datasource | datasource.url in prisma.config.ts |
| Client connection | Built-in query engine | Driver adapter, required |
| Pool size | connection_limit, default num_cpus * 2 + 1 | The driver's option, max (10) for pg |
| Connect timeout | connect_timeout, 5 s | connectionTimeoutMillis, 0 (none) for pg |
| Engine binaries | binaryTargets on prisma-client-js | None: prisma-client is Rust-free |
The missing timeout matters for this error: Prisma 6 gives up on opening a connection after 5 seconds, while pg's default never times out, so a database behind a firewall that drops packets can look like a hung request instead of an error. If you still run Prisma 6 in Docker, binaryTargets has to include the container's platform, and Prisma's Docker guide warns against installing glibc on Alpine because Prisma downloads musl-specific engines there.
Check which major version you install. As of November 15, 2026, npm's latest tag for prisma points at a Prisma 8 release candidate, which Prisma's docs describe as a ground-up TypeScript rewrite with a different CLI. Prisma 7 stays fully supported: the docs say to install the CLI as prisma@prev and the client as @prisma/client@7.
SSL settings that break the connection
Hosted databases often require TLS, and the sslmode parameter in the URL decides what Prisma does:
- Prisma 6 accepts
prefer(the default),disableandrequire, and by default doesn't check the certificate (sslaccept=accept_invalid_certs). - Prisma 7 with pg hands the URL to node-postgres. Its
pg-connection-stringREADME sayssslmode=prefer,require,verify-caandverify-fullall setssltotrue, which verifies the certificate. The upgrade guide notes that invalid certificates used to be ignored and now fail withP1010; it suggestsssl: { rejectUnauthorized: false }onPrismaPgto restore the old behaviour, orNODE_EXTRA_CA_CERTSto trust the CA properly.
Going the other way, asking for TLS from a server that doesn't offer it, node-postgres fails with The server does not support SSL connections. Use exactly the connection string your provider gives you rather than adding sslmode by habit.
What happens on EthioDeploy?
Adding a Postgres addon injects DATABASE_URL into the project:
postgres://ethiodeploy:<password>@<addon-host>:5432/ethiodeploy
The host is a private name that only resolves from your running app, on the same server. The variable reaches the build too (unless you mark it runtime only), so prisma generate and an env("DATABASE_URL") config both work there, but the database itself isn't reachable during the build. Run migrations from the Start command in Settings → Build:
npx prisma migrate deploy && npm start
Leave the internal URL as it is. The connection stays on the private network and the URL has no sslmode, which is what the addon expects. To reach the database from your own computer with psql or a GUI client, turn on external access on the Addons tab: it gives a second connection string that already ends in sslmode=require. A MySQL addon also injects DATABASE_URL, so the same steps apply with Prisma's MySQL provider.
Framework specifics are in the Next.js, NestJS and Express deploy guides.
Questions
Prisma couldn't open a network connection to the host and port in DATABASE_URL. The hostname didn't resolve, nothing was listening on the port, or a firewall dropped the connection. It happens before authentication, so the username and password haven't been checked yet.
Many hosts build your app in an isolated builder that can't reach the database's private network. Keep prisma generate in the build and run prisma migrate deploy in the start command, right before the server starts.
DATABASE_URL in production is still your local value, or it isn't set and a committed .env with a localhost URL filled the gap. Inside a container localhost is the container itself. Set the real connection string as an environment variable on the host.
Not by itself. Prisma 7's CLI reads the URL from prisma.config.ts and doesn't load .env files, so add import "dotenv/config" at the top of the config. In your app, load it the same way or set real environment variables.
Only if your database expects TLS. With Prisma 7 and the pg adapter, sslmode=require also verifies the certificate, and a server without TLS fails with "The server does not support SSL connections". Use the connection string your provider gives you.
Sources
Checked on November 15, 2026:
- Prisma: Error reference (v7)
- Prisma: Upgrade to Prisma ORM 7
- Prisma: Config API (v7)
- Prisma: Connection URLs (v7)
- Prisma: Connection pool (v7)
- Prisma: Deploying database changes with Prisma Migrate (v7)
- Prisma: Docker guide (v7)
- Prisma: Generators (v7)
- Prisma: PostgreSQL connector (v6)
- Prisma docs index (ORM 8 and v7 status)
- @prisma/adapter-pg: errors.ts (7.10.1)
- pg-connection-string README
- node-postgres: connection.js
- dotenv README
- prisma on npm
Push a repo. Get a URL.
Start freeJoin the EthioDeploy Telegram
Release notes as they ship, plus deploy help from the team and other developers.