🖥️psql
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the psql command with important options and switches using examples.
3 minute read
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ██████╗ ███████╗ ██████╗ ██╗
# ██╔══██╗██╔════╝██╔═══██╗██║
# ██████╔╝███████╗██║ ██║██║
# ██╔═══╝ ╚════██║██║▄▄ ██║██║
# ██║ ███████║╚██████╔╝███████╗
# ╚═╝ ╚══════╝ ╚══▀▀═╝ ╚══════╝
# PostgreSQL command-line client.
# Connect to database. It connects to localhost using default port 5432 with default user as currently logged in user:
psql database
# Connect to database on given server host running on given port with given username, without a password prompt:
psql -h host -p port -U username database
# Connect to database; user will be prompted for password:
psql -h host -p port -U username -W database
# Execute a single SQL query or PostgreSQL command on the given database (useful in shell scripts):
psql -c 'query' database
# Execute commands from a file on the given database:
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
# psql is the PostgreSQL terminal interface. The following commands were tested on version 9.5.
# Connection options:
# -U username (if not specified current OS user is used).
# -p port.
# -h server hostname/address.
# Connect to a specific database:
psql -U postgres -h serverAddress -d dbName
# Get databases on a server:
psql -U postgres -h serverAddress --list
# Execute sql query and save output to file:
psql -U postgres -d dbName -c 'select * from tableName;' -o fileName
# Execute query and get tabular html output:
psql -U postgres -d dbName -H -c 'select * from tableName;'
# Execute query and save resulting rows to csv file:
psql -U postgres -d dbName -t -A -P fieldsep=',' -c 'select * from tableName;' -o fileName.csv
# Read commands from file:
psql -f fileName
# Restore databases from file:
psql -f fileName.backup postgres
#==============================##==============================#
# CMD PSQL #
#==============================##==============================#
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command psql in a clear format. This allows users to quickly access the needed information for psql without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for psql are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.