Created
December 8, 2017 05:01
-
-
Save songpon/f515fe24183205f0d7591f6202c38e89 to your computer and use it in GitHub Desktop.
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 USER readonlyuser WITH ENCRYPTED PASSWORD 'secret'; | |
GRANT USAGE ON SCHEMA public to readonlyuser; | |
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonlyuser; | |
-- repeat code below for each database: | |
GRANT CONNECT ON DATABASE mydbname to readonlyuser; | |
\c mydbname | |
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO readonlyuser; --- this grants privileges on new tables generated in new database "foo" | |
GRANT USAGE ON SCHEMA public to readonlyuser; | |
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO readonlyuser; | |
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonlyuser; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment