Created
January 14, 2021 06:04
-
-
Save luckylu/981db2d4f723ad355c23c6a6bf038531 to your computer and use it in GitHub Desktop.
create readonly user on postgresql 9
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 readonly WITH ENCRYPTED PASSWORD 'readonly'; | |
GRANT USAGE ON SCHEMA public to readonly; | |
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly; | |
-- repeat code below for each database: | |
GRANT CONNECT ON DATABASE foo to readonly; | |
\c foo | |
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly; --- this grants privileges on new tables generated in new database "foo" | |
GRANT USAGE ON SCHEMA public to readonly; | |
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO readonly; | |
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment