Created
April 4, 2020 08:50
-
-
Save gpad/0e9130d2994eada1efac1c6f2f49f0f4 to your computer and use it in GitHub Desktop.
Script to create read_only user in PG
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 <user_name> WITH LOGIN PASSWORD '<password>' NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION; | |
| GRANT CONNECT ON DATABASE <db> TO <user_name>; | |
| \c <db> | |
| GRANT USAGE ON SCHEMA public TO <user_name>; | |
| GRANT SELECT ON ALL TABLES IN SCHEMA public TO <user_name>; | |
| GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO <user_name>; | |
| ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO <user_name>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment