psql - PostgreSQL interactive terminal (simulator: the lab's minimal client for pg.lab)
psql [OPTION]... [DBNAME [USERNAME]] | psql postgresql://USER:PASSWORD@HOST:5432/DB
Options you will use
-p, --port=PORT- database server port (default 5432).
-U, --username=USER- database user name.
-d, --dbname=DBNAME- database name to connect to.
-c, --command=COMMAND- run only a single command (SQL or internal) and exit.
-W, --password- force password prompt.
-A- unaligned table output mode.
-t- print rows only.
-At- unaligned rows only: what scripts use.
-V, --version- output version information, then exit.
Examples
$ PGPASSWORD=$PW psql -h pg.lab -U $USER -d orders -c 'SELECT current_user;'log in with Vault's dynamic credentials
$ psql -h pg.lab -U vault -d orders -c '\du'list roles (Vault's v-... users)
Gotchas
- The password comes from PGPASSWORD, the URL, ~/.pgpass, or a prompt.
- A role past its VALID UNTIL fails exactly like a wrong password: "password authentication failed".
Try psql in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.