stat_progress_vacuum collector provides real-time progress information for running vacuum operations.
Status
Default: EnabledMetrics
pg_stat_progress_vacuum_phase
Type: GaugeDescription: Current vacuum phase (1 = active, 0 = inactive) Labels:
datname- Database namerelname- Table name being vacuumedphase- Human-readable phase name
initializingscanning heapvacuuming indexesvacuuming heapcleaning up indexestruncating heapperforming final cleanup
pg_stat_progress_vacuum_heap_blks
Type: GaugeDescription: Total number of heap blocks in the table being vacuumed Labels:
datname, relname
pg_stat_progress_vacuum_heap_blks_scanned
Type: GaugeDescription: Number of heap blocks scanned so far Labels:
datname, relname
pg_stat_progress_vacuum_heap_blks_vacuumed
Type: GaugeDescription: Number of heap blocks vacuumed so far Labels:
datname, relname
pg_stat_progress_vacuum_index_vacuums
Type: GaugeDescription: Number of completed index vacuum cycles Labels:
datname, relname
pg_stat_progress_vacuum_max_dead_tuples
Type: GaugeDescription: Maximum number of dead tuples that can be stored before cleanup is performed Labels:
datname, relname
pg_stat_progress_vacuum_num_dead_tuples
Type: GaugeDescription: Current number of dead tuples found so far Labels:
datname, relname
SQL Query
PostgreSQL Versions
Supported: PostgreSQL 9.6+ Thepg_stat_progress_vacuum view was introduced in PostgreSQL 9.6.
Required Permissions
The monitoring user needs:- Access to
pg_stat_get_progress_info()function - Access to
pg_databasecatalog
Example Output
Use Cases
Monitor Vacuum Progress
Identify Current Phase
Estimate Remaining Time
Combine with vacuum start time to estimate completion:Vacuum Phases Explained
- initializing - Starting vacuum operation
- scanning heap - Scanning table pages for dead tuples
- vacuuming indexes - Removing index entries for dead tuples
- vacuuming heap - Removing dead tuples from table pages
- cleaning up indexes - Final index cleanup
- truncating heap - Returning empty pages at end of table to OS
- performing final cleanup - Final cleanup before completion
Index Vacuum Cycles
Theindex_vacuum_count metric shows how many times indexes have been vacuumed. Multiple cycles occur when:
- Table has many dead tuples
maintenance_work_memis too small to hold all dead tuple identifiers- Multiple index vacuum passes are required
Dead Tuple Limits
Themax_dead_tuples value is determined by maintenance_work_mem:
num_dead_tuples reaches max_dead_tuples, vacuum performs an index vacuum cycle.
Alert Examples
Troubleshooting
Check Vacuum Progress Directly
Slow Vacuum Issues
- Many index vacuum cycles: Increase
maintenance_work_mem - Stuck in scanning heap: Check for concurrent long-running transactions
- Slow I/O: Check
autovacuum_vacuum_cost_delayand storage performance