'How to solve "User `postgres` was denied access on the database `.public`";?
I use prisma and node.js.
When I called some functions (example prisma.users.findAll()) in docker container I have error User 'postgres' was denied access on the database 'my_db.public', but if I run in local I don't have any problem.
However, my containers are successfully, but when I call any function with database I had an error.
My docker file
FROM node:15.13.0
RUN mkdir -p /project/node_modules && chown -R node:node /project
WORKDIR /project
COPY package*.json ./
COPY --chown=node:node prisma ./prisma
COPY config ./config
RUN npm install
RUN npx prisma generate
RUN npx prisma db push --preview-feature
COPY --chown=node:node ./temp ./temp
COPY --chown=node:node . .
CMD [ "node", "index.js" ]
Also, my db
my_db | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
prisma settings
DATABASE_URL=postgresql://postgres:[email protected]:5432/my_db?connect_timeout=300&connection_limit=150
Solution 1:[1]
If you can get the same error message by running either of these two prisma commands in your project,
npx prisma db pull
npx prisma generate
it means that the error comes from a bad DATABASE_URL value.
For example: the user should be chris instead of postgres.
// wrong user
DATABASE_URL="postgresql://postgres:passw@localhost:5432/dbname?schema=public"
// correct user
DATABASE_URL="postgresql://chris:passw@localhost:5432/dbname?schema=public"
Make sure you have the correct values.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | chris |
