Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

Prisma P1010: the database user was denied access

ErrorP1010: User `app_user` was denied access on the database `appdb`

Short answer

P1010 means the database server refused the connection for that user and database. With PostgreSQL the usual reasons are that the server requires TLS and the client did not use it, no pg_hba.conf rule matches the client's address, user or database, or the role has no CONNECT right. The server log names which one.

  • Applies to Prisma ORM 7, PostgreSQL 16, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the PostgreSQL server log at the time of the failed connection. It states the exact reason, and the next steps depend on it.

    sudo tail -n 30 /var/log/postgresql/postgresql-16-main.log
  2. 2Match what you see, then jump to its fix

    1. 1The server log says no pg_hba.conf entry ... no encryption, often right after upgrading to Prisma ORM 7The server requires TLS and the client connects without itFix
    2. 2The server log shows the host, user and database that were rejectedNo pg_hba.conf rule or allow-list entry matches this clientFix
    3. 3The server log names a permission problem for the role on the database or schemaThe role may not connect to the database or use the schemaFix

What does the error look like?

  • P1010: User `app_user` was denied access on the database `appdb`
  • no pg_hba.conf entry for host "...", user "...", database "...", no encryption
  • P1011: Error opening a TLS connection

Cause 1 of 3

The server requires TLS and the client connects without it

1Check

The node-postgres driver behind the Prisma adapter connects without TLS by default, while Prisma ORM 6 defaulted to prefer. A host or provider that only allows encrypted connections then rejects the client. Look at whether your URL has an sslmode.

echo "$DATABASE_URL" | sed -E "s#//[^@]*@#//***@#"

2Fix

Turn TLS on in the connection string. If your provider uses a private certificate authority, pass the CA in code and keep sslmode out of the URL.

DATABASE_URL="postgres://USER:PASSWORD@HOST:5432/DB?sslmode=verify-full"

// private CA
import { readFileSync } from "node:fs";
import { PrismaPg } from "@prisma/adapter-pg";
const adapter = new PrismaPg({
  connectionString: process.env.DATABASE_URL, // no sslmode or sslrootcert in it
  ssl: { ca: readFileSync("./certs/ca.pem", "utf8") },
});

3Verify

Run any query. P1010 is gone, and a wrong CA would now show as P1011 instead.

psql "$DATABASE_URL" -c "SELECT 1;"

Confirmed by prisma.io

Did this fix it?

Cause 2 of 3

No pg_hba.conf rule or allow-list entry matches this client

1Check

The same message appears when no rule covers your client's address, user or database. On a managed database, the provider's IP allow list works the same way. Rules are read top to bottom and the first match decides, and with no match access is denied. Compare the three values in the log with your rules.

sudo grep -v '^#' /etc/postgresql/16/main/pg_hba.conf | grep -v '^$'

2Fix

Add a rule for the real client address, user and database, then reload PostgreSQL. On a provider, add the client's IP to the allow list instead.

# pg_hba.conf
hostssl  appdb  app_user  203.0.113.10/32  scram-sha-256
# then reload (or run SELECT pg_reload_conf(); in psql)
sudo systemctl reload postgresql

3Verify

Connect again with the same URL and see the query succeed.

psql "$DATABASE_URL" -c "SELECT 1;"

Confirmed by postgresql.org

Did this fix it?

Cause 3 of 3

The role may not connect to the database or use the schema

1Check

Check the privileges the role holds on the database and on the public schema from a superuser session.

sudo -u postgres psql -d appdb -c "\l+ appdb"
sudo -u postgres psql -d appdb -c "\dn+ public"

2Fix

Grant the role the rights it needs: CONNECT on the database, USAGE on the schema and the table privileges.

GRANT CONNECT ON DATABASE appdb TO app_user;
GRANT USAGE ON SCHEMA public TO app_user;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO app_user;

3Verify

Run the query that failed, as that role.

psql "$DATABASE_URL" -c "SELECT 1;"

Confirmed by postgresql.org

Did this fix it?

How do I stop it coming back?

  • Put sslmode in the connection string of every environment, so staging and production behave alike.
  • Keep the pg_hba.conf rule or allow-list entry in your infrastructure code, not only on one server.
  • After upgrading Prisma ORM, run one query against each environment before the release.

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

Next step

Want this handled for good?

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