Created
February 2, 2022 23:34
-
-
Save taiar/67b7c998350ef09639e8ea979be4f68b to your computer and use it in GitHub Desktop.
Create a read only user on psql
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 ROLE _readonly_user_name_ WITH LOGIN PASSWORD '_readonly_user_password_' | |
NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION VALID UNTIL 'infinity'; | |
GRANT CONNECT ON DATABASE _database_to_give_access_ TO _readonly_user_name_; | |
GRANT USAGE ON SCHEMA public TO _readonly_user_name_; | |
GRANT SELECT ON ALL TABLES IN SCHEMA public TO _readonly_user_name_; | |
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO _readonly_user_name_; | |
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO _readonly_user_name_; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment