Skip to content

Instantly share code, notes, and snippets.

@AdrianTP
Forked from Kartones/postgres-cheatsheet.md
Created December 12, 2016 22:42
Show Gist options
  • Save AdrianTP/3ef8eab3f89926e22f3231660eaeacdf to your computer and use it in GitHub Desktop.
Save AdrianTP/3ef8eab3f89926e22f3231660eaeacdf to your computer and use it in GitHub Desktop.
PostgreSQL command line cheatsheet

Magic words:

psql -U postgres

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*

  • \q: Quit/Exit
  • \c __database__: Connect to a database
  • \dt: List tables
  • \l: List databases
  • \dn: List schemas
  • \df: List functions
  • \dv: List views
  • SELECT * FROM pg_proc WHERE proname='__procedurename__': List procedure/function
  • SELECT * FROM pg_views WHERE viewname='__viewname__';: List view (including the definition)
  • SELECT pg_size_pretty(pg_total_relation_size('__table_name__'));: Show DB table space in use.
  • SELECT pg_size_pretty(pg_database_size('__database_name__'));: Show DB space in use.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment