Postgres Cheat Sheet

PostgreSQL console

psql

Enter the postgres command line

psql -U postgres

-U ⇒ user

Login as postgres user

PostgreSQL command line

Databases:

\l

List databases

\c my_db

set current database to my_db

Tables:

\dt

list database tables

\dt+

list database tables with Description column

DROP TABLE mytable

drop mytable

DROP TABLE mytable CASCADE

Automatically drop objects that depend on the table

CREATE TABLE mytable

Create Table

\d

describe tables

\d+

describe tables

  • Delete single row from table: DELETE FROM table_name WHERE condition;

Users:

\du

display users