Prisma P1001: Can't reach database server at … — how to fix it
Prisma tried the host and port in your connection URL and nothing answered there. After a deploy that is almost always a URL that says localhost, a database that is not attached to the project, or prisma migrate deploy running in a build that has no database. Read the host in the message first: it tells you which.
By Livops team, the people who build and run LivopsUpdated
The message, as Prisma’s error reference defines it[1][2], with your host and port filled in:
P1001: Can't reach database server at `localhost`:`5432` Please make sure your database server is running at `localhost`:`5432`.
You see it from the Prisma CLI (prisma migrate deploy, prisma db push, prisma migrate dev) and from Prisma Client when it opens its first connection. This page explains what the code means, lists the causes after a deploy from the most common, covers what changed between Prisma 6 and Prisma 7, and ends with how a database is attached on Livops.
What does P1001 mean?
Prisma had a host and a port, tried to open a connection there, and nothing answered. The neighbouring codes rule out the other failures[1]:
| Code | Message (shortened) | What it means |
|---|---|---|
P1000 |
Authentication failed against database server | Reached, wrong user or password |
P1001 |
Can’t reach database server | Nothing answered at that host and port |
P1002 |
The database server … was reached but timed out | Reached, no answer in time |
P1011 |
Error opening a TLS connection | Reached, SSL failed |
P1013 |
The provided database string is invalid | The URL itself is malformed |
P1017 |
Server has closed the connection | Was connected, then cut off |
Prisma Client raises a connection failure at start-up as PrismaClientInitializationError, when $connect() is called or the first query runs; “no database server running under the provided hostname and port” is one of its listed causes[1].
Read the host in the message first. localhost or 127.0.0.1 means the app never got the database’s real address. Any other host means it did, and that host is not reachable from where the command ran.
Causes, most common first
1. The URL says localhost
The connection URL Prisma used points at the machine it runs on. In a deployed app that is the app’s own container, and no database runs there. The URL came from:
- a
.envfile that was committed or uploaded with the code; - a fallback in code, such as
process.env.DATABASE_URL ?? 'postgresql://localhost:5432/app'; - a variable with a different name than the one Prisma reads (
DB_URLin the platform,DATABASE_URLinprisma.config.ts).
Read the platform’s variable and fail loudly when it is missing, rather than quietly trying localhost. With Prisma 7’s env() helper, a missing variable stops the config from loading with PrismaConfigEnvError: Cannot resolve environment variable: DATABASE_URL[4], which names the problem instead of hiding it behind P1001.
2. No database is attached
The app was deployed, but no database was added to the project, so there is nothing at any address. Or a database was added after the app started: variables reach a process when it starts, so the running process still has the old environment. Attach the database and deploy again (or restart).
3. prisma migrate deploy runs in the build
"build": "prisma migrate deploy && next build"
migrate deploy applies pending migrations and is meant for non-development environments[7] — but it needs a live database, and a build often runs where none is reachable. Depending on whether the build can see DATABASE_URL, you get P1001 for the database’s host, or a missing-URL error such as The datasource.url property is required in your Prisma config file when using prisma migrate deploy.[4]
prisma generate does not need a database and can stay in the build. Move prisma migrate deploy to a step that runs before the new version starts — the pre-deploy command on Livops.
4. The host is right, but not from here
An internal host name such as postgres or db resolves only inside its own private network. A URL copied from a Docker Compose file on your laptop means nothing on the server, and a platform database’s internal address means nothing on your laptop. Run the command where the database is reachable, or reach it through the tunnel the provider gives you.
5. An SSL setting that does not match
This usually shows as P1011: Error opening a TLS connection rather than P1001[1], but it comes up in the same search. Prisma’s PostgreSQL URL takes sslmode, whose default is prefer: use TLS if available[5][6]. require fails when the server does not offer TLS[5]. A URL copied from a hosted provider often carries sslmode=require; use your platform’s URL as it is, and add SSL parameters only when the database’s provider asks for them.
6. The database is full of connections
Once every connection slot is taken, new connections are refused, and a service that cannot get one fails just as surely. Prisma pools add up across processes:
- Prisma 7 with
@prisma/adapter-pg: the pool is thepgdriver’s, sized bymax, default 10 per process[3]. - Prisma 6: the
connection_limitURL parameter, defaultnum_cpus * 2 + 1[3][6], which depends on the machine.
A web app and a worker on Prisma 7 defaults already hold up to 20. When Prisma’s own pool is exhausted rather than the server’s, Prisma 6 reports P2024: Timed out fetching a new connection from the connection pool[2]; set the size explicitly in both versions.
Prisma 6 and Prisma 7: what changed
Prisma 7 uses driver adapters by default, so pooling and timeouts come from the Node.js driver you supply, not from URL parameters[3]. That changes three things that matter for P1001.
Where the URL is read. The CLI reads it from datasource.url in the Prisma config file — prisma.config.ts, or prisma7.config.ts in projects created with Prisma ORM 7.10 or later[4][5]:
import 'dotenv/config'
import { defineConfig, env } from 'prisma/config'
export default defineConfig({
schema: 'prisma/schema.prisma',
datasource: { url: env('DATABASE_URL') },
})
Prisma 7 does not load .env files by itself[4]; import 'dotenv/config' on the first line does that on your machine, and on a platform the variable is already in the environment.
Where the client connects. The client gets its own connection string through the adapter, and the variable has to be set when that code runs[5]:
import { PrismaPg } from '@prisma/adapter-pg'
import { PrismaClient } from './generated/prisma/client'
const adapter = new PrismaPg({
connectionString: process.env.DATABASE_URL,
max: 5, // pool size; pg's default is 10
connectionTimeoutMillis: 5_000, // pg's default is 0: wait forever
})
export const prisma = new PrismaClient({ adapter })
How long it waits. On Prisma 6, connect_timeout defaulted to 5 seconds; with the pg adapter, connectionTimeoutMillis defaults to 0, no timeout[3]. So an unreachable host can hang a Prisma 7 app instead of failing fast. Setting connectionTimeoutMillis: 5_000 restores the Prisma 6 behaviour[3].
On Prisma 6 the URL carries the pool size and timeouts[6]:
postgresql://app:secret@postgres:5432/app?connection_limit=5&connect_timeout=10
Prisma ORM 8, now the default in Prisma’s docs, replaced the P codes with dotted NAMESPACE.SUBCODE codes[8]; what is above applies to Prisma 6 and 7.
How to confirm the fix
First, print the host and port the process will use, without the password:
node -e 'const u = new URL(process.env.DATABASE_URL); console.log(u.hostname, u.port)'
If that prints localhost, or throws because the variable is empty, the URL is the problem, not the network. Then run the command that failed from the same place the app runs, not from the build:
npx prisma migrate status
migrate status connects with the same URL; if it reaches the database, so will migrate deploy and the client.
On Livops
- Attach the database. Under Databases, add PostgreSQL 15, 16 or 17 (16 is the default), or MySQL 8.0 or 8.4. It runs in its own container inside the project environment. One 500 MB database per team is free.
- DATABASE_URL is written for you, into every service in the environment, including services added later, together with
PGHOST,PGPORT,PGUSER,PGPASSWORDandPGDATABASE. It looks likepostgresql://app:<password>@postgres:5432/app. Pointenv('DATABASE_URL')and the adapter’sconnectionStringat it and keep the value as Livops writes it. - Variables take effect on the next deploy. After adding a database, deploy again, or restart the service to apply it now.
- The build has no database.
prisma generateis fine there: when the project hasprismaandprisma/schema.prisma, Livops runsprisma generatebefore the build itself. Putnpx prisma migrate deployin the pre-deploy command, which runs before each new version starts; if it fails, the deploy stops aspredeploy_failedand the old version keeps serving. - No public port. The host is the internal name
postgres, reachable only from services in the project. Runningprisma migratefrom your laptop against it gives P1001; reach it through Connect from your computer, an SSH tunnel signed by your key, and uselocalhostwith the port the tunnel shows. - 20 connections. PostgreSQL accepts 20 connections at once, MySQL 30, and a built-in pooler (PgBouncer) is not offered yet. Keep pools small: on Prisma 7,
max: 5in the@prisma/adapter-pgoptions, which default to 10; on Prisma 6,?connection_limit=5inDATABASE_URL. - Staging gets its own database. A new environment gets an empty database of each type production has; run the migrations there too.
- A failed start keeps the old version. If the app stops on P1001 at start-up, the deploy fails as
start_failed, its last lines are on the Logs page, and a web app’s previous version keeps serving. The assistant button next to the failed deploy reads the log and says what to change.
A web app costs 39 credits a month, a worker 19. The variables are listed in Databases, the Prisma build step in Build failed, and the same case for other drivers in ECONNREFUSED: the app cannot reach its database.
Questions
What does P1001 mean in Prisma?
That Prisma could not reach a database server at the host and port in your connection URL. It is a network failure, not a login failure: wrong credentials give P1000 instead, and a server that was reached but did not answer in time gives P1002.
Why does P1001 say localhost after I deployed?
Because the URL Prisma used says localhost. It came from a .env file or a default in your code, not from the platform. In a deployed app localhost is the app's own container, where no database runs. Use the DATABASE_URL the platform gives you, and do not fall back to localhost.
Why does prisma migrate deploy fail with P1001 in the build?
Because the build cannot reach the database. On many platforms, Livops among them, the build has no database at all. prisma generate needs no database and can stay in the build; prisma migrate deploy belongs in a step that runs before the app starts.
Does Prisma 7 still read my .env file?
Not by itself. Prisma 7 does not load .env files: add import dotenv/config as the first line of prisma.config.ts, or set the variable in the environment. On a platform the variable is already in the environment, so nothing has to load it.
How many connections does Prisma open?
On Prisma 7 with the pg adapter, up to 10 per process, the pg pool's default max. On Prisma 6, the connection_limit URL parameter, which defaults to twice the number of physical CPUs plus one. Multiply by the number of processes that run Prisma and keep the total under the database's limit.
Is P1001 still the code in Prisma 8?
No. Prisma ORM 8 replaced the P codes with dotted namespace codes. This page is about Prisma 6 and 7, where the code is P1001.
Sources
- Prisma ORM v7 — Error reference (prisma.io). Checked .
- Prisma ORM v6 — Error reference (prisma.io). Checked .
- Prisma ORM v7 — Connection pool (prisma.io). Checked .
- Prisma ORM v7 — Prisma Config reference (prisma.io). Checked .
- Prisma ORM v7 — PostgreSQL (prisma.io). Checked .
- Prisma ORM v6 — PostgreSQL connection URL arguments (prisma.io). Checked .
- Prisma ORM v7 — Prisma CLI reference (migrate deploy) (prisma.io). Checked .
- Prisma ORM — Error reference (Prisma ORM 8) (prisma.io). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy with a databaseRelated
- ECONNREFUSED / Connection refused: why the app cannot reach its database after deployNothing was listening at the address your app tried. When the address is 127.0.0.1 or localhost, the app never read the database's real address: DATABASE_URL is not set, is not read, or is read during a build that has no database. Attach the database, read DATABASE_URL (or REDIS_URL, MYSQL_URL) at runtime, run migrations before the start rather than in the build, and keep the connection pool under the server's limit.
- Managed PostgreSQL hosting in 2026: the options comparedA production PostgreSQL needs backups you can restore, a connection limit your app stays under, the app in the same region, and a supported version. On Livops a PostgreSQL 15, 16 or 17 database runs inside your project, its DATABASE_URL is written into your services, and it is backed up every night; 500 MB is free, one per team, and 1 GB is 9 credits a month. Here is how Neon, Supabase, Render, Railway and a VPS compare.
- Node.js hosting in 2026: how to deploy an Express appA Node.js server in production needs one long-running process that listens on the port it is given, restarts when it crashes and exits cleanly on SIGTERM. On Livops you push a repository with package.json and it runs as a web app for 39 credits a month (39,000 so'm). Here is what Node needs, and how a VPS, Render, Railway, Fly.io, DigitalOcean and Heroku compare.
- Next.js hosting without Vercel: the options comparedNext.js runs on any host that runs Node: next build, then next start, and every feature works, Server Actions and image optimization included. On Livops a repository with next in package.json runs as a server from a push for 39 credits a month (39,000 so'm), and a static export is free. Here is how Vercel, Render, Railway, Fly.io and a VPS compare.
- 502 Bad Gateway after deploying: what it means and how to fix itThe proxy in front of your app reached for it and got no valid answer: nothing was listening on the port it tried, or the process closed the connection mid-request. After a deploy that is almost always one of five things: the app listens on the wrong port or on 127.0.0.1, it crashed on start, it was still starting, it ran out of memory, or the proxy points at the wrong port. The app's own log says which.
- A staging environment next to productionOn Livops, Add environment on the project page makes a staging copy of your production services, each with its own address, its own variables and its own empty database, so a test never touches production data. Promote to production then ships the exact release you tested, without rebuilding. A staging environment costs half; pull request previews are billed like regular services.