Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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