POSTGRESQL-ESSENTIALS practice question 2 of 15

Which psql meta-command is used to display all roles and their attributes?

Full set: 71 questions
Answer options
A: \du Correct answer
B: \dr
C: \roles
D: \users
Correct Answer:
A. \du
Explanation

The \du meta-command in psql is used to list all available roles. Since PostgreSQL version 8.1, the concepts of "users" and "groups" have been unified into a single entity type called a "role". Therefore, \du displays all roles, which encompasses what were formerly known as users and groups. The output includes the role name and a list of its attributes, such as Superuser, Create role, Create DB, Connections, and membership in other roles. The \du command is an alias for \dg, providing identical functionality.

Why Incorrect

\dr: This is not a valid psql meta-command for listing roles. The \drds command exists to show default access privileges, but \dr is not a defined command. \roles: This is not a valid psql meta-command. Meta-commands must begin with a backslash (\). ROLES is a SQL identifier, not a client command. \users: This is not a valid psql meta-command. Like \roles, it lacks the required backslash prefix and is not a defined psql command.

References

1. PostgreSQL 16 Documentation, psql Meta-Commands: The official documentation lists \du and its alias \dg as the commands to "list roles". The table explicitly describes its function.

Source: PostgreSQL 16 Documentation, Section: psql, Subsection: "Meta-Commands". The table under the "Informational" category lists \du[S+] [pattern] with the description "list roles".

2. PostgreSQL 16 Documentation, Database Roles: This section clarifies the unification of users and groups into roles, which is fundamental to understanding why \du lists all of them.

Source: PostgreSQL 16 Documentation, Chapter 22: "Database Roles", Section 22.1: "Database Roles". The first paragraph states, "PostgreSQL manages database access permissions using the concept of roles. A role can be thought of as either a database user, or a group of database users... Since version 8.1, users and groups are unified into a single kind of entity called a role."

Scroll to Top