Skip to content

Instantly share code, notes, and snippets.

@reterVision
Last active December 10, 2015 04:08
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 reterVision/4379026 to your computer and use it in GitHub Desktop.
Save reterVision/4379026 to your computer and use it in GitHub Desktop.
How to create a role and grant a view to him with the read only privilege in postgres.
CREATE ROLE <newuser> WITH LOGIN ENCRYPTED PASSWORD <password>;
CREATE VIEW <viewname> AS SELECT * FROM <yourtable> LIMIT 20;
GRANT CONNECT ON DATABASE "<databasename>" TO <newuser>;
GRANT SELECT ON schemaname.viewname TO <newuser>;
REVOKE ALL PRIVILEGES ON <schemaname> FROM <newuser>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment