- Learn
- PostgreSQL
- PostgreSQL List Users
PostgreSQL List Users
View all users, roles, and permissions in PostgreSQL.
Quick Answer
To list all users in PostgreSQL:
SQL
Or for more detail:
SQL
But keep reading—PostgreSQL's user management has nuances worth understanding.
Users vs Roles
In modern PostgreSQL, users and roles are the same thing. A "user" is just a role with login permission.
SQL
The distinction matters when listing users: some commands show only roles with login permission, while others show all roles.
Methods to List Users
1. Using pg_user (Login Roles Only)
SQL
Returns only roles that can log in:
| usename | usecreatedb | usesuper |
|---|---|---|
| postgres | t | t |
| alice | f | f |
| bob | f | f |
2. Using pg_roles (All Roles)
SQL
Returns all roles, including groups and roles without login:
| rolname | rolcanlogin | rolsuper | rolcreatedb |
|---|---|---|---|
| postgres | t | t | t |
| alice | t | f | f |
| readonly | f | f | f |
| admin_group | f | f | f |
3. Using psql Command (\du)
In the psql terminal:
Output:
For more detail:
4. Using information_schema
SQL
This shows roles that have been granted permissions on tables.
Detailed User Information
See Everything About Users
SQL
Check User's Group Memberships
SQL
Find Users with Superuser Access
SQL
Database-Specific Permissions
Who Can Access a Specific Database?
SQL
List Users with Access to Current Database
SQL
Table-Level Permissions
Who Can Access a Specific Table?
SQL
All Permissions for a User
SQL
Active Connections
See who's currently connected:
SQL
Count connections per user:
SQL
Common Administrative Tasks
Create a New User
SQL
Grant Database Access
SQL
Make a User Read-Only
SQL
Remove a User
SQL
Quick Reference
| Command | Description |
|---|---|
SELECT * FROM pg_user | List login-capable users |
SELECT * FROM pg_roles | List all roles (including groups) |
\du | psql shortcut to list roles |
\du+ | psql shortcut with more detail |
SELECT * FROM pg_stat_activity | Show active connections |
Summary
- In PostgreSQL, users are just roles with
LOGINpermission - Use
pg_userfor login-capable users,pg_rolesfor all roles - The
\ducommand in psql is the quickest way to see users - Check
pg_stat_activityto see who's currently connected - Use
information_schema.role_table_grantsto audit permissions