Fix guides

Can't connect to Supabase Postgres from Prisma, Drizzle, or Vercel: password authentication failed, Tenant or user not found, P1013, ENETUNREACH

The Supabase client works, but your DATABASE_URL does not: password authentication failed, Tenant or user not found, Prisma P1013 invalid port number, ENETUNREACH on Vercel, or prepared statement already exists. Each error points at one part of the connection string. Here is which part and the fix.

Free · no card

Paste your error. Get a free diagnosis by email.

Tell us what broke and we’ll email you a short diagnosis: the likely cause and what to try first. Usually within a day.

No passwords or secret keys, please. We only use your email to reply about this.

What you are seeing

Why it happens

  1. Special characters in the password are not percent-encoded. Characters like @ : / % # ? & or a space change how the URL is split into user, password, host, and port. The result looks like a wrong password or a bad port, which is why resetting the password does not help if the new one also has symbols. Supabase and Prisma both say to percent-encode them.
  2. The username does not match the connection mode. Shared pooler (Supavisor) connections need postgres.<project-ref>; direct connections use plain postgres. The wrong one gives Tenant or user not found.
  3. The pooler host was typed or guessed. Hosts look like aws-1-us-east-2.pooler.supabase.com; the number is a cluster index, not part of the region, so aws-0-... is not a safe default. Copy it from the Connect dialog.
  4. The direct connection is IPv6 only (unless you buy the IPv4 add-on on Pro). Supabase lists Vercel, GitHub Actions, Render, and Retool as IPv4-only, so the direct string fails from there. The shared pooler is IPv4 on every plan.
  5. Transaction mode (port 6543 on the shared pooler) does not support prepared statements. Prisma needs pgbouncer=true, and Postgres.js / Drizzle need prepare: false.

How to fix it

1. Copy the exact string from Connect

In the Supabase dashboard click Connect at the top of the project. Serverless (Vercel functions, Netlify, edge): choose Transaction pooler (port 6543). Long-running server or migrations from an IPv4-only network (GitHub Actions, Render): choose Session pooler (port 5432). IPv6-capable server, or you have the IPv4 add-on: Direct connection is fine. Replace only [YOUR-PASSWORD]. Keep the host and username exactly as copied.

2. Percent-encode the password

# print the encoded form of your password (Node), then paste it into the URL
node -e "console.log(encodeURIComponent(process.argv[1]))" 'p@ss:w/rd#1?'
# -> p%40ss%3Aw%2Frd%231%3F

# or reset the database password (Database Settings, or Reset in the Connect dialog)
# to letters and digits only. A reset breaks every existing connection that uses the old password.

3. Check the username and port match the mode

# shared pooler, transaction mode (serverless)
postgresql://postgres.<project-ref>:<encoded-password>@<pooler-host>:6543/postgres
# shared pooler, session mode (IPv4 servers, migrations from CI)
postgresql://postgres.<project-ref>:<encoded-password>@<pooler-host>:5432/postgres
# direct (IPv6, or IPv4 add-on)
postgresql://postgres:<encoded-password>@db.<project-ref>.supabase.co:5432/postgres

4. Prisma: two URLs

# .env
DATABASE_URL="postgresql://postgres.<ref>:<encoded-password>@<pooler-host>:6543/postgres?pgbouncer=true"
# migrations use session mode (or direct)
DIRECT_URL="postgresql://postgres.<ref>:<encoded-password>@<pooler-host>:5432/postgres"

# point prisma migrate at DIRECT_URL (prisma.config.ts datasource url, or directUrl in schema.prisma on older Prisma),
# and let the app use DATABASE_URL

5. Drizzle / Postgres.js in serverless: turn off prepared statements

import postgres from 'postgres'
import { drizzle } from 'drizzle-orm/postgres-js'

// create once at module scope, not per request
const client = postgres(process.env.DATABASE_URL!, { prepare: false, max: 1, ssl: 'require' })
export const db = drizzle(client)

6. Check IPv6 from the machine that fails

# on the server or in a CI step: an IPv6 address back means IPv6 works there
curl -6 https://ifconfig.co/ip

# if it fails, use a pooler string, or add the IPv4 add-on (Pro plan, paid hourly)

7. Update the host's env vars and redeploy

Paste the new DATABASE_URL (and DIRECT_URL) into Vercel / Netlify / your CI secrets for every environment that needs it, then redeploy. Env changes do not apply to a deployment that is already built. Never put this URL in a NEXT_PUBLIC_ or VITE_ variable: it contains the database password.

How to know it is fixed

From the same environment that failed (a Vercel function, the CI job), run one simple query such as select 1 through your ORM, then a real page that reads data. prisma migrate deploy or drizzle-kit migrate finishes using the session or direct URL. Under load, the logs show no prepared statement errors. Sources: Supabase: Connect to your database, Supabase KB: password authentication failed, Supabase KB: Tenant or user not found, Supabase: IPv4 and IPv6 compatibility, Supabase: Prisma quickstart, Prisma: connection URLs (special characters). Related: Supabase Unhealthy or hibernated, 28P01, Environment variables undefined after deploy.