Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

Prisma says P1000: the database credentials are not valid

ErrorP1000: Authentication failed against database server at `localhost`, the provided database credentials for `postgres` are not valid.

Short answer

P1000 means the server was reached but rejected the user and password in DATABASE_URL. With a Postgres container the usual reasons are: the volume was created with an older POSTGRES_PASSWORD, the password has characters that need percent-encoding, or Prisma reads a different .env file than the one you edited.

  • Applies to Prisma 6, postgres Docker image 17, Docker Compose 2, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Log in with psql using the exact user and password from DATABASE_URL, outside Prisma. If this fails too, the problem is the database side; if it works, look at how Prisma reads the URL.

    grep -n DATABASE_URL .env
    docker compose exec db psql -U postgres -c "select current_user;"
  2. 2Match what you see, then jump to its fix

    1. 1You changed POSTGRES_PASSWORD in compose.yaml, restarted, and P1000 stayed.The volume still holds an older passwordFix
    2. 2The password has characters such as @, :, / or # and the same text works in psql.The password contains characters that are not URL-encodedFix
    3. 3The URL in the file you changed is right, yet the error names an old user or host.Prisma reads a different .env than the one you editedFix

What does the error look like?

  • P1000: Authentication failed against database server at `localhost`, the provided database credentials for `postgres` are not valid.
  • Please make sure to provide valid database credentials for the database server at `localhost`.

Cause 1 of 3

The volume still holds an older password

1Check

The image applies POSTGRES_PASSWORD only when it starts with an empty data directory. A volume from an earlier run keeps whatever password it was first created with, so the new value in the file is ignored.

docker volume ls
docker compose config | grep -n -A3 volumes

2Fix

Either set the role's password inside the running database to match DATABASE_URL, or, if the data is disposable, remove the volume so the container initialises again with the current value.

# keep the data: change the password in place
docker compose exec db psql -U postgres -c "ALTER ROLE postgres WITH PASSWORD 'new-password';"

# throw the data away and start clean
docker compose down -v
docker compose up -d

3Verify

Run a Prisma command that opens a connection.

npx prisma migrate status

Confirmed by hub.docker.com

Did this fix it?

Cause 2 of 3

The password contains characters that are not URL-encoded

1Check

Prisma requires percent-encoding of special characters in any part of a PostgreSQL connection URL, passwords included. An unencoded @ ends the password early.

grep -n DATABASE_URL .env

2Fix

Encode the password in the URL (for example @ becomes %40), or choose a password without such characters.

# password: p@ss:word
DATABASE_URL="postgresql://postgres:p%40ss%3Aword@localhost:5432/mydb"

3Verify

The same Prisma command now connects.

npx prisma migrate status

Confirmed by prisma.io

Did this fix it?

Cause 3 of 3

Prisma reads a different .env than the one you edited

1Check

The Prisma CLI looks for .env in several places in order: the project root, the schema folder, the path from package.json and ./prisma. A second file in one of these, or a variable already set in your shell, can win over the one you changed. Prisma Client itself only loads the root .env on its own.

find . -name ".env*" -not -path "./node_modules/*"
env | grep DATABASE_URL

2Fix

Keep one definition of DATABASE_URL, remove stale copies, and unset any old value in the shell.

unset DATABASE_URL
npx prisma migrate status

3Verify

The command connects without P1000.

npx prisma migrate status

Confirmed by prisma.io

Did this fix it?

How do I stop it coming back?

  • Treat POSTGRES_PASSWORD as an initial value only; change an existing password with ALTER ROLE or psql's \password.
  • Generate passwords from letters and digits, or encode them before putting them in a URL.
  • Keep DATABASE_URL in one .env file and load it the same way in the CLI and in the app.
  • Test every new URL with psql first, so Prisma is never the first thing to try it.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Databases

The Postgres container rejects the password you set in POSTGRES_PASSWORD

psql: error: connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "postgres"

The official Postgres image reads POSTGRES_PASSWORD only when it creates a new database cluster in an empty data directory.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.