Skip to content

Instantly share code, notes, and snippets.

@swapnilman
Last active April 2, 2024 10:35
Show Gist options
  • Select an option

  • Save swapnilman/cccfbd6f4efc49b7cbc436583622e8f0 to your computer and use it in GitHub Desktop.

Select an option

Save swapnilman/cccfbd6f4efc49b7cbc436583622e8f0 to your computer and use it in GitHub Desktop.
Add user with read only access in Postgresql
# Create a group
CREATE ROLE readonly;
# 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 user with password and assign group
CREATE USER reader WITH PASSWORD 'password';
GRANT readonly TO reader;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment