Last active
November 12, 2021 13:39
-
-
Save surendra-wal/3011278db996d8d8f13446a47bc7c029 to your computer and use it in GitHub Desktop.
Create user in postgres with read only access
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
-- | |
-- Read only | |
-- | |
-- Create a group | |
CREATE ROLE cents_rd_group; | |
-- Grant access to existing tables | |
GRANT USAGE ON SCHEMA public TO cents_rd_group; | |
GRANT SELECT ON ALL TABLES IN SCHEMA public TO cents_rd_group; | |
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO cents_rd_group; | |
-- Grant access to future tables on select | |
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO cents_rd_group; | |
-- Create a final user with password | |
CREATE USER cents_rd WITH PASSWORD 'bhoom'; | |
GRANT cents_rd_group TO cents_rd; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment