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.
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.
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 message | What it tells you | Go to |
|---|---|---|
localhost, 127.0.0.1 or db | The production variable is missing or copied from local .env or Docker Compose | Cause 1 |
something.railway.internal | Railway private network, only reachable at runtime inside the same project and environment | Cause 2 |
db.<ref>.supabase.co, port 5432 | Supabase direct connection, IPv6 unless you bought the IPv4 add-on | Cause 3 |
aws-...pooler.supabase.com | Supabase pooler. Reachable over IPv4, so look at the project status, password or SSL | Causes 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.
# 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
| Cause | Where it fails | Fix |
|---|---|---|
| Local URL in production | Everywhere | Set the real URL on the host and redeploy |
railway.internal during build | Build log, migrate step | Move migrations to the pre-deploy or start command |
railway.internal from Vercel or a laptop | Any request | Enable the TCP proxy and use DATABASE_PUBLIC_URL |
| Supabase direct string on IPv4-only host | Vercel functions, CI | Use the session or transaction pooler |
| Project paused or database stopped | Everything, suddenly | Resume or restart it in the dashboard |
| TLS or timeout settings | Intermittent, or after a Prisma upgrade | Set 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.
# 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/ipWhat the psql result tells you
could not translate host name: DNS. The host does not exist from here, which is therailway.internalfrom outside case or a typo.Network is unreachablewith an IPv6 address: the host has no IPv6 route. Switch to the Supabase pooler.Connection refusedor a timeout: the name resolved but nothing listens, or a firewall blocks it. Check the port, that public access is on, and that the database is running.password authentication failed: the network is fine. Prisma would show P1000 here, so you are looking at a different string from the one that failed.1printed: the string works from this machine. Compare it character by character with the value the deployed app actually reads.
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
- Prisma docs: Error referencedocs.prisma.io
- Prisma docs: PostgreSQL (v6 connection URL arguments)docs.prisma.io
- Prisma docs: PostgreSQL (v7)prisma.io
- Prisma docs: Upgrade to v7prisma.io
- Railway docs: Private networking, how it worksdocs.railway.com
- Railway docs: PostgreSQLdocs.railway.com
- Railway docs: Pre-deploy commanddocs.railway.com
- Railway docs: railway connectdocs.railway.com
- Supabase docs: Connect to your databasesupabase.com
- Supabase docs: Prismasupabase.com
- Supabase docs: IPv4 and IPv6 compatibilitysupabase.com
- Vercel docs: Environment variablesvercel.com
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.