Skip to main content

PostgreSQL (psql) Cheat Sheet 2026 — Quick CLI Command Reference

PostgreSQL (psql) Cheat Sheet 2026 — Quick Command Reference

PostgreSQL (psql) Cheat Sheet is the complete quick-reference of PostgreSQL (psql) commands grouped by function. Copy any command with one click and find what you need with Ctrl+F in under 3 seconds.

psql Commands & Meta-commands

Action Command Useful flags
Connect to the database. By default, it connects to the local socket using port
psql <database>
Connect to the database on given server host running on given port with given us
psql --host <host> --port <port> --username <username> <database>
--host --port --username
Connect to the database; user will be prompted for password
psql --host <host> --port <port> --username <username> --password <database>
--host --port --username --password
Execute a single SQL query or PostgreSQL command on the given database (useful i
psql --command '<query>' <database>
--command
Execute commands from a file on the given database
psql <database> --file <path/to/file.sql>
--file

⚠️ Dangerous / Destructive Commands

These commands are irreversible. Verify your environment (dev/staging vs prod) before running them.

Action Command Warning
⚠️ Destroy ⚠️
terraform destroy -auto-approve
Irreversible — verify the target before running
⚠️ Delete
kubectl delete namespace production
Irreversible — verify the target before running
⚠️ Prune ⚠️
docker system prune -af --volumes
Irreversible — verify the target before running
⚠️ Delete
pvesh delete /nodes/{node}/qemu/{vmid}
Irreversible — verify the target before running
⚠️ Delete
az group delete --name MyResourceGroup --yes
Irreversible — verify the target before running

FAQ — Frequently Asked Questions

What is the difference between psql Commands & Meta-commands and the other groups?

Each group in this PostgreSQL (psql) cheat sheet covers a distinct area. psql Commands & Meta-commands focuses on its specific scope, while the other groups and the remaining groups cover networking, storage, security and diagnostics respectively.

How do I check the installed PostgreSQL (psql) version?

Run the version command (usually psql version or psql --version). The output shows the client and, when applicable, the server version.

Why does PostgreSQL (psql) return ‘permission denied’?

A ‘permission denied’ error in PostgreSQL (psql) usually means the current user lacks sufficient privileges or credentials are not configured. Check: (1) assigned IAM/RBAC roles, (2) an active authentication context via the corresponding login command.

How do I filter PostgreSQL (psql) output by status or name?

Use flags such as --filter, --selector or --query depending on the tool. You can also pipe into grep or jq to process JSON:

psql list | grep RUNNING

What is the fastest way to debug a PostgreSQL (psql) error?

Add the verbose flag (--verbose, -v or --debug) to the failing command. This reveals the underlying HTTP/API calls and the full error response body.

Official sources & references

Commands cross-checked against vendor documentation and high-authority repositories: