-- 05_monitor.sql -- Run this in a SEPARATE psql session while the migration is executing. -- Poll every few seconds to watch MVCC bloat build up in real time. -- -- Usage (run continuously): -- watch -n 3 'PGPASSWORD=... psql -h 127.0.0.1 -p 15432 -U postgres knoe-db -f demo/ci-migration/05_monitor.sql' -- -- Or in interactive psql with \watch: -- \i demo/ci-migration/05_monitor.sql -- \watch 3 \echo '═══════════════════════════════════════════════════════════' \echo ' MVCC BLOAT MONITOR — updated every \watch cycle' \echo '═══════════════════════════════════════════════════════════' \echo '' \echo '── Long-running transactions (xmin holders) ─────────────' SELECT pid, tx_duration, state, wait_event_type || '/' || COALESCE(wait_event,'') AS wait, left(query_snippet, 80) AS query FROM demo.long_running_tx LIMIT 5; \echo '' \echo '── xmin horizon (blocks autovacuum cleanup) ─────────────' SELECT pid, xmin_age, tx_age, state, left(query_snippet, 60) AS query FROM demo.xmin_horizon LIMIT 5; \echo '' \echo '── Dead tuple accumulation ──────────────────────────────' SELECT table_name, live_rows, dead_rows, dead_pct, total_size FROM demo.mvcc_bloat_monitor LIMIT 10; \echo '' \echo '── Active lock waits ────────────────────────────────────' SELECT blocked_pid, blocking_pid, wait_duration, left(blocked_query, 60) AS blocked_q, left(blocking_query, 60) AS blocking_q FROM demo.lock_waits LIMIT 5; \echo '' \echo '── WAL generation progress ──────────────────────────────' SELECT current_lsn, total_wal, wal_segment_count, wal_dir_size FROM demo.wal_progress; \echo '' \echo '── Autovacuum activity ──────────────────────────────────' SELECT pid, running_for, left(vacuum_query, 80) AS query FROM demo.autovacuum_status;