While looking through vacuum code, I noticed that
unlike non-parallel vacuum, parallel vacuum only gets
a failsafe check after an entire index cycle completes.

In vacuumlazy.c, lazy_check_wraparound_failsafe is checked
after every index completes, while in parallel, it is checked
after an entire index cycle completed.

if (!ParallelVacuumIsActive(vacrel))
                {
                                for (int idx = 0; idx < vacrel->nindexes; idx++)
                                {
                                                Relation                indrel 
= vacrel->indrels[idx];
                                                IndexBulkDeleteResult *istat = 
vacrel->indstats[idx];

                                                vacrel->indstats[idx] =
                                                                
lazy_vacuum_one_index(indrel, istat, vacrel->old_live_tuples,
                                                                                
                                                                  vacrel);

                                                /*
                                                * Done vacuuming an index. 
Increment the indexes completed
                                                */
                                                
pgstat_progress_update_param(PROGRESS_VACUUM_INDEX_COMPLETED,
                                                                                
                                                                                
idx + 1);

                                                if 
(lazy_check_wraparound_failsafe(vacrel))
                                                {
                                                                /* Wraparound 
emergency -- end current index scan */
                                                                allindexes = 
false;
                                                                break;
                                                }
                                }
                }
                else
                {
                                /* Outsource everything to parallel variant */
                                
parallel_vacuum_bulkdel_all_indexes(vacrel->pvs, vacrel->old_live_tuples,
                                                                                
                                                                                
                vacrel->num_index_scans);

                                /*
                                * Do a postcheck to consider applying 
wraparound failsafe now.  Note
                                * that parallel VACUUM only gets the precheck 
and this postcheck.
                                */
                                if (lazy_check_wraparound_failsafe(vacrel))
                                                allindexes = false;
                }

When a user is running a parallel vacuum and the vacuum is long running
due to many large indexes, it would make sense to check for failsafe earlier.

Also, checking after every index for parallel vacuum will provide the same
failsafe behavior for both parallel and non-parallel vacuums.

To make this work, it is possible to call lazy_check_wraparound_failsafe
inside parallel_vacuum_process_unsafe_indexes and
parallel_vacuum_process_safe_indexes of vacuumparallel.c


Regards,

Sami Imseih
Amazon Web Services (AWS)

Reply via email to