Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgres table privileges do not allow user to create/select view

Tags:

sql

postgresql

I am managing a database that has a number of schemas. I am having some difficulty with setting privileges and would like to request some help.

I have the schema called schemaA and a group_role db_writer

I use the following sql:

GRANT USAGE ON SCHEMA schemaA TO db_writer;
GRANT UPDATE, INSERT, SELECT, DELETE ON ALL TABLES IN SCHEMA schemaA TO db_writer;

However, the db_writer is unable to create views. They are returned with a permission denied error. Also, when I create views, she is then unable to select them...and I have to set the priviliges again for that view.

It was my understanding the views were treated as tables with respect to privileges...and if one is granted certain permissions to all tables in a schema this would apply to views also.

What am I missing? Any advice appreciated.

like image 494
user3770062 Avatar asked Dec 10 '14 14:12

user3770062


People also ask

How do I fix Postgres permission denied?

Grant privileges to a new user We resolve this permission denied error using the command. GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO new_user; The new_user was then able to read data from the table. Similarly, we can also resolve the permission denied error by setting DEFAULT privileges to the user.


1 Answers

The problem is USAGE does not allow users to create objects within the database.

Try

GRANT USAGE, CREATE ON SCHEMA schemaA TO db_writer 

Edit:

New objects will get default privileges, for the user to have those privileges for objects created in the future you can do it as:

ALTER DEFAULT PRIVILEGES IN SCHEMA schemaA GRANT UPDATE, INSERT, SELECT, DELETE ON TABLES TO db_writer;
ALTER DEFAULT PRIVILEGES IN SCHEMA schemaA GRANT SELECT ON TABLES TO db_reader;

Check this answer for more info

like image 99
Filipe Roxo Avatar answered Oct 06 '22 00:10

Filipe Roxo