Skip to content

Instantly share code, notes, and snippets.

@RHeynsZa
Created August 9, 2023 09:43
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 RHeynsZa/d3fafd829f274f6d65b50ed7d2e9ebb0 to your computer and use it in GitHub Desktop.
Save RHeynsZa/d3fafd829f274f6d65b50ed7d2e9ebb0 to your computer and use it in GitHub Desktop.
How to create a read only user in AWS RDS PostgreSQL
-- https://stackoverflow.com/questions/56940582/how-do-i-create-a-readonly-user-in-postgres-in-aws-rds
REVOKE CREATE ON SCHEMA public FROM public;
-- Create a group
CREATE ROLE postgres_ro_group;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO postgres_ro_group;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO postgres_ro_group;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO postgres_ro_group;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO postgres_ro_group;
-- Create a final user with password
CREATE USER postgres_ro WITH PASSWORD 'secret';
GRANT postgres_ro_group TO postgres_ro;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment