Sobes.tech
Junior — Middle

How to get a list of all users in a PostgreSQL database using the command line?

sobes.tech AI

Answer from AI

To get a list of all users in a PostgreSQL database via the command line, you can use the psql utility and execute an SQL query on the system tables pg_roles or pg_user.

Example command:

psql -U postgres -c "SELECT rolname FROM pg_roles;"

Here, -U postgres specifies the user for connection, and -c allows executing an SQL query and displaying the result. You will receive a list of all roles (users) in the database.