1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-29 23:24:55 +02:00
tldr/pages/common/psql.md

24 lines
716 B
Markdown
Raw Normal View History

2014-05-08 17:10:08 +03:00
# psql
> PostgreSQL command-line client.
2014-05-08 17:10:08 +03:00
- Connect to database. It connects to localhost using default port 5432 with default user as currently logged in user:
2014-05-08 17:10:08 +03:00
`psql {{database}}`
- Connect to database on given server host running on given port with given username, without a password prompt:
2014-05-08 17:10:08 +03:00
2014-05-12 14:44:31 +03:00
`psql -h {{host}} -p {{port}} -U {{username}} {{database}}`
2014-05-08 17:10:08 +03:00
- Connect to database; user will be prompted for password:
2015-12-30 14:07:35 +01:00
`psql -h {{host}} -p {{port}} -U {{username}} -W {{database}}`
- Execute a single SQL query or PostgreSQL command on the given database. Note: useful in shell scripts:
2014-05-08 17:10:08 +03:00
2014-05-12 14:44:31 +03:00
`psql -c '{{query}}' {{database}}`
2014-05-08 17:10:08 +03:00
- Execute commands from a file on the given database:
2014-05-08 17:10:08 +03:00
`psql {{database}} -f {{file.sql}}`