How to get list of users in PostgreSQL

In this article, we will see How to get list of users in PostgreSQL. We can get the list of users by running meta command \du and by querying against table pg_user.

1. List of users in PostgreSQL using meta command:

\du

List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- elchuru | | {} george | | {} james | | {} karunakar | | {} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

How to get list of users in PostgreSQL

2. List of users in PostgreSQL using SQL Statement:

select usename from pg_user;

postgres=# select usename from pg_user; usename ----------- postgres george karunakar james elchuru (5 rows)