Skip to content

Instantly share code, notes, and snippets.

@sebastianwebber
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save sebastianwebber/77f685a60ea3ec79ff30 to your computer and use it in GitHub Desktop.

Select an option

Save sebastianwebber/77f685a60ea3ec79ff30 to your computer and use it in GitHub Desktop.
List USER permissions by table on PostgreSQL
-- Tested on PostgreSQL 9.4
-- More details on http://www.postgresql.org/docs/9.4/static/functions-info.html
-- and http://www.postgresql.org/docs/9.4/static/view-pg-tables.html
-- and http://www.postgresql.org/docs/9.4/static/view-pg-roles.html
SELECT
schemaname,
tablename,
rolname,
has_table_privilege(rolname, tablename, 'SELECT') as can_select,
has_table_privilege(rolname, tablename, 'UPDATE') as can_update,
has_table_privilege(rolname, tablename, 'DELETE') as can_delete,
has_table_privilege(rolname, tablename, 'INSERT') as can_insert
FROM pg_tables, pg_roles
WHERE schemaname NOT IN ('information_schema', 'pg_catalog');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment