Options (6)
-h, --hostbooleanConnect 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}}-p, --portbooleanConnect 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}}-U, --usernamebooleanConnect 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}}-W, --passwordbooleanConnect to the database; user will be prompted for password
psql {{[-h|--host]}} {{host}} {{[-p|--port]}} {{port}} {{[-U|--username]}} {{username}} {{[-W|--password]}} {{database}}-c, --commandbooleanExecute a single SQL query or PostgreSQL command on the given database (useful in shell scripts)
psql {{[-c|--command]}} '{{query}}' {{database}}-f, --filebooleanExecute commands from a file on the given database
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 databaseConnect 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 databaseConnect to the database; user will be prompted for password
psql [-h|--host] host [-p|--port] port [-U|--username] username [-W|--password] databaseExecute a single SQL query or PostgreSQL command on the given database (useful in shell scripts)
psql [-c|--command] 'query' databaseExecute commands from a file on the given database
psql database [-f|--file] path/to/file.sql