Skip to content

Instantly share code, notes, and snippets.

@okanmenevseoglu
Created February 23, 2018 06:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okanmenevseoglu/a0321f52f5baeff15e1d7d063e0789af to your computer and use it in GitHub Desktop.
Save okanmenevseoglu/a0321f52f5baeff15e1d7d063e0789af to your computer and use it in GitHub Desktop.
Creating User and Giving Granular Access to the User on PostgreSQL
-- Create new user to the DB
CREATE USER {{username}} WITH ENCRYPTED PASSWORD {{password}};
-- Give access connection to the wanted DB
GRANT CONNECT ON DATABASE {{dbname}} TO {{username}};
-- Give access to the wanted schema
GRANT USAGE ON SCHEMA {{schemaname}} TO {{userName}};
-- Give select access to the sequences for the wanted schema
GRANT SELECT ON ALL SEQUENCES IN SCHEMA {{schemaName}} TO {{userName}};
-- Give select access to the all tables for the wanted schema
GRANT SELECT ON ALL TABLES IN SCHEMA {{schemaName}} TO {{userName}};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment