Docs and tutorials

Show

Show database

\l

source

Tables

Show all tables.

\dt

For more info.

\dt+

Get info on a table.

\d+ table_name

Quit

\q

Or CTRL+d.

Users

Login

Here we use a user named postgres.

$ psql -U postgres

The console will now look like this:

postgres=#

This is implied for the rest of this guide.

Create user

CREATE USER postgres
CREATE USER foo WITH PASSWORD 'bar';

https://www.postgresql.org/docs/current/app-createuser.html

Create role

CREATE ROLE foo LOGIN;
CREATE ROLE admin WITH CREATEDB CREATEROLE;

https://www.postgresql.org/docs/current/sql-createrole.html

Change password

ALTER USER postgres WITH PASSWORD 'newpass';

https://www.postgresql.org/docs/current/sql-alteruser.html

Set it interactively.

\password

https://serverfault.com/questions/110154/whats-the-default-superuser-username-password-for-postgres-after-a-new-install/325596

List users

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

More detail:

# \du+

List users PG tutorial.