commands.sh
⌘K

psql

all

PostgreSQL client.

More info →

Options (6)

-h, --hostboolean

Connect to the database on given server host running on given port with given username, without a password prompt

Example: psql {{[-h|--host]}} {{host}} {{[-p|--port]}} {{port}} {{[-U|--username]}} {{username}} {{database}}
-p, --portboolean

Connect to the database on given server host running on given port with given username, without a password prompt

Example: psql {{[-h|--host]}} {{host}} {{[-p|--port]}} {{port}} {{[-U|--username]}} {{username}} {{database}}
-U, --usernameboolean

Connect to the database on given server host running on given port with given username, without a password prompt

Example: psql {{[-h|--host]}} {{host}} {{[-p|--port]}} {{port}} {{[-U|--username]}} {{username}} {{database}}
-W, --passwordboolean

Connect to the database; user will be prompted for password

Example: psql {{[-h|--host]}} {{host}} {{[-p|--port]}} {{port}} {{[-U|--username]}} {{username}} {{[-W|--password]}} {{database}}
-c, --commandboolean

Execute a single SQL query or PostgreSQL command on the given database (useful in shell scripts)

Example: psql {{[-c|--command]}} '{{query}}' {{database}}
-f, --fileboolean

Execute commands from a file on the given database

Example: psql {{database}} {{[-f|--file]}} {{path/to/file.sql}}

Examples (5)

Connect to the database. By default, it connects to the local socket using port 5432 with the currently logged in user

psql database

Connect to the database on given server host running on given port with given username, without a password prompt

psql [-h|--host] host [-p|--port] port [-U|--username] username database

Connect to the database; user will be prompted for password

psql [-h|--host] host [-p|--port] port [-U|--username] username [-W|--password] database

Execute a single SQL query or PostgreSQL command on the given database (useful in shell scripts)

psql [-c|--command] 'query' database

Execute commands from a file on the given database

psql database [-f|--file] path/to/file.sql
made by @shridhargupta | data from tldr-pages