2014-05-08 15:10:08 +01:00
|
|
|
# psql
|
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
> PostgreSQL command-line client.
|
2014-05-08 15:10:08 +01:00
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Connect to *database*. It connects to localhost using default port *5432* with default user:
|
2014-05-08 15:10:08 +01:00
|
|
|
|
|
|
|
`psql {{database}}`
|
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Connect to *database* on given server *host* running on given *port* with *username* given, no password prompt:
|
2014-05-08 15:10:08 +01:00
|
|
|
|
2014-05-12 12:44:31 +01:00
|
|
|
`psql -h {{host}} -p {{port}} -U {{username}} {{database}}`
|
2014-05-08 15:10:08 +01:00
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Connect to *database*, user will be prompted for password:
|
2015-12-30 13:07:35 +00:00
|
|
|
|
|
|
|
`psql -h {{host}} -p {{port}} -U {{username}} -W {{database}}`
|
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Run single *query* against the given *database*. Note: useful in shell scripts:
|
2014-05-08 15:10:08 +01:00
|
|
|
|
2014-05-12 12:44:31 +01:00
|
|
|
`psql -c '{{query}}' {{database}}`
|
2014-05-08 15:10:08 +01:00
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Run several queries against the given *database*. Note: useful in shell scripts:
|
2014-05-08 15:10:08 +01:00
|
|
|
|
2015-10-28 08:33:06 +00:00
|
|
|
`echo '{{query1}}; {{query2}}' | psql {{database}}`
|