1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-07-05 09:15:25 +02:00
tldr/pages/common/psql.md
Managor 23340cc6e0
common/*: reduce usage of "command-line" (part 1) (#16949)
Co-authored-by: Dylan <145150333+dmmqz@users.noreply.github.com>
Co-authored-by: Lena <126529524+acuteenvy@users.noreply.github.com>
2025-06-29 11:48:18 +03:00

918 B

psql

PostgreSQL client. More information: https://www.postgresql.org/docs/current/app-psql.html.

  • 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]}} {{file.sql}}