Skip to content

Instantly share code, notes, and snippets.

@arthuralvim
Created January 22, 2018 20:05
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 arthuralvim/05602501509991702ca7ce87a47a5e2d to your computer and use it in GitHub Desktop.
Save arthuralvim/05602501509991702ca7ce87a47a5e2d to your computer and use it in GitHub Desktop.
Working with permissions on PostgreSQL.
CREATE ROLE [user_read_only] WITH LOGIN PASSWORD 'mysuperstrongpassword' NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION VALID UNTIL 'infinity';
GRANT CONNECT ON DATABASE [database_name] TO [user_read_only];
GRANT USAGE ON SCHEMA public TO [user_read_only];
GRANT SELECT ON [table_name] TO [user_read_only];
REVOKE ALL ON DATABASE [database_name] FROM [user_read_only];
REVOKE ALL ON SCHEMA public FROM [user_read_only];
REVOKE ALL ON [table_name] FROM [user_read_only];
DROP USER [user_read_only];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment