Tuesday, March 7, 2017

Creating ReadOnly user in Postgres



Very simple but easily forgotten. :)

1. Grant permissions to connect to your database
GRANT CONNECT ON DATABASE my_db TO my_user;
2. Grant permission to use the schema that you want to
GRANT USAGE ON SCHEMA public TO my_user;
GRANT USAGE ON SCHEMA my_schema TO my_user;
3. Grant only select for the user
GRANT SELECT ON ALL TABLES IN SCHEMA public TO my_user;
GRANT SELECT ON ALL TABLES IN SCHEMA my_schema TO my_user;
4. Sometimes it might be necessary to run this also
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO my_user;
Cheers.

No comments :