Skip to content

Instantly share code, notes, and snippets.

@nomatteus
Created July 22, 2013 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nomatteus/6054239 to your computer and use it in GitHub Desktop.
Save nomatteus/6054239 to your computer and use it in GitHub Desktop.
Learning how to use psql instead of pgAdmin (mostly), and these are the command I want to remember.

Useful psql commands:

How to start/quit the program

  • $ psql database_name: Start psql with database name.
  • \q: Quit psql

General

  • \l: List all databases
  • \dt: List tables/relations
  • \d <table_name>: List info about a table

Display

  • \x: Turn on extended display (useful for select * from <large_table> type queries or for fields with long fields.)
  • \pset pager: Toggle pager (it gets annoying sometimes)
  • \timing: Turn on/off query time display

Help

  • \h: Help on SQL Syntax
  • \?: List psql slash commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment