PostgreSQL: Top PSQL 5 Commands for 90% of the time

  1. Fixing something over SSH
  2. Quickly managing something in the terminal
  3. Writing the script

1. Navigate to the databases

List all databases
Change database
equivalent to SQL USE <database_name>
\c <database_name>
Bonus: select schema
\dn - list schemas
set search_path to <schema_name>
show search_path

2. Seeing stuff in the databases

\dt -- list tables
\dn -- list schema
\du -- list roles
Describe table
\d <table_name>

3. Seeing stuff in the table

TABLE <table_name>;

4. Good output

For long input, page one-by-one with

\x auto
\x off
\pset format wrapped
\pset pager off
do not use 'less' to view result just print out

5. Clear the screen

\! clear



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store