Skip to content

Instantly share code, notes, and snippets.

@gc
Created May 28, 2022 08:36
Show Gist options
  • Save gc/3d749160c77cf81dc8114bac0aecb234 to your computer and use it in GitHub Desktop.
Save gc/3d749160c77cf81dc8114bac0aecb234 to your computer and use it in GitHub Desktop.
Read only postgres user
```sql
CREATE ROLE read_only;
GRANT USAGE ON SCHEMA public TO read_only;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO read_only;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO read_only;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO read_only;
CREATE USER reader WITH PASSWORD 'hunter2';
GRANT read_only TO reader;
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment