Skip to content

Instantly share code, notes, and snippets.

@fxkraus
Created July 4, 2017 15:35
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 fxkraus/a8a59e31b57c98aa264be74f915df6d1 to your computer and use it in GitHub Desktop.
Save fxkraus/a8a59e31b57c98aa264be74f915df6d1 to your computer and use it in GitHub Desktop.
PostgreSQL: Create read-only database user/role
CREATE USER username WITH PASSWORD 'the_password';
GRANT CONNECT ON DATABASE the_database TO username;
GRANT USAGE ON SCHEMA public TO username;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO username;
-- has to be executed while connected to the actual database
\c the_database
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO the_database;
GRANT SELECT ON ALL TABLES IN SCHEMA public to the_database;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment