dataiotech Labs
Scripts Library/postgresql/#19
Script #19
postgresql
Maintenanceread-onlyMin Version: 9.6

Track Running VACUUM Progress in PostgreSQL

Shows which phase each running vacuum is in and how far it has progressed. Helps estimate when a long vacuum will finish.

#vacuum#progress#pg_stat_progress_vacuum
postgresql · sql
SELECT p.pid, p.datname, p.relid::regclass AS table_name, p.phase,
       p.heap_blks_total, p.heap_blks_scanned,
       round(100.0 * p.heap_blks_scanned / NULLIF(p.heap_blks_total, 0), 1) AS pct_scanned,
       now() - a.xact_start AS running_for,
       left(a.query, 80) AS query
FROM pg_stat_progress_vacuum p
JOIN pg_stat_activity a USING (pid);
Operational Notes & Remediation Guidance

Verify in a staging environment prior to running in production. This is a read-only diagnostic query; it does not acquire exclusive locks.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 9.6).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.

Engineering Triad: Related Runbooks & Incident Response

Which production incidents and emergency drills execute this script as a diagnosis step?

Runbook Library (63)
Related Alerts & Metrics
M5PostgreSQL Transaction ID AgePostgreSQL
M6PostgreSQL Dead Tuple RatioPostgreSQL