Shows every database role—helpful for auditing who can log in and what they can do.
Audit security, verify role creation, and check login permissions. Knowing every role prevents privilege creep and flags unused accounts.
pg_roles, pg_user, and pg_authid (super-users only).pg_roles is the safest read-only source.
Select from pg_roles: SELECT rolname, rolsuper, rolcanlogin FROM pg_roles;
Join pg_roles to pg_auth_members to see which users belong to which group roles.
Add WHERE rolcanlogin
to exclude pure group roles.
Yes.Run \du
or \dg
in psql for a formatted list.
Join pg_roles with information_schema.role_table_grants to find roles granted SELECT on Customers.
SELECT r.rolname FROM pg_roles r;
SELECT DISTINCT grantee FROM information_schema.role_table_grants WHERE table_name = 'customers';
Create group roles (e.g., app_readonly), grant privileges to the group, and add individual users to it.Revoke unused accounts promptly.
Schedule the syntax below in cron or pgAgent, then write results to a log table for compliance.
CONNECT to the database and a role with pg_read_all_stats
membership, or be a superuser.
Tools like Galaxy surface user lists in one click and let you endorse audit queries for team reuse.
.
Yes, roles starting with pg_
are system generated. Filter them out with WHERE rolname NOT LIKE 'pg_%'
.
Only superusers can query pg_authid. Regular users should rely on rolvaliduntil to check password expiry without exposing hashes.
Reassign or drop owned objects, then execute DROP ROLE username;
. Ensure the role is not a member of required group roles.