Databases

psql basics: list tables, describe, switch database and quit

The handful of psql commands everyone needs: show databases and tables, look at a table, move around and get out.

Fill these in once
  1. Open psql
    Terminal
    psql postgres

    The rest of the commands are typed at the psql prompt.

  2. List databases
    Inside psql
    \l
  3. Switch to a database
    Inside psql
    \c myapp_dev
  4. List tables
    Inside psql
    \dt
  5. Describe a table
    Inside psql
    \d users
  6. Quit
    Inside psql
    \q
  1. Open psql
    Terminal · Ubuntu / Debian
    sudo -u postgres psql

    The rest of the commands are typed at the psql prompt.

  2. List databases
    Inside psql
    \l
  3. Switch to a database
    Inside psql
    \c myapp_dev
  4. List tables
    Inside psql
    \dt
  5. Describe a table
    Inside psql
    \d users
  6. Quit
    Inside psql
    \q
  1. Open psql
    PowerShell
    psql -U postgres

    The rest of the commands are typed at the psql prompt.

  2. List databases
    Inside psql
    \l
  3. Switch to a database
    Inside psql
    \c myapp_dev
  4. List tables
    Inside psql
    \dt
  5. Describe a table
    Inside psql
    \d users
  6. Quit
    Inside psql
    \q