Created
March 4, 2019 10:42
-
-
Save pplonski/49044e4f93950c157013ad40d61254b8 to your computer and use it in GitHub Desktop.
Read only user in postgres database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- create a group | |
CREATE ROLE readaccess; | |
-- grant access to existing tables | |
GRANT USAGE ON SCHEMA public TO readaccess; | |
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess; | |
-- grant access to future tables | |
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess; | |
-- create user | |
CREATE USER user_name WITH PASSWORD 'secret_password'; | |
GRANT readaccess TO user_name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The gist is based on:
The blog post:
https://pplonski.github.io/read-only-user-in-postgres/