Created
June 8, 2017 15:33
-
-
Save sitano/98499fc64409024de3aff22c54593ab6 to your computer and use it in GitHub Desktop.
PostgreSQL create read only user
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 a group | |
CREATE ROLE readonly WITH LOGIN; | |
-- Grant access to existing tables | |
GRANT USAGE ON SCHEMA public TO readonly; | |
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly; | |
-- Grant access to future tables | |
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly; | |
-- Create a final user with password | |
CREATE USER readonly WITH ENCRYPTED PASSWORD 'secret'; | |
GRANT readonly TO readonly; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/760210/how-do-you-create-a-read-only-user-in-postgresql