@@ -158,6 +158,9 @@ static bool lazy_check_needs_freeze(Buffer buf, bool *hastup);
158158static void lazy_vacuum_index (Relation indrel ,
159159IndexBulkDeleteResult * * stats ,
160160LVRelStats * vacrelstats );
161+ static void lazy_vacuum_all_indexes (Relation onerel ,LVRelStats * vacrelstats ,
162+ Relation * Irel ,int nindexes ,
163+ IndexBulkDeleteResult * * indstats );
161164static void lazy_cleanup_index (Relation indrel ,
162165IndexBulkDeleteResult * stats ,
163166LVRelStats * vacrelstats );
@@ -740,12 +743,6 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
740743if ((vacrelstats -> max_dead_tuples - vacrelstats -> num_dead_tuples )< MaxHeapTuplesPerPage &&
741744vacrelstats -> num_dead_tuples > 0 )
742745{
743- const int hvp_index []= {
744- PROGRESS_VACUUM_PHASE ,
745- PROGRESS_VACUUM_NUM_INDEX_VACUUMS
746- };
747- int64 hvp_val [2 ];
748-
749746/*
750747 * Before beginning index vacuuming, we release any pin we may
751748 * hold on the visibility map page. This isn't necessary for
@@ -758,28 +755,9 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
758755vmbuffer = InvalidBuffer ;
759756}
760757
761- /* Log cleanup info before we touch indexes */
762- vacuum_log_cleanup_info (onerel ,vacrelstats );
763-
764- /* Report that we are now vacuuming indexes */
765- pgstat_progress_update_param (PROGRESS_VACUUM_PHASE ,
766- PROGRESS_VACUUM_PHASE_VACUUM_INDEX );
767-
768- /* Remove index entries */
769- for (i = 0 ;i < nindexes ;i ++ )
770- lazy_vacuum_index (Irel [i ],
771- & indstats [i ],
772- vacrelstats );
773-
774- /*
775- * Report that we are now vacuuming the heap. We also increase
776- * the number of index scans here; note that by using
777- * pgstat_progress_update_multi_param we can update both
778- * parameters atomically.
779- */
780- hvp_val [0 ]= PROGRESS_VACUUM_PHASE_VACUUM_HEAP ;
781- hvp_val [1 ]= vacrelstats -> num_index_scans + 1 ;
782- pgstat_progress_update_multi_param (2 ,hvp_index ,hvp_val );
758+ /* Work on all the indexes, then the heap */
759+ lazy_vacuum_all_indexes (onerel ,vacrelstats ,Irel ,
760+ nindexes ,indstats );
783761
784762/* Remove tuples from heap */
785763lazy_vacuum_heap (onerel ,vacrelstats );
@@ -790,7 +768,6 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
790768 * valid.
791769 */
792770vacrelstats -> num_dead_tuples = 0 ;
793- vacrelstats -> num_index_scans ++ ;
794771
795772/*
796773 * Vacuum the Free Space Map to make newly-freed space visible on
@@ -1420,33 +1397,12 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
14201397/* XXX put a threshold on min number of tuples here? */
14211398if (vacrelstats -> num_dead_tuples > 0 )
14221399{
1423- const int hvp_index []= {
1424- PROGRESS_VACUUM_PHASE ,
1425- PROGRESS_VACUUM_NUM_INDEX_VACUUMS
1426- };
1427- int64 hvp_val [2 ];
1428-
1429- /* Log cleanup info before we touch indexes */
1430- vacuum_log_cleanup_info (onerel ,vacrelstats );
1431-
1432- /* Report that we are now vacuuming indexes */
1433- pgstat_progress_update_param (PROGRESS_VACUUM_PHASE ,
1434- PROGRESS_VACUUM_PHASE_VACUUM_INDEX );
1435-
1436- /* Remove index entries */
1437- for (i = 0 ;i < nindexes ;i ++ )
1438- lazy_vacuum_index (Irel [i ],
1439- & indstats [i ],
1440- vacrelstats );
1441-
1442- /* Report that we are now vacuuming the heap */
1443- hvp_val [0 ]= PROGRESS_VACUUM_PHASE_VACUUM_HEAP ;
1444- hvp_val [1 ]= vacrelstats -> num_index_scans + 1 ;
1445- pgstat_progress_update_multi_param (2 ,hvp_index ,hvp_val );
1400+ /* Work on all the indexes, and then the heap */
1401+ lazy_vacuum_all_indexes (onerel ,vacrelstats ,Irel ,nindexes ,
1402+ indstats );
14461403
14471404/* Remove tuples from heap */
14481405lazy_vacuum_heap (onerel ,vacrelstats );
1449- vacrelstats -> num_index_scans ++ ;
14501406}
14511407
14521408/*
@@ -1508,6 +1464,36 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
15081464pfree (buf .data );
15091465}
15101466
1467+ /*
1468+ *lazy_vacuum_all_indexes() -- vacuum all indexes of relation.
1469+ *
1470+ *This is a utility wrapper for lazy_vacuum_index(), able to do
1471+ *progress reporting.
1472+ */
1473+ static void
1474+ lazy_vacuum_all_indexes (Relation onerel ,LVRelStats * vacrelstats ,
1475+ Relation * Irel ,int nindexes ,
1476+ IndexBulkDeleteResult * * indstats )
1477+ {
1478+ int i ;
1479+
1480+ /* Log cleanup info before we touch indexes */
1481+ vacuum_log_cleanup_info (onerel ,vacrelstats );
1482+
1483+ /* Report that we are now vacuuming indexes */
1484+ pgstat_progress_update_param (PROGRESS_VACUUM_PHASE ,
1485+ PROGRESS_VACUUM_PHASE_VACUUM_INDEX );
1486+
1487+ /* Remove index entries */
1488+ for (i = 0 ;i < nindexes ;i ++ )
1489+ lazy_vacuum_index (Irel [i ],& indstats [i ],vacrelstats );
1490+
1491+ /* Increase and report the number of index scans */
1492+ vacrelstats -> num_index_scans ++ ;
1493+ pgstat_progress_update_param (PROGRESS_VACUUM_NUM_INDEX_VACUUMS ,
1494+ vacrelstats -> num_index_scans );
1495+ }
1496+
15111497
15121498/*
15131499 *lazy_vacuum_heap() -- second pass over the heap
@@ -1528,6 +1514,10 @@ lazy_vacuum_heap(Relation onerel, LVRelStats *vacrelstats)
15281514PGRUsage ru0 ;
15291515Buffer vmbuffer = InvalidBuffer ;
15301516
1517+ /* Report that we are now vacuuming the heap */
1518+ pgstat_progress_update_param (PROGRESS_VACUUM_PHASE ,
1519+ PROGRESS_VACUUM_PHASE_VACUUM_HEAP );
1520+
15311521pg_rusage_init (& ru0 );
15321522npages = 0 ;
15331523