Skip to content

Instantly share code, notes, and snippets.

@niteshy
Created December 26, 2017 08:47
Show Gist options
  • Save niteshy/2655b547e7f778fbb3854365276c632a to your computer and use it in GitHub Desktop.
Save niteshy/2655b547e7f778fbb3854365276c632a to your computer and use it in GitHub Desktop.
--
-- To create the group
--
-- Create a ro_group (readonly group)
CREATE ROLE ro_group;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO ro_group;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO ro_group;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO ro_group;
-- Create a ro_user (readonly user) with password ('secret')
CREATE USER ro_user WITH PASSWORD 'secret';
GRANT ro_group TO ro_user;
--
-- To remove the group
--
-- REVOKE ro_group
REVOKE USAGE ON SCHEMA public FROM ro_group;
-- REVOKE ro_group
REVOKE ALL ON public FROM ro_group;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment