I have a DB in Postgres that i administrate with the admin user and i want to create a schema and tables for an application user.
I am creating the schema and the app user with the admin user and then i grant:
GRANT SELECT, UPDATE, INSERT, DELETE ON ALL TABLES IN SCHEMA my_schema to my_user;
Then i create my tables inside my_schema, but when i try to access them with my_user i get permission denied:
ERROR permission denied for table my_table
Is there a way to solve this?
Thank you
2
Answers
If you want to have mentioned privileges for your ‘my_user’. You need to have USAGE privilege.
What you need to do in order to successfully retrieve data from tables in schema ‘my_schema’. If I understand your question correctly. You should follow this:
GRANT … ON ALL TABLES
does not include future tables. You were granting permissions on all tables currently in the schema, then you were creating new tables. Those new tables won’t have any permissions granted tomy_user
.You can either
move the
GRANT … ON ALL TABLES
statement after the creation of the tables on which you want to grant the privileges, orchange the default privileges that will be applied to new objects (i.e. tables):
This will automatically
GRANT
the specified privileges tomy_user
on any new table thatadmin_user
will create.