Skip to content

Instantly share code, notes, and snippets.

@rflpazini
Created January 10, 2018 12:17
Show Gist options
  • Save rflpazini/7392011e77c7f0313a309fed0c2d8961 to your computer and use it in GitHub Desktop.
Save rflpazini/7392011e77c7f0313a309fed0c2d8961 to your computer and use it in GitHub Desktop.
-- Create a group to grant select permission
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
-- Create a new user with password and add this to readaccess group
CREATE USER myuser WITH PASSWORD 'secret';
GRANT readaccess TO myuser;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment