Users

Set/reset Postgres user password

\password username

// To set/reset a password for PostgreSQL database user (psql)

For example: Change password for current user “postgres”:

\password postgres
Enter new password: xxxx
Enter it again: xxxx


Show all users

select * from pg_user;

// Display PostgreSQL database users (SQL)

\du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 testrole  |                                                            | {} 
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

// Display PostgreSQL database roles (psql)


Login & enter Postgres terminal

$ psql -U testuser mytest
Password for user testuser: ......
psql (9.6.12)
Type "help" for help.

// Login to PostgreSQL: psql -U user database (psql)