Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres: Permission denied for schema even though grants were given

I am running Postgres 10.4 and am currently baffled since I can't seem to grant access to a schema to another role.

What I want to do:

I have one role with one schema and want to access the schema and its tables from another role. So I did the usual (what worked with other schemas):

grant usage on schema myschema to newuser;

grant select on all tables in schema myschema to newuser;

Both of those statements were run as the owner of the schema. I didn't run into any errors while doing so.

When I log in as the newuser and try to select some data:

select * from myschema.table;

I get the error:

SQL Error [42501]: ERROR: permission denied for schema myschema

I can see that the newuser has the right privileges in the table "information_schema.role_table_grants"

It also worked with another role and another schema. I'm clueless.

like image 766
kidman01 Avatar asked Jan 28 '23 07:01

kidman01


2 Answers

Step 1
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA name_schema TO name_user;

Step 2
GRANT USAGE ON SCHEMA name_schema TO name_user;

like image 139
Reaper_20 Avatar answered Jan 29 '23 21:01

Reaper_20


It definitely works as posted in my question, the problem was that I didn't user the owner of the schema.

So always make sure you grant access to a schema from the owner role.

like image 30
kidman01 Avatar answered Jan 29 '23 22:01

kidman01