psql: Add role's membership options to the \du+ command

From: Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>
To: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: psql: Add role's membership options to the \du+ command
Date: 2023-01-09 16:09:19
Message-ID: b9be2d0e-a9bc-0a30-492f-a4f68e4f7740@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

When you include one role in another, you can specify three options:
ADMIN, INHERIT (added in e3ce2de0) and SET (3d14e171).

For example.

CREATE ROLE alice LOGIN;

GRANT pg_read_all_settings TO alice WITH ADMIN TRUE, INHERIT TRUE, SET TRUE;
GRANT pg_stat_scan_tables TO alice WITH ADMIN FALSE, INHERIT FALSE, SET
FALSE;
GRANT pg_read_all_stats TO alice WITH ADMIN FALSE, INHERIT TRUE, SET FALSE;

For information about the options, you need to look in the pg_auth_members:

SELECT roleid::regrole, admin_option, inherit_option, set_option
FROM pg_auth_members
WHERE member = 'alice'::regrole;
        roleid        | admin_option | inherit_option | set_option
----------------------+--------------+----------------+------------
 pg_read_all_settings | t            | t              | t
 pg_stat_scan_tables  | f            | f              | f
 pg_read_all_stats    | f            | t              | f
(3 rows)

I think it would be useful to be able to get this information with a
psql command
like \du (and \dg). With proposed patch the \du command still only lists
the roles of which alice is a member:

\du alice
                                     List of roles
 Role name | Attributes |                          Member of
-----------+------------+--------------------------------------------------------------
 alice     |            |
{pg_read_all_settings,pg_read_all_stats,pg_stat_scan_tables}

But the \du+ command adds information about the selected ADMIN, INHERIT
and SET options:

\du+ alice
                                    List of roles
 Role name | Attributes |                   Member of                  
| Description
-----------+------------+-----------------------------------------------+-------------
 alice     |            | pg_read_all_settings WITH ADMIN, INHERIT, SET+|
           |            | pg_read_all_stats WITH INHERIT               +|
           |            | pg_stat_scan_tables                           |

One more change. The roles in the "Member of" column are sorted for both
\du+ and \du for consistent output.

Any comments are welcome.

--
Pavel Luzanov
Postgres Professional: https://postgrespro.com

Attachment Content-Type Size
add_role_membership_options_to_du.patch text/x-patch 5.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dean Rasheed 2023-01-09 16:12:37 Re: [PATCH] random_normal function
Previous Message Karl O. Pinc 2023-01-09 15:53:38 Re: doc: add missing "id" attributes to extension packaging page