Post/Code

HomeAboutUsesNow

Postgres Cheat Sheet.

My Postgres cheat sheet:

  • Add this to your .bash_profile to ensure psql in on your path (Mac): export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
  • Installation directory: /Library/PostgreSQL/10
  • Default port: 5432
  • Login from terminal: psql -U userNameHere
  • Run on a particular port (other than default): psql -p 5433
  • Show version: psql --version
  • Determine where Postgres is installed: which postgres
  • Create a database: createdb tableName
  • Drop a database: dropdb tableName

psql

  • Show version: SELECT version();
  • List all databases: \l
  • Help sql: \h
  • Help psql: \?
  • Quit: \q
  • Select a database: \c databaseName
  • List tables: \dt
  • See a specific table schema: \d tableName
  • List schema: \dn
  • List users: \du
  • Command history: \s
  • Execute previous command: \q
  • Change password for user: \password
  • You can find the Postgres version of my Itemly Todo API here.
  • The MySQL version is here.
  • The Mongo version is here.