Skip to content

Instantly share code, notes, and snippets.

@dznz
Created October 10, 2014 01:26
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 dznz/f9dcd594427aa31f6d8f to your computer and use it in GitHub Desktop.
Save dznz/f9dcd594427aa31f6d8f to your computer and use it in GitHub Desktop.
Set up a read-only user in Postgresql
CREATE ROLE readonly LOGIN PASSWORD 'some_pass';
-- Existing objects
GRANT CONNECT ON DATABASE the_db TO readonly;
GRANT USAGE ON SCHEMA public TO readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO readonly;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO readonly;
-- New objects
ALTER DEFAULT PRIVILEGES FOR owner_user IN SCHEMA public GRANT SELECT ON TABLES TO readonly;
ALTER DEFAULT PRIVILEGES FOR owner_user IN SCHEMA public GRANT SELECT ON SEQUENCES TO readonly;
ALTER DEFAULT PRIVILEGES FOR owner_user IN SCHEMA public GRANT EXECUTE ON FUNCTIONS TO readonly;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment