Created
July 4, 2017 15:35
-
-
Save fxkraus/a8a59e31b57c98aa264be74f915df6d1 to your computer and use it in GitHub Desktop.
PostgreSQL: Create read-only database user/role
This file contains 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 username WITH PASSWORD 'the_password'; | |
GRANT CONNECT ON DATABASE the_database TO username; | |
GRANT USAGE ON SCHEMA public TO username; | |
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO username; | |
-- has to be executed while connected to the actual database | |
\c the_database | |
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO the_database; | |
GRANT SELECT ON ALL TABLES IN SCHEMA public to the_database; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment