- Learn
- PostgreSQL
- PostgreSQL List Users
PostgreSQL List Users
View all users, roles, and permissions in PostgreSQL.
Quick Answer
To list all users in PostgreSQL:
Or for more detail:
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.
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)
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)
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:
\du
Output:
List of roles
Role name | Attributes
-----------+-----------------------------------------------
alice |
bob | Create DB
postgres | Superuser, Create role, Create DB, Replication
readonly | Cannot login
For more detail:
\du+
4. Using information_schema
This shows roles that have been granted permissions on tables.
Detailed User Information
See Everything About Users
Check User's Group Memberships
Find Users with Superuser Access
Database-Specific Permissions
Who Can Access a Specific Database?
List Users with Access to Current Database
Table-Level Permissions
Who Can Access a Specific Table?
All Permissions for a User
Active Connections
See who's currently connected:
Count connections per user:
Common Administrative Tasks
Create a New User
Grant Database Access
Make a User Read-Only
Remove a User
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