Created
December 25, 2021 21:31
-
-
Save hbasria/699ca60bce29d4fb49ef1ac5a0401d32 to your computer and use it in GitHub Desktop.
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
-- 1. Create a group | |
CREATE ROLE readaccess; | |
-- 2. Grant usage on schema: | |
GRANT USAGE ON SCHEMA schema_name TO readaccess; | |
-- 3.1 Grant select for a specific table: | |
GRANT SELECT ON table_name TO readaccess; | |
-- 3.2 Grant select for multiple tables: | |
GRANT SELECT ON ALL TABLES IN SCHEMA schema_name TO readaccess; | |
-- 4. 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 readaccess; | |
-- 5. To create a new user in PostgreSQL | |
CREATE USER username WITH PASSWORD 'your_password'; | |
-- 6 Grant the connect access: | |
GRANT CONNECT ON DATABASE database_name TO username; | |
-- 7 Grant the read access: | |
GRANT readaccess TO username; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment