Skip to content

Instantly share code, notes, and snippets.

@surendra0507
Last active November 12, 2021 13:39
Show Gist options
  • Save surendra0507/3011278db996d8d8f13446a47bc7c029 to your computer and use it in GitHub Desktop.
Save surendra0507/3011278db996d8d8f13446a47bc7c029 to your computer and use it in GitHub Desktop.
Create user in postgres with read only access
--
-- Read only
--
-- Create a group
CREATE ROLE cents_rd_group;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO cents_rd_group;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO cents_rd_group;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO cents_rd_group;
-- Grant access to future tables on select
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO cents_rd_group;
-- Create a final user with password
CREATE USER cents_rd WITH PASSWORD 'bhoom';
GRANT cents_rd_group TO cents_rd;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment