Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL user listing

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 
like image 893
Arun Dambal Avatar asked Jan 19 '12 12:01

Arun Dambal


People also ask

How do I see roles in PostgreSQL?

SELECT rolname FROM pg_roles; The psql program's \du meta-command is also useful for listing the existing roles. In order to bootstrap the database system, a freshly initialized system always contains one predefined role.

Where are users stored in PostgreSQL?

User Data in PostgreSQL All the user-related data is stored in the table named pg_user, which belongs to the schema named pg_catalog.

What are users in postgres?

Users own database objects (for example, tables) and can assign privileges on those objects to other users to control who has access to which object. This chapter describes how to create and manage users and introduces the privilege system.


1 Answers

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).

like image 91
Michael Krelin - hacker Avatar answered Sep 21 '22 01:09

Michael Krelin - hacker