Thread: psql \du and \dg commands.

psql \du and \dg commands.

From
David BOURIAUD
Date:
Hello,
I don't really know since when those commands are provided by psql, but I
found them recently and was quite annoyed by the output given by both of
them.
Though I find that the \du command's output is quite accurate, I wonder why
\dg gives the same informations ?
I would have expected to see the group names in a left column, and the list of
users that belongs to this group.
I know I can get the information by fetching rows of pg_group system table,
but I was just wondering about this issue and see what you here would think
of it.
Thanks for any suggestions about this behavior.

Re: psql \du and \dg commands.

From
Shane Ambler
Date:
David BOURIAUD wrote:
> Hello,
> I don't really know since when those commands are provided by psql, but I 
> found them recently and was quite annoyed by the output given by both of 
> them.

Not certain since when but I would think from a very early version.

> Though I find that the \du command's output is quite accurate, I wonder why 
> \dg gives the same informations ?
> I would have expected to see the group names in a left column, and the list of 
> users that belongs to this group.
> I know I can get the information by fetching rows of pg_group system table, 
> but I was just wondering about this issue and see what you here would think 
> of it. 
> Thanks for any suggestions about this behavior.

Historically old versions had a clear definition between groups and 
users. 8.1 introduced the role as we use today replacing the users and 
groups.

The views in pg_catalog that are used to replace the old users and 
groups defines a group as a role that cannot login. This is an 
approximation only as any role can have members assigned to them as if 
it was a group, inheriting privileges of that role.
And nologin may be assigned to any role for more reasons than to define 
it as a group.

The \dg and \du commands in psql need to remain as the new version can 
still connect to old servers that don't support the new roles. But with 
an 8.1 or newer server it can't reliably distinguish between a user and 
a group role so returns the same info.


I guess there is always a chance of someone making a patch that would 
hide the two options (maybe replace them with \dr?) when connected to an 
8.1 or higher server. But I wouldn't expect it any time soon.



-- 

Shane Ambler
pgSQL (at) Sheeky (dot) Biz

Get Sheeky @ http://Sheeky.Biz