Skip to main content

Postgres | psql cli

An optional way to connect into postgres is using the psql client. It's possible to create a interactive session or execute one-off commands.

Connection Configuration

NameTypeDescription
HOSTenv-varThe IP or Host of the Postgres server
PORTenv-varThe port of the Postgres server
USERenv-varThe user to connect in the Postgres server
PGPASSWORDenv-varThe password to connect in the Postgres server
DBenv-varThe name of the database to connect into

Connnection Command

psql -P pager=off -h $HOST -U$USER --port$PORT $DB
NOTE

The PGPASSWORD is mapped as an environment variable, thus there's no need to use it in the command.

How to Use

Start an interactive session with psql client

hoop connect psql

In the same connection, one-off process can be run as well

hoop exec psql <<EOF
SLEEP 5;
SELECT NOW();
EOF
hoop exec psql -f /tmp/myquery.sql
hoop exec psql -i 'SELECT NOW()'