Last active
April 2, 2024 10:35
-
-
Save swapnilman/cccfbd6f4efc49b7cbc436583622e8f0 to your computer and use it in GitHub Desktop.
Add user with read only access 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 a group | |
| CREATE ROLE readonly; | |
| # 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 user with password and assign group | |
| CREATE USER reader WITH PASSWORD 'password'; | |
| GRANT readonly TO reader; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment