Skip to content

Instantly share code, notes, and snippets.

@francisco-rojas
Last active June 6, 2017 13:47
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 francisco-rojas/da8234ce90b9dabd44dd60bbeaa133ac to your computer and use it in GitHub Desktop.
Save francisco-rojas/da8234ce90b9dabd44dd60bbeaa133ac to your computer and use it in GitHub Desktop.
Postgresql read only user
# create user with password
CREATE USER read_user WITH ENCRYPTED PASSWORD 'password';

# grant access to existing tables
GRANT CONNECT ON DATABASE cpu TO read_user;
GRANT USAGE ON SCHEMA public TO read_user;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO read_user;
GRANT SELECT ON ALL TABLES IN SCHEMA public to read_user;

# grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO read_user;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment