Redshift: How to list all users in a group
Asked Answered
U

3

34

Getting the list of users belonging to a group in Redshift seems to be a fairly common task but I don't know how to interpret BLOB in grolist field.

I am literally getting "BLOB" in grolist field from TeamSQL. Not so sure this is specific to TeamSQL but I kind of remember thatI got a list of IDs there instead previously in other tool

Uhhuh answered 19/8, 2018 at 1:45 Comment(0)
S
75

This worked for me:

select usename 
from pg_user , pg_group
where pg_user.usesysid = ANY(pg_group.grolist) and 
      pg_group.groname='<YOUR_GROUP_NAME>';
Spermary answered 21/8, 2018 at 14:17 Comment(2)
As of Dec 16, 2022 the query above does not work.Luckily
I just ran this today as a superuser and it worked perfectly. So maybe the previous commenter was just running it without sufficient permissions?Corking
T
36
SELECT usename, groname 
FROM pg_user, pg_group
WHERE pg_user.usesysid = ANY(pg_group.grolist)
AND pg_group.groname in (SELECT DISTINCT pg_group.groname from pg_group);

This will provide the usernames along with the respective groups.

Trumpeter answered 29/10, 2018 at 9:36 Comment(0)
B
4

this worked better for me:

SELECT 
    pu.usename, 
    pg.groname 
FROM 
    pg_user pu
left join pg_group pg
    on pu.usesysid = ANY(pg.grolist)
order by pu.usename
Bandy answered 28/9, 2022 at 15:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.