Skip to content

Instantly share code, notes, and snippets.

@pplonski
Created March 4, 2019 10:42
Show Gist options
  • Select an option

  • Save pplonski/49044e4f93950c157013ad40d61254b8 to your computer and use it in GitHub Desktop.

Select an option

Save pplonski/49044e4f93950c157013ad40d61254b8 to your computer and use it in GitHub Desktop.
Read only user in postgres database
-- create a group
CREATE ROLE readaccess;
-- grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
-- create user
CREATE USER user_name WITH PASSWORD 'secret_password';
GRANT readaccess TO user_name;
@pplonski
Copy link
Author

pplonski commented Mar 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment