EXPLAIN with buffers

Run query and show real timings plus buffer hits/reads to spot disk I/O

EXPLAIN (ANALYZE, BUFFERS, VERBOSE) SELECT ... ; -- shared hit/read shows cache vs disk I/O

tool
postgres29 commands
tags
postgresperformancedebugdisk

More postgres commands

  • SELECT pid, pg_blocking_pids(pid) AS blocked_by, wait_event_type, query FROM pg_stat_activity WHERE cardinality(pg_blocking_pids(pid)) > 0;

    Show backends waiting on locks and which pids block them

  • SELECT client_addr, state, pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn) AS replay_lag_bytes, write_lag, flush_lag, replay_lag FROM pg_stat_replication;

    Measure replica lag in bytes plus write/flush/replay lag intervals

  • SELECT datname, pg_size_pretty(pg_database_size(datname)) AS size FROM pg_database ORDER BY pg_database_size(datname) DESC;

    Human-readable size of every database, largest first

  • SELECT relname, pg_size_pretty(pg_total_relation_size(oid)) AS total, pg_size_pretty(pg_relation_size(oid)) AS table FROM pg_class WHERE relkind='r' ORDER BY pg_total_relation_size(oid) DESC LIMIT 20;

    Top tables by total size including indexes and TOAST

  • SELECT relname, indexrelname, idx_scan, pg_size_pretty(pg_relation_size(indexrelid)) AS size FROM pg_stat_user_indexes WHERE idx_scan=0 ORDER BY pg_relation_size(indexrelid) DESC;

    Indexes never scanned (idx_scan=0); candidates to drop and reclaim space

all 29 postgres commands