Prisma P1001 "Can't reach database server" in production

Prisma P1001 means nothing answered at the host and port in DATABASE_URL. Fix localhost URLs, Railway private hosts at build time and Supabase IPv6.

Simon, Founder of Shipyard

By · Founder of Shipyard

7 minute read

What P1001 means

Prisma error P1001, "Can't reach database server at host:port", means Prisma could not open a network connection to the address in your connection string. It is not a password problem: that is P1000. In production on Railway, Vercel or Supabase the usual causes are a DATABASE_URL that still points at localhost, a Railway *.railway.internal host used at build time or from outside the project, or a Supabase direct connection (IPv6) used from a host that only has IPv4. Read the host in the message, match it to the table below, and test that exact string with psql from the same place the app runs.

The error message already tells you most of what you need, because it prints the host and port Prisma tried. Start there before changing anything.

The exact message

From prisma migrate deploy or prisma db push it looks like the first block. From the running app on Prisma 6 and earlier it arrives as a PrismaClientInitializationError with the same text. On Prisma 7 the client connects through a driver adapter such as pg, so a runtime failure can surface as that driver's error instead, for example ENOTFOUND or ECONNREFUSED. The causes are the same.

Text
Error: P1001: Can't reach database server at `postgres.railway.internal`:`5432`

Please make sure your database server is running at `postgres.railway.internal`:`5432`.

Read the host first

Host in the messageWhat it tells youGo to
localhost, 127.0.0.1 or dbThe production variable is missing or copied from local .env or Docker ComposeCause 1
something.railway.internalRailway private network, only reachable at runtime inside the same project and environmentCause 2
db.<ref>.supabase.co, port 5432Supabase direct connection, IPv6 unless you bought the IPv4 add-onCause 3
aws-...pooler.supabase.comSupabase pooler. Reachable over IPv4, so look at the project status, password or SSLCauses 3 and 4

Cause 1: the URL still points at your laptop

If the message names localhost, the app is using the value from your local .env or a default in code. A deployed container has no database on its own localhost. The same goes for a service name like db from Docker Compose, which only resolves inside that Compose network.

Check the variable on the host, not in your repository. On Vercel, environment variables are set per environment (Production, Preview, Development), and Vercel's docs say a change only applies to new deployments, so redeploy after fixing it. On Railway, check the service's Variables tab. If the app reads a different name, such as POSTGRES_URL, setting DATABASE_URL does nothing. Also note that Prisma 7 no longer loads .env files by itself, so local runs need dotenv or your framework to load them.

Cause 2: Railway private networking

Railway's Postgres service exposes a DATABASE_URL that uses its private hostname, in the form <service-name>.railway.internal. Railway's docs set out three limits on that hostname. It works only inside the same project and environment, so a different Railway project cannot use it. It works only at runtime: private networking is not available during the build phase. And anything outside Railway, including Vercel and your own computer, cannot resolve it at all.

The build limit is the one that catches most people. A build command such as prisma migrate deploy && next build, or a framework that queries the database while pre-rendering pages, runs before the private network exists, and fails with P1001 on the railway.internal host. Railway's answer is the pre-deploy command, which runs after the build, inside the private network, with the service's variables. Put npx prisma migrate deploy there, or in the start command, and keep the build free of database calls.

To reach a Railway database from outside, enable public access in the database's networking settings. Railway then creates a TCP proxy and fills in DATABASE_PUBLIC_URL. Use that from Vercel or your laptop. Railway bills TCP proxy traffic as network egress, so a Railway app should keep using the private URL at runtime.

One more detail: Railway environments created before 16 October 2025 resolve private names to IPv6 addresses only. Newer ones return IPv4 and IPv6. Node's Postgres drivers handle IPv6, but a custom client bound to IPv4 may not.

Cause 3: Supabase direct connection and IPv6

Supabase offers three connection strings and they do not behave the same on the network. Supabase's docs say all databases have a direct connection string that maps to an IPv6 address, and that the shared pooler is IPv4. Supabase names Vercel, GitHub Actions and Render among platforms that only accept IPv4 connections, so a direct string from any of them fails with P1001 even though the project is healthy.

Use the pooler instead, from the project's Connect dialog. Supabase's Prisma guide gives two layouts. For a long-running server, set DATABASE_URL to the Session pooler string on port 5432 and use it for both the app and migrations. For serverless, such as Vercel functions, set DATABASE_URL to the Transaction pooler on port 6543 with ?pgbouncer=true, which turns off prepared statements, and add DIRECT_URL with the session or direct string for migrations. On Prisma 7 the migration URL goes in prisma.config.ts, not schema.prisma.

If you want the direct connection from an IPv4 host, Supabase sells an IPv4 add-on on paid plans. To check whether a server has IPv6 at all, Supabase suggests running curl -6 https://ifconfig.co/ip on it. Supabase also pauses inactive Free plan projects, and a paused project cannot process requests, so check the dashboard if the same string worked last week.

Text
# Supabase, serverless (from the Connect dialog; values are examples)
DATABASE_URL="postgresql://postgres.abcdefgh:PASSWORD@aws-0-eu-central-1.pooler.supabase.com:6543/postgres?pgbouncer=true"
DIRECT_URL="postgresql://postgres.abcdefgh:PASSWORD@aws-0-eu-central-1.pooler.supabase.com:5432/postgres"

Cause 4: SSL and timeouts

SSL problems more often produce their own error, such as P1011 for a failed TLS connection, but a wrong setting can also look like an unreachable server. Prisma's PostgreSQL connector accepts sslmode with the values prefer, require and disable, and prefer is the default. For a hosted database over the public internet, adding sslmode=require makes the intent explicit.

Prisma 7 changed two defaults. It uses node-pg underneath, so certificate checks are stricter than in Prisma 6, which ignored invalid certificates. And the pg driver has no connection timeout by default, where Prisma 6 waited five seconds. Prisma's upgrade guide shows how to set connectionTimeoutMillis on the adapter. On Prisma 6, Supabase's older troubleshooting advice was to add connect_timeout=30 for slow first connections.

Causes at a glance

CauseWhere it failsFix
Local URL in productionEverywhereSet the real URL on the host and redeploy
railway.internal during buildBuild log, migrate stepMove migrations to the pre-deploy or start command
railway.internal from Vercel or a laptopAny requestEnable the TCP proxy and use DATABASE_PUBLIC_URL
Supabase direct string on IPv4-only hostVercel functions, CIUse the session or transaction pooler
Project paused or database stoppedEverything, suddenlyResume or restart it in the dashboard
TLS or timeout settingsIntermittent, or after a Prisma upgradeSet sslmode=require and a connection timeout

Test the exact string with psql

Prisma adds nothing to the network path, so if psql cannot connect with the same string from the same place, Prisma cannot either. Test from where the app runs whenever you can. A string that works on your laptop proves little about a private Railway hostname.

On Railway, railway connect opens psql against the database. Railway's CLI docs say it uses the public TCP proxy if one exists and otherwise falls back to an SSH tunnel, so it shows whether the database is up, not whether your app's private URL resolves. To test the private path, put a short check in the pre-deploy command and read the deploy log.

Terminal
# 1. Does the host resolve, and to what kind of address?
nslookup db.abcdefgh.supabase.co

# 2. Does the exact string connect? Quote it.
psql "$DATABASE_URL" -c 'select 1'

# 3. Same, forcing TLS
psql "postgresql://user:pass@host:5432/db?sslmode=require" -c 'select 1'

# 4. Railway: open psql against the project's database
railway connect

# 5. Does this server have IPv6?
curl -6 https://ifconfig.co/ip

What the psql result tells you

Keep migrations out of the build

Running migrations as part of the build is the pattern most likely to bring this error back. It ties a successful build to database access, which Railway's build does not have on the private network. Run prisma migrate deploy in a step that runs once per release with the real network: Railway's pre-deploy command, a release step in CI with the public or direct URL, or the start command if nothing else is available. Keep prisma generate in the build, because it needs no database.

When Shipyard sets up the database, it puts the connection string on the host as DATABASE_URL: a reference to the Railway Postgres service, or Supabase's pooled string read from its API. Our guides to Next.js and Postgres on Railway and to Supabase connection strings cover those setups in more detail.

Sources

Launch in an hour, not a weekend

Shipyard connects your accounts once, then sets up the domain, hosting, database, email and payments for every new product.

Get started See how it works

Read next