2018-01-17 16:10:16 +00:00
|
|
|
# psql
|
|
|
|
# PostgreSQL command-line client.
|
|
|
|
|
2020-11-22 12:10:48 +00:00
|
|
|
# Connect to database.
|
|
|
|
# It connects to localhost using default port 5432
|
|
|
|
# with default user as currently logged in user
|
2018-01-17 16:10:16 +00:00
|
|
|
psql database
|
|
|
|
|
2020-11-22 12:10:48 +00:00
|
|
|
# Connect to database on given server host running on given port
|
|
|
|
# with given username, without a password prompt
|
2018-01-17 16:10:16 +00:00
|
|
|
psql -h host -p port -U username database
|
|
|
|
|
2020-11-22 12:10:48 +00:00
|
|
|
# Connect to database; user will be prompted for password
|
2018-01-17 16:10:16 +00:00
|
|
|
psql -h host -p port -U username -W database
|
|
|
|
|
2020-11-22 12:10:48 +00:00
|
|
|
# Execute a single SQL query or PostgreSQL command
|
|
|
|
# on the given database (useful in shell scripts)
|
2018-01-17 16:10:16 +00:00
|
|
|
psql -c 'query' database
|
|
|
|
|
2020-11-22 12:10:48 +00:00
|
|
|
# Execute commands from a file on the given database
|
2018-01-17 16:10:16 +00:00
|
|
|
psql database -f file.sql
|
|
|
|
|
|
|
|
# See also:
|
|
|
|
# pg_dump, pg_restore, pg_top
|
|
|
|
# PostgreSQL cheat sheets at /psql/
|
|
|
|
# list of pages: /psql/:list
|
|
|
|
# search in pages: /psql/~keyword
|
|
|
|
|