PostgreSQL: list all database user accounts in postgres

Trabla: PostgreSQL: list all database user accounts in postgres

Solving:

1. Run psql in database server:

 sudo -u postgres psql

2. SQL Query:

SELECT u.usename AS "User name",u.usesysid AS "User ID",CASE WHEN u.usesuper AND u.usecreatedb THEN CAST('superuser, createdatabase' AS pg_catalog.text)WHEN u.usesuper THEN CAST('superuser' AS pg_catalog.text)WHEN u.usecreatedb THEN CAST('create database' ASpg_catalog.text)ELSE CAST('' AS pg_catalog.text)END AS "Attributes"FROM pg_catalog.pg_user uORDER BY 1;


Source: http://www.postgresql.org/message-id/1121195544.8208.242.camel@state.g2switchworks.com

Example output:

 User name | User ID |    Attributes
-----------+---------+-------------------
 user123    |   16384 |
 postgres  |      12 | superuser, create+
           |         | database
(2 rows)

No comments:

Post a Comment