Skip to content

Instantly share code, notes, and snippets.

@jdunck
Created May 10, 2016 23:09
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 jdunck/3b2e262ba5417c1acca4289f382373c5 to your computer and use it in GitHub Desktop.
Save jdunck/3b2e262ba5417c1acca4289f382373c5 to your computer and use it in GitHub Desktop.
postgres permissions
select usename, nspname || '.' || relname as relation,
case relkind when 'r' then 'TABLE' when 'v' then 'VIEW' end as relation_type,
priv
from pg_class join pg_namespace on pg_namespace.oid = pg_class.relnamespace,
pg_user,
(values('SELECT', 1),('INSERT', 2),('UPDATE', 3),('DELETE', 4)) privs(priv, privorder)
where relkind in ('r', 'v')
and has_table_privilege(pg_user.usesysid, pg_class.oid, priv)
and not (nspname ~ '^pg_' or nspname = 'information_schema')
order by 2, 1, 3, privorder;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment