Skip to content

Instantly share code, notes, and snippets.

@shadyrudy
Created February 1, 2024 17:23
Show Gist options
  • Save shadyrudy/26e6223ff9970e4c95b58504bd307b58 to your computer and use it in GitHub Desktop.
Save shadyrudy/26e6223ff9970e4c95b58504bd307b58 to your computer and use it in GitHub Desktop.
PostgreSQL \du+ in query form
-- The following script emulates the PostgreSQL commmand
-- \du+ using SQL instead of the command
SELECT r.rolname
,r.rolsuper
,r.rolinherit
,r.rolcreaterole
,r.rolcreatedb
,r.rolcanlogin
,r.rolreplication
,r.rolconnlimit
,r.rolvaliduntil
, ARRAY(SELECT b.rolname
FROM pg_catalog.pg_auth_members m
JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid) WHERE m.member = r.oid) AS memberof
,r.rolconfig
FROM pg_catalog.pg_roles r
ORDER BY 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment