skip to Main Content

I want to see all.SELECT usename, usesuper, usecreatedb
FROM pg_catalog.pg_user
ORDER BY role_name desc;SELECT usename, usesuper, usecreatedb
FROM pg_catalog.pg_user
ORDER BY role_name desc;

2

Answers


  1. You can run this query to get the list of users and roles in your PostgreSQL database:

    SELECT usename, usesuper, usecreatedb 
    FROM pg_catalog.pg_user
    ORDER BY role_name desc;
    
    Login or Signup to reply.
  2. I advise you this request to see all the users of your database:

    postgres-# du
    

    If you want more information from your users you can use:

    postgres-# du+ 
    

    I advise you this request if you have more difficulties

    SELECT usename AS role_name,
     CASE
      WHEN usesuper AND usecreatedb THEN
        CAST('superuser, create database' AS pg_catalog.text)
    
      WHEN usesuper THEN
        CAST('superuser' AS pg_catalog.text)
    
      WHEN usecreatedb THEN
        CAST('create database' AS pg_catalog.text)
    
      ELSE
        CAST('' AS pg_catalog.text)
     END role_attributes
    FROM pg_catalog.pg_user
    ORDER BY role_name desc;
    

    I advise you to show this doc:
    https://ubiq.co/database-blog/how-to-list-all-users-in-postgresql/#:~:text=Using%20psql%20command,-Log%20into%20PostgreSQL&text=Enter%20password%20to%20log%20into%20PostgreSQL.&text=Enter%20%5Cdu%20command%20to%20list%20all%20users%20in%20PostrgeSQL.&text=You%20will%20see%20the%20list,user%2C%20enter%20%5Cdu%2B%20command.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search