Skip to content

Instantly share code, notes, and snippets.

@msdousti
Last active July 25, 2025 22:37
Show Gist options
  • Save msdousti/216171bb61234913e441df8dad448fb3 to your computer and use it in GitHub Desktop.
Save msdousti/216171bb61234913e441df8dad448fb3 to your computer and use it in GitHub Desktop.
SELECT
c.relname,
a.grantor::regrole,
a.grantee::regrole,
c.relowner::regrole,
array_agg(a.privilege_type ORDER BY a.privilege_type) AS privileges
FROM
pg_class c
JOIN pg_namespace n ON c.relnamespace = n.oid
LEFT JOIN aclexplode(c.relacl) AS a ON TRUE
WHERE
n.nspname = 'public'
AND c.relkind IN ('r', 'p')
GROUP BY
1, 2, 3, 4
ORDER BY
1, 2, 3, 4;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment