PostgreSQL user listing

Arun Dambal picture Arun Dambal · Jan 19, 2012 · Viewed 74.4k times · Source

I want to get a list of users for a certain database in psql - for example "template0". Who are the users? Or for "template1" database: - who are the users there?

Already tried:

\du+  -- no database is Listed not Users
Select * from "pg_users";  -- no database is listed

Answer

Michael Krelin - hacker picture Michael Krelin - hacker · Jan 19, 2012

User aren't actually, "for the database", they're for cluster and are given different permissions to access databases. To list users \du should do, but you need to be connected. Something like

psql template1 -c '\du'

from the command line prompt should do. (or \du from psql prompt when you are connected to the database).