P
Prisma•2mo ago
Lami

User was denied access on the database `postgres`

The application cannot connect to the database. Commands like prisma migrate dev, prisma studio, and prisma db pull work.
# SERVER_ERROR: [Error [PrismaClientKnownRequestError]:
Invalid `db[model].findFirst()` invocation in
D:\Desktop\Projects\aporo-app\.next\server\chunks\node_modules_better-auth_dist_30558edf._.js:1602:44

1599 if (!db[model]) {
1600 throw new __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$better$2d$auth$2f$dist$2f$shared$2f$better$2d$auth$2e$DdzSJf$2d$n$2e$mjs__$5b$app$2d$route$5d$__$28$ecmascript$29$__["B"](`Model ${model} does not exist in the database. If you haven't generated the Prisma client, you need to run 'npx prisma generate'`);
1601 }
→ 1602 return await db[model].findFirst(
User was denied access on the database `postgres`] {
code: 'P1010',
meta: [Object],
clientVersion: '6.16.3'
}
# SERVER_ERROR: [Error [PrismaClientKnownRequestError]:
Invalid `db[model].findFirst()` invocation in
D:\Desktop\Projects\aporo-app\.next\server\chunks\node_modules_better-auth_dist_30558edf._.js:1602:44

1599 if (!db[model]) {
1600 throw new __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$better$2d$auth$2f$dist$2f$shared$2f$better$2d$auth$2e$DdzSJf$2d$n$2e$mjs__$5b$app$2d$route$5d$__$28$ecmascript$29$__["B"](`Model ${model} does not exist in the database. If you haven't generated the Prisma client, you need to run 'npx prisma generate'`);
1601 }
→ 1602 return await db[model].findFirst(
User was denied access on the database `postgres`] {
code: 'P1010',
meta: [Object],
clientVersion: '6.16.3'
}
4 Replies
Prisma AI Help
Prisma AI Help•2mo ago
You selected the bot's instantaneous insights. Let me compile your answer right away! The error "User was denied access on the database postgres" (Prisma error code P1010) during runtime, while commands like prisma migrate dev, prisma studio, and prisma db pull work, typically points to a difference in how your application and the CLI commands are connecting to the database. Based on the knowledge sources, here are the most common causes and solutions: 1. Different Database Connections
The CLI commands may be connecting to a different PostgreSQL instance than your application. This often happens if you have multiple PostgreSQL servers running (e.g., one via Docker and another installed locally). The CLI might connect to the correct one, but your app connects to another, leading to access issues. Make sure all Postgres instances except the one you intend to use are stopped. Users have resolved this by quitting other local Postgres instances (like Postgres.app or pgAdmin) when using Docker, so only the intended instance is running migrate deploy: Error: P1010. 2. Connection String Issues
Double-check that your application and CLI are using the exact same DATABASE_URL. Even a small difference (like using localhost vs. 127.0.0.1, or a different port) can cause this. Also, ensure the user and password in the connection string are correct and have the necessary permissions migrate schema into postgresql and get Error P1010. 3. pg_hba.conf Configuration
If you are using peer authentication or have restrictive settings in your pg_hba.conf, the CLI and your app may be treated differently. Updating pg_hba.conf to allow trusted connections for localhost can resolve this. For example, change:
host all all 127.0.0.1/32 ident

host all all 127.0.0.1/32 ident

to
host all all 127.0.0.1/32 trust

host all all 127.0.0.1/32 trust

and restart PostgreSQL migrate deploy: Error: P1010. 4. Environment Variables in Production
If your app is running in a different environment (e.g., Docker, production server), ensure the environment variables are loaded correctly and match your local setup. Summary:
The issue is almost always due to a mismatch in database connection details or running multiple Postgres instances. Ensure your app and CLI use the same connection string and only one Postgres instance is running. If the problem persists, review your pg_hba.conf settings. If you need more specific help, please provide your DATABASE_URL and details about your environment setup. šŸ¤” Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Lami
LamiOP•2mo ago
Same DATABASE_URL prisma.config.ts
import dotenv from "dotenv";
import { defineConfig } from "prisma/config";

dotenv.config({
path: [
".env",
".env.local",
`.env.${process.env.NODE_ENV || "development"}`,
`.env.${process.env.NODE_ENV || "development"}.local`,
],
});

export default defineConfig({
experimental: {
externalTables: true,
},
tables: {
external: [
"public.awsdms_apply_exceptions",
"public.corporates_replicate",
"public.Corporate",
],
},
enums: {
external: ["public.TransactionType"],
},
});
import dotenv from "dotenv";
import { defineConfig } from "prisma/config";

dotenv.config({
path: [
".env",
".env.local",
`.env.${process.env.NODE_ENV || "development"}`,
`.env.${process.env.NODE_ENV || "development"}.local`,
],
});

export default defineConfig({
experimental: {
externalTables: true,
},
tables: {
external: [
"public.awsdms_apply_exceptions",
"public.corporates_replicate",
"public.Corporate",
],
},
enums: {
external: ["public.TransactionType"],
},
});
@Prisma AI Help Raw query failed. Code: 28000. Message: no pg_hba.conf entry for host "", user "postgres", database "postgres", no encryption
Nurul
Nurul•2mo ago
Are you running postgres locally or are you using a managed postgres offering?
Lami
LamiOP•2mo ago
PostgreSQL running on AWS RDS. I'm using Tailscale to connect into my VPC. It has been confirmed that the connection is possible through DBeaver.

Did you find this page helpful?