Introduction
PostgreSQL is an open source object-relational database system. Its
psql client runs SQL and meta-commands from a terminal.
- PostgreSQL documentation (postgresql.org)
Connecting
psql # default database, default user
sudo -u postgres psql # as the postgres role
psql commands
| Command | Description |
|---|---|
\du | List roles |
\l | List databases |
\dt | List tables |
\d <table> | Describe a table |
\d+ <table> | Describe with sizes |
\c <database> | Connect to a database |
\q | Quit |
Creating a database
createdb <database>
Dropping a database
dropdb <database>
Running a query
psql -Atc "SELECT * FROM <table>" # scripting
psql --no-align --tuples-only \
--command="SELECT * FROM <table>" # same
0 Comments for this cheatsheet. Write yours!