Skip to content

Instantly share code, notes, and snippets.

@taiar
Created February 2, 2022 23:34
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 taiar/67b7c998350ef09639e8ea979be4f68b to your computer and use it in GitHub Desktop.
Save taiar/67b7c998350ef09639e8ea979be4f68b to your computer and use it in GitHub Desktop.
Create a read only user on psql
CREATE ROLE _readonly_user_name_ WITH LOGIN PASSWORD '_readonly_user_password_'
NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION VALID UNTIL 'infinity';
GRANT CONNECT ON DATABASE _database_to_give_access_ TO _readonly_user_name_;
GRANT USAGE ON SCHEMA public TO _readonly_user_name_;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO _readonly_user_name_;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO _readonly_user_name_;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO _readonly_user_name_;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment