Skip to content

Instantly share code, notes, and snippets.

@olance
Created May 28, 2019 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olance/48f216ea16ab134521f8a596973bb953 to your computer and use it in GitHub Desktop.
Save olance/48f216ea16ab134521f8a596973bb953 to your computer and use it in GitHub Desktop.
A snippet to quickly create a read-only user for a postgresql DB
CREATE user <username> with encrypted password '<password>';
GRANT CONNECT ON DATABASE <db_name> TO <username>;
GRANT USAGE ON SCHEMA public TO <username>;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO <username>;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO <username>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment