# get all users in postgresql

<div class="WaaZC" id="bkmrk-to-retrieve-a-list-o"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CAsQAQ" data-ved="2ahUKEwjQlcjzvduQAxU7XmwGHbR0MFEQo_EKegQICxAB"><span data-huuid="10795884478261928047">To retrieve a list of all users in PostgreSQL, you can use either the `psql` command-line interface or a SQL query. </span></div></div></div><div class="WaaZC" id="bkmrk-1.-using-the-psql-co"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc pyPiTc" data-hveid="CA4QAQ" data-ved="2ahUKEwjQlcjzvduQAxU7XmwGHbR0MFEQo_EKegQIDhAB"><span data-huuid="10795884478261929461">1. Using the `psql` command-line interface: </span></div></div></div><div class="WaaZC" id="bkmrk-connect-to-postgresq"><div class="RJPOee EIJn2" style="animation: none !important;">- <span data-huuid="10795884478261929534">**Connect to PostgreSQL:** </span><span data-huuid="10795884478261928193">Open your terminal or command prompt and connect to your PostgreSQL server, typically as the `postgres` superuser: </span>

</div></div><div class="WaaZC" id="bkmrk-code"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
    psql -U postgres
```

<div class="WaaZC" id="bkmrk-you-may-be-prompted-"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc uP58nb" data-hveid="CAMQAQ" data-ved="2ahUKEwjQlcjzvduQAxU7XmwGHbR0MFEQo_EKegQIAxAB"><span data-huuid="10795884478261931021"><span aria-level="2" role="heading">You may be prompted for the `postgres` user's password.</span> </span></div></div></div><div class="WaaZC" id="bkmrk-list-users%3A-once-con"><div class="RJPOee EIJn2" style="animation: none !important;">- <span data-huuid="10795884478261931094">**List users:** </span><span data-huuid="10795884478261929753">Once connected, use the `\du` meta-command to display a list of all roles (which includes users) and their attributes: </span>

</div></div><div class="WaaZC" id="bkmrk-code-1"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
    \du
```

<div class="WaaZC" id="bkmrk-for-more-details%3A-us"><div class="RJPOee EIJn2" style="animation: none !important;">- <span data-huuid="17153446535547090059">**For more details:** </span><span data-huuid="17153446535547089078">Use `\du+` to see extended information about the roles, including descriptions and membership details: </span>

</div></div><div class="WaaZC" id="bkmrk-code-2"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
    \du+
```

<div class="WaaZC" id="bkmrk-2.-using-a-sql-query"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc pyPiTc" data-hveid="CCEQAQ" data-ved="2ahUKEwjQlcjzvduQAxU7XmwGHbR0MFEQo_EKegQIIRAB"><span data-huuid="1227468098871535387">2. Using a SQL Query: </span></div></div></div><div class="WaaZC" id="bkmrk-connect-to-postgresq-1"><div class="RJPOee EIJn2" style="animation: none !important;">- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="1227468098871535712">**Connect to PostgreSQL:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="1227468098871534455">Connect to your PostgreSQL server using any client that supports PostgreSQL, such as `psql` or a graphical tool like pgAdmin or DBeaver. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="1227468098871536037">Query the `pg_roles` system catalog: </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="1227468098871534780">PostgreSQL stores information about roles (users) in the `pg_roles` system catalog. </span><span data-huuid="1227468098871537619">You can query this table to retrieve user details: </span></div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-code-3"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
    SELECT rolname, rolsuper, rolcreaterole, rolcreatedb, rolcanlogin
    FROM pg_roles;
```

<div class="WaaZC" id="bkmrk-this-query-will-retu"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CDAQAQ" data-ved="2ahUKEwjQlcjzvduQAxU7XmwGHbR0MFEQo_EKegQIMBAB"><span data-huuid="2033545397344837280">This query will return the role name (`rolname`), whether it's a superuser (`rolsuper`), if it can create roles (`rolcreaterole`), create databases (`rolcreatedb`), and if it can log in (`rolcanlogin`). </span><span data-huuid="2033545397344835661">You can select other columns from `pg_roles` as needed for more specific information</span></div></div></div>