The Quick Answer
On a fresh install only the postgres system user can log in to the database as a superuser. Open psql as that user and list the roles:
sudo -u postgres psql
\du
To run it without opening an interactive session:
sudo -u postgres psql -c '\du'
The output has one row per role, with its name and attributes such as Superuser, Create role, Create DB, Replication, and Bypass RLS. A role with none of them shows an empty attribute column.
More Detail with \du+
\du+ adds a Description column with any comment set on the role. A pattern limits the list:
\du app*
\du+ app_user
Built-in roles whose names start with pg_ are hidden by default. \duS includes them.
Roles and Users
PostgreSQL has only roles. A user is a role with the LOGIN attribute, and a group is a role without it that other roles are members of. CREATE USER is the same as CREATE ROLE with LOGIN added. In \du, a role that cannot log in shows "Cannot login" among its attributes. To create roles, see PostgreSQL create user.
List Users with SQL
The pg_roles view works for any connected user:
SELECT rolname, rolsuper, rolcreatedb, rolcanlogin
FROM pg_roles
ORDER BY rolname;
Only roles that can log in, without the built-in ones:
SELECT rolname
FROM pg_roles
WHERE rolcanlogin AND rolname NOT LIKE 'pg\_%'
ORDER BY rolname;
The older pg_user view shows only login roles, with the column usename:
SELECT usename, usesuper FROM pg_user;
Password hashes are stored in pg_authid, which only superusers can read. The views show a masked value instead.
Show Role Membership
From PostgreSQL 16, psql shows role grants with a separate command, \drg, which also lists the grant options and the grantor, and \du no longer has a "Member of" column. Older releases show memberships in \du. A query that works on every current release:
SELECT r.rolname AS role, m.rolname AS member
FROM pg_auth_members am
JOIN pg_roles r ON r.oid = am.roleid
JOIN pg_roles m ON m.oid = am.member
ORDER BY 1, 2;
Who Can Access a Database or Table
| Command | Shows |
|---|---|
\l | Databases, owners, and access privileges |
\dp | Table privileges in the current database |
\dn+ | Schemas and their privileges |
\ddp | Default privileges for new objects |
Privileges appear as short codes such as app_user=CTc/postgres: the role, the granted rights, and who granted them. Connect to the right database with \c dbname before \dp, since it shows only the current one. More commands are in psql commands, and listing databases is covered in PostgreSQL list databases.
Common Problems
- Peer authentication failed for user: on a local socket, PostgreSQL matches the database role to the Linux user. Run psql as
postgreswith sudo, or connect with-h localhostand a password wherepg_hba.confallows password authentication for local TCP connections. - A role is listed but cannot connect: check that it has LOGIN, that it has CONNECT on the database, and that
pg_hba.confallows its host and method. See PostgreSQL remote access. - Coming from MySQL: PostgreSQL roles have no host part. Which addresses may connect is set in
pg_hba.conf, not in the role. For the MySQL side, see MySQL list users.