So I'm making this app and I'm using Postgres and I've already created a database, a user and a password and granted all privileges on the database to the user I've created.
The thing is, when I switch the database in psql using \c <database_name> I get in just fine and can use queries on it.
But when I run psql using postgres://user_name:password@localhost:5432/databasename on terminal and try to select * from the <table_name> it gives me this message
permission denied for relation <table_name>
Can you please tell me what to do, I've had this problem before and I had to create another database or change the user but I want a better solution please.
PS: I've tried to use this :
GRANT ALL PRIVILEGES ON TABLE <table_name> to <user_name>
This is how I created and accessed my database:
rawan95=# create database food ;
CREATE DATABASE
rawan95=# create user meal with password '123';
CREATE ROLE
rawan95=# grant all privileges on database food to meal;
GRANT
rawan95=# \c food
You are now connected to database "food" as user "rawan95".
After that, I've built it using
food=# \i src/database/db_build.sql
BEGIN
DROP TABLE
CREATE TABLE
INSERT 0 1
COMMIT
Then I selected data from the table just fine, but when I try to access it using this, I get an error: psql postgres://meal:123@localhost:5432/food
food=> select * from foods;
ERROR: permission denied for relation foods
\c <database_name>uses the same user as the previous connection. Whereaspsql postgres://user_name:password@localhost:5432/databasenameuses a different user - so apparently you did not grant all needed privilege to the second user - a_horse_with_no_namepsql postgres://user_name:password@localhost:5432/databasename, then run my\i db_build.sqlto create my tables, right? - Rawan Al-Rajabi\cbut you also need to specify the user you want to change to\c databasename user_name- a_horse_with_no_name