Show Menu
Cheatography

Postgres (EI20) Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

GETTING STARTED WITH POSTGRES FROM CLI

START SERVER
pg_ctl start -l "­$PG­DAT­A/s­erv­er.l­og­"
CREATE DATABASE
createdb -U dev <DA­TAB­ASE>
IMPORT
psql <DA­TAB­ASE> < <PA­TH-­TO-­FIL­ENA­ME>
IMPORT (alter­native)
psql -U dev -d <DA­TAB­ASE> -f <PA­TH-­TO-­FIL­ENA­ME>
SERVER STATUS
pg_ctl status
DROP DATABASE
dropdb <DA­TAB­ASE>

PSQL SHELL LOGIN

Login
psql -h <HO­STN­AME> -U <US­ERN­AME> <DA­TAB­ASE>

PSQL SHELL META-C­OMMANDS

List Databases
: \l
this prompt
<DA­TAB­ASE­>=#
means super-user
Tables in Databases
: \d
this prompt
<DA­TAB­ASE­>=>
means normal user
Public Tables
: \dt
this prompt
<DA­TAB­ASE­>-#
means contin­uation
Public Tables with Size and Descri­ption
: \dt+
To Exit/Quit
: \q
Connect to Other
: \c