2014-05-08 18:10:08 +04:00
|
|
|
# psql
|
|
|
|
|
2016-01-07 20:31:27 +03:00
|
|
|
> PostgreSQL command-line client.
|
2019-05-29 16:53:55 +03:00
|
|
|
> More information: <https://www.postgresql.org/docs/current/app-psql.html>.
|
2014-05-08 18:10:08 +04:00
|
|
|
|
2022-07-22 03:56:44 +03:00
|
|
|
- Connect to the database. By default, it connects to the local socket using port 5432 with the currently logged in user:
|
2014-05-08 18:10:08 +04:00
|
|
|
|
|
|
|
`psql {{database}}`
|
|
|
|
|
2021-08-15 20:59:09 +03:00
|
|
|
- Connect to the database on given server host running on given port with given username, without a password prompt:
|
2014-05-08 18:10:08 +04:00
|
|
|
|
2014-05-12 15:44:31 +04:00
|
|
|
`psql -h {{host}} -p {{port}} -U {{username}} {{database}}`
|
2014-05-08 18:10:08 +04:00
|
|
|
|
2021-08-15 20:59:09 +03:00
|
|
|
- Connect to the database; user will be prompted for password:
|
2015-12-30 16:07:35 +03:00
|
|
|
|
|
|
|
`psql -h {{host}} -p {{port}} -U {{username}} -W {{database}}`
|
|
|
|
|
2016-08-08 10:48:21 +03:00
|
|
|
- Execute a single SQL query or PostgreSQL command on the given database (useful in shell scripts):
|
2014-05-08 18:10:08 +04:00
|
|
|
|
2014-05-12 15:44:31 +04:00
|
|
|
`psql -c '{{query}}' {{database}}`
|
2014-05-08 18:10:08 +04:00
|
|
|
|
2016-08-08 10:11:27 +03:00
|
|
|
- Execute commands from a file on the given database:
|
2014-05-08 18:10:08 +04:00
|
|
|
|
2016-08-08 10:11:27 +03:00
|
|
|
`psql {{database}} -f {{file.sql}}`
|