Created
October 10, 2014 01:26
-
-
Save dznz/f9dcd594427aa31f6d8f to your computer and use it in GitHub Desktop.
Set up a read-only user in Postgresql
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 LOGIN PASSWORD 'some_pass'; | |
-- Existing objects | |
GRANT CONNECT ON DATABASE the_db TO readonly; | |
GRANT USAGE ON SCHEMA public TO readonly; | |
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly; | |
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO readonly; | |
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO readonly; | |
-- New objects | |
ALTER DEFAULT PRIVILEGES FOR owner_user IN SCHEMA public GRANT SELECT ON TABLES TO readonly; | |
ALTER DEFAULT PRIVILEGES FOR owner_user IN SCHEMA public GRANT SELECT ON SEQUENCES TO readonly; | |
ALTER DEFAULT PRIVILEGES FOR owner_user IN SCHEMA public GRANT EXECUTE ON FUNCTIONS TO readonly; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment