What select statement can I use to determine 1) the roles that a user belongs to and 2) the tables that a user has access to using PostgreSQL? -
using psql, \dg
, \du
tells me roles each user (role) belongs to. want determine programmatically single user cannot find system tables used generate results returned \dg
.
need special privileges execute query?
as related question, want determine tables role can update.
i've read documentation on create role
, grant
, surrounding documentation tell me how set roles , privileges, not how test role membership or table access privileges.
there built-in system information functions both. see pg_has_role
, etc.
you can query the information_schema
role membership data, in particular information_schema.applicable_roles
, information_schema.enabled_roles
, information_schema.administrable_role_authorizations
.
finally, psql \d
command can find out psql
doing information running psql
-e
option print sql runs. don't recommend using psql
's sql when there's builtin function or information_schema
view same information though. psql
's approach may faster it's more postgresql-version-specific , may not work postgresql versions other 1 you're running. in case of \du
, \dg
psql
querying pg_catalog.pg_roles
part of join against other tables. it's simpler , more portable use information_schema
views instead.
this should the documentation entries on role membership; i'll post patch adds appropriate cross-references.
Comments
Post a Comment