Last active
November 13, 2019 04:11
-
-
Save aamsur-mkt/e6a2fa9a8b1fbe7179ff709755ed95cd to your computer and use it in GitHub Desktop.
Create user read only 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
# 1. To create a new user in PostgreSQL: | |
CREATE USER username WITH ENCRYPTED PASSWORD 'your_password'; | |
#2. GRANT the CONNECT access: | |
GRANT CONNECT ON DATABASE database_name TO username; | |
#3. Then GRANT USAGE on schema: | |
GRANT USAGE ON SCHEMA schema_name TO username; | |
#4. GRANT SELECT | |
#Grant SELECT for a specific table: | |
GRANT SELECT ON table_name TO username; | |
#Grant SELECT for multiple tables: | |
GRANT SELECT ON ALL TABLES IN SCHEMA schema_name TO username; | |
#If you want to grant access to the new table in the future automatically, you have to alter default: | |
ALTER DEFAULT PRIVILEGES IN SCHEMA schema_name | |
GRANT SELECT ON TABLES TO username; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment