Skip to content

Instantly share code, notes, and snippets.

@sitano
Created June 8, 2017 15:33
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 sitano/98499fc64409024de3aff22c54593ab6 to your computer and use it in GitHub Desktop.
Save sitano/98499fc64409024de3aff22c54593ab6 to your computer and use it in GitHub Desktop.
PostgreSQL create read only user
-- Create a group
CREATE ROLE readonly WITH LOGIN;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly;
-- Create a final user with password
CREATE USER readonly WITH ENCRYPTED PASSWORD 'secret';
GRANT readonly TO readonly;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment