Prisma P1010: the database user was denied access
P1010: 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.
Fix it fast
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.log2Match what you see, then jump to its fix
- 1
The 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
The server log shows the host, user and database that were rejectedNo pg_hba.conf rule or allow-list entry matches this clientFix - 3
The 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
- 1
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 encryptionP1011: 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
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 postgresql3Verify
Connect again with the same URL and see the query succeed.
psql "$DATABASE_URL" -c "SELECT 1;"Confirmed by postgresql.org
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
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
Databases
Prisma says P1000: the database credentials are not valid
Please make sure to provide valid database credentials for the database server at `localhost`.
P1000 means the server was reached but rejected the user and password in DATABASE_URL.
3 causes, each with a fixDatabases
Prisma says it can't reach the database server, but the database is up
Please make sure your database server is running at `localhost`:`5432`.
P1001 is Prisma's catch-all for any failed connection, even a wrong password, so do not trust the label.
4 causes, each with a fixDatabases
NestJS cannot open an SSL connection to a managed Postgres database
SELF_SIGNED_CERT_IN_CHAIN
TypeORM passes its ssl option to node-postgres, which hands it to Node's TLS layer.
4 causes, each with a fixDatabases
node-postgres fails locally with 'The server does not support SSL connections'
Error: The server does not support SSL connections
The client asked for SSL and the server answered that it has none.
3 causes, each with a fixDatabases
Sequelize fails with 'Operation timeout' while waiting for a connection
ConnectionAcquireTimeoutError
This error means Sequelize waited the full acquire time and no connection in its pool became free.
5 causes, each with a fixDatabases
Strapi cannot reach PostgreSQL on 127.0.0.1:5432
Error: connect ECONNREFUSED 127.0.0.1:5432
ECONNREFUSED means nothing accepted the connection at that address.
3 causes, each with a fix