Estimate number of rows in table

SELECT reltuples::BIGINT AS estimate from pg_class where relname='<TABLE_NAME>';

Show running queries

     , age(clock_timestamp(), query_start)
     , usename
     , query
  FROM pg_stat_activity
  WHERE query != '' AND
        query NOT ILIKE '%pg_stat_activity%'
  ORDER BY query_start desc;

Kill running query

SELECT pg_cancel_backend(<PID>);

Show last vacuum/autovacuum/analyze/autoanalyze

SELECT relname
     , last_vacuum
     , last_autovacuum
     , last_analyze
     , last_autoanalyze
  FROM pg_stat_user_tables;

Repeat previous query every N seconds

\watch N

Describe table


Describe index


All databases with sizes

     , pg_size_pretty(total_bytes) AS total
     , pg_size_pretty(index_bytes) AS INDEX
     , pg_size_pretty(toast_bytes) AS toast
     , pg_size_pretty(table_bytes) AS TABLE
  FROM (
  SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes
    FROM (
      SELECT c.oid
           , nspname AS table_schema
           , relname AS TABLE_NAME
           , c.reltuples AS row_estimate
           , pg_total_relation_size(c.oid) AS total_bytes
           , pg_indexes_size(c.oid) AS index_bytes
           , pg_total_relation_size(reltoastrelid) AS toast_bytes
        FROM pg_class c
          LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
          WHERE relkind = 'r'