Connect and inspect PostgreSQL

Databases

Connect to PostgreSQL, list databases/tables, and inspect indexes.

  1. 1

    Connect

    psql postgresql://<user>:<pass>@<host>:5432/<db>
  2. 2

    List databases

    \l
  3. 3

    List tables

    \dt
  4. 4

    Describe table

    \d+ <table>
  5. 5

    Find active queries

    SELECT pid, state, query FROM pg_stat_activity WHERE state <> 'idle';

Common mistakes

  • Running kill/terminate query commands without confirming ownership.

Related commands: psql, \dt, pg_stat_activity