Command (shell) |
Does this |
psql |
Starts psql connected to your own user's database |
psql -d <database> |
Starts psql connected to the given <database> |
cat some.sql | psql -d <database> |
Runs the SQL script in some.sql on <database> |
An arcane way of quitting is the hallmark of a wonderful tool
Command |
Does this |
\q |
Quit |
Your cheatsheet, it is not complete
Command |
Does this |
\? |
Show PSQL commands |
\h |
Show SQL commands |
\h <command> |
Get help for a SQL command |
Why are the first things a dev wants to do so hard to find?
Command |
Does this |
\l |
List all databases |
\connect <database> |
Change to another database (shortcut \c ) |
\dt |
Show all tables in the current database |
\d <table> |
Describe a table's columns |
\di |
Show all indices in the current database |
Set your EDITOR
environmental variable. Then use \e
to edit the last query you entered, or start a new one if you haven't run a query yet. When you save and quit your query will run if it parses. If not, your inadequacies will be pointed out to you by a machine.
Command |
Does this |
\x auto |
Displays query results so as not to overflow the screen when it can (will use a dictionary style for a single row) |
\timing |
Toggle query timings on (off by default) |