Last active
February 21, 2025 10:27
-
-
Save winebarrel/0b048346235c87aed63c to your computer and use it in GitHub Desktop.
show grants for PostgreSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
pg_user.usename, | |
t1.nspname, | |
t1.relname, | |
relacl.privilege_type, | |
relacl.is_grantable | |
from ( | |
select | |
pg_namespace.nspname, | |
pg_class.relname, | |
coalesce(pg_class.relacl, ('{' || pg_user.usename || '=arwdDxt/' || pg_user.usename || '}')::aclitem[]) as relacl | |
from | |
pg_class | |
inner join pg_namespace on pg_class.relnamespace = pg_namespace.oid | |
inner join pg_user on pg_class.relowner = pg_user.usesysid | |
where | |
pg_namespace.nspname !~ '^pg_' | |
and pg_namespace.nspname != 'information_schema' | |
) as t1 | |
cross join aclexplode(t1.relacl) as relacl | |
inner join pg_user on relacl.grantee = pg_user.usesysid | |
order by | |
pg_user.usename, | |
t1.nspname, | |
t1.relname, | |
relacl.privilege_type |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, this actually helped a lot.