From 2d498cbb0e2e5c5438e1bb204b8708831c4d4c3c Mon Sep 17 00:00:00 2001
From: Masahiko Sawada <sawada.mshk@gmail.com>
Date: Thu, 27 Feb 2025 13:41:35 -0800
Subject: [PATCH v17 4/5] Support parallelism for collecting dead items during
 lazy vacuum.

This feature allows the vacuum to leverage multiple CPUs in order to
collect dead items (i.e. the first pass over heap table) with parallel
workers. The parallel degree for parallel heap vacuuming is determined
based on the number of blocks to vacuum unless PARALLEL option of
VACUUM command is specified, and further limited by
max_parallel_maintenance_workers.

For the parallel heap scan to collect dead items, we utilize a
parallel block table scan, controlled by ParallelBlockTableScanDesc,
in conjunction with the read stream. The workers' parallel scan
descriptions are stored in the DSM space, enabling different parallel
workers to resume the heap scan (phase 1) after a cycle of heap
vacuuming and index vacuuming (phase 2 and 3) from their previous
state. However, due to the potential presence of pinned buffers loaded
by the read stream's look-ahead mechanism, we cannot abruptly stop
phase 1 even when the space of dead_items TIDs exceeds the
limit. Therefore, once the space of dead_items TIDs exceeds the limit,
we begin processing pages without attempting to retrieve additional
blocks by look-ahead mechanism until the read stream is exhausted,
even if the the memory limit is surpassed. While this approach may
increase the memory usage, it typically doesn't pose a significant
problem, as processing a few 10s-100s buffers doesn't substantially
increase the size of dead_items TIDs.

Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Reviewed-by: Tomas Vondra <tomas@vondra.me>
Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CAD21AoAEfCNv-GgaDheDJ+s-p_Lv1H24AiJeNoPGCmZNSwL1YA@mail.gmail.com
---
 doc/src/sgml/ref/vacuum.sgml                  |   54 +-
 src/backend/access/heap/heapam_handler.c      |    8 +-
 src/backend/access/heap/vacuumlazy.c          | 1182 +++++++++++++++--
 src/backend/commands/vacuumparallel.c         |   29 +
 src/include/access/heapam.h                   |   13 +
 src/include/commands/vacuum.h                 |    3 +
 src/test/regress/expected/vacuum_parallel.out |    7 +
 src/test/regress/sql/vacuum_parallel.sql      |    8 +
 src/tools/pgindent/typedefs.list              |    5 +
 9 files changed, 1198 insertions(+), 111 deletions(-)

diff --git a/doc/src/sgml/ref/vacuum.sgml b/doc/src/sgml/ref/vacuum.sgml
index bd5dcaf86a5..294494877d9 100644
--- a/doc/src/sgml/ref/vacuum.sgml
+++ b/doc/src/sgml/ref/vacuum.sgml
@@ -280,25 +280,41 @@ VACUUM [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] [ <re
     <term><literal>PARALLEL</literal></term>
     <listitem>
      <para>
-      Perform index vacuum and index cleanup phases of <command>VACUUM</command>
-      in parallel using <replaceable class="parameter">integer</replaceable>
-      background workers (for the details of each vacuum phase, please
-      refer to <xref linkend="vacuum-phases"/>).  The number of workers used
-      to perform the operation is equal to the number of indexes on the
-      relation that support parallel vacuum which is limited by the number of
-      workers specified with <literal>PARALLEL</literal> option if any which is
-      further limited by <xref linkend="guc-max-parallel-maintenance-workers"/>.
-      An index can participate in parallel vacuum if and only if the size of the
-      index is more than <xref linkend="guc-min-parallel-index-scan-size"/>.
-      Please note that it is not guaranteed that the number of parallel workers
-      specified in <replaceable class="parameter">integer</replaceable> will be
-      used during execution.  It is possible for a vacuum to run with fewer
-      workers than specified, or even with no workers at all.  Only one worker
-      can be used per index.  So parallel workers are launched only when there
-      are at least <literal>2</literal> indexes in the table.  Workers for
-      vacuum are launched before the start of each phase and exit at the end of
-      the phase.  These behaviors might change in a future release.  This
-      option can't be used with the <literal>FULL</literal> option.
+      Perform scanning heap, index vacuum, and index cleanup phases of
+      <command>VACUUM</command> in parallel using
+      <replaceable class="parameter">integer</replaceable> background workers
+      (for the details of each vacuum phase, please refer to
+      <xref linkend="vacuum-phases"/>).
+     </para>
+     <para>
+      For heap tables, the number of workers used to perform the scanning
+      heap is determined based on the size of table. A table can participate in
+      parallel scanning heap if and only if the size of the table is more than
+      <xref linkend="guc-min-parallel-table-scan-size"/>. During scanning heap,
+      the heap table's blocks will be divided into ranges and shared among the
+      cooperating processes. Each worker process will complete the scanning of
+      its given range of blocks before requesting an additional range of blocks.
+     </para>
+     <para>
+      The number of workers used to perform parallel index vacuum and index
+      cleanup is equal to the number of indexes on the relation that support
+      parallel vacuum. An index can participate in parallel vacuum if and only
+      if the size of the index is more than <xref linkend="guc-min-parallel-index-scan-size"/>.
+      Only one worker can be used per index. So parallel workers for index vacuum
+      and index cleanup are launched only when there are at least <literal>2</literal>
+      indexes in the table.
+     </para>
+     <para>
+      Workers for vacuum are launched before the start of each phase and exit
+      at the end of the phase. The number of workers for each phase is limited by
+      the number of workers specified with <literal>PARALLEL</literal> option if
+      any which is futher limited by <xref linkend="guc-max-parallel-maintenance-workers"/>.
+      Please note that in any parallel vacuum phase, it is not guaanteed that the
+      number of parallel workers specified in <replaceable class="parameter">integer</replaceable>
+      will be used during execution. It is possible for a vacuum to run with fewer
+      workers than specified, or even with no workers at all. These behaviors might
+      change in a future release. This option can't be used with the <literal>FULL</literal>
+      option.
      </para>
     </listitem>
    </varlistentry>
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index cb4bc35c93e..1db6dc5b1db 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2668,7 +2668,13 @@ static const TableAmRoutine heapam_methods = {
 
 	.scan_bitmap_next_tuple = heapam_scan_bitmap_next_tuple,
 	.scan_sample_next_block = heapam_scan_sample_next_block,
-	.scan_sample_next_tuple = heapam_scan_sample_next_tuple
+	.scan_sample_next_tuple = heapam_scan_sample_next_tuple,
+
+	.parallel_vacuum_compute_workers = heap_parallel_vacuum_compute_workers,
+	.parallel_vacuum_estimate = heap_parallel_vacuum_estimate,
+	.parallel_vacuum_initialize = heap_parallel_vacuum_initialize,
+	.parallel_vacuum_initialize_worker = heap_parallel_vacuum_initialize_worker,
+	.parallel_vacuum_collect_dead_items = heap_parallel_vacuum_collect_dead_items
 };
 
 
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index b3aa151b497..71c4a363916 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -99,6 +99,44 @@
  * After pruning and freezing, pages that are newly all-visible and all-frozen
  * are marked as such in the visibility map.
  *
+ * Parallel Vacuum:
+ *
+ * Lazy vacuum on heap tables supports parallel processing for phase I and
+ * phase II. Before starting phase I, we initialize parallel vacuum state,
+ * ParallelVacuumState, and allocate the TID store in a DSA area if we can
+ * use parallel mode for any of these two phases.
+ *
+ * We could require different number of parallel vacuum workers for each phase
+ * for various factors such as table size and number of indexes. Parallel
+ * workers are launched at the beginning of each phase and exit at the end of
+ * each phase.
+ *
+ * While vacuum cutoffs are shared between leader and worker processes, each
+ * individual process uses its own GlobalVisState, potentially causing some
+ * workers to remove fewer tuples than optimal. During parallel lazy heap scans,
+ * each worker tracks the oldest existing XID and MXID. The leader computes the
+ * globally oldest existing XID and MXID after the parallel scan, while
+ * gathering table data too.
+ *
+ * The parallel lazy heap scan (i.e. parallel phase I) is controlled by
+ * ParallelLVScanDesc in conjunction with the read stream. The table is split
+ * into multiple chunks, which are then distributed among parallel workers.
+ * Due to the potential presence of pinned buffers loaded by the read stream's
+ * look-ahead mechanism, we cannot abruptly stop phase I even hen the space
+ * of dead_items TIDs exceeds the limit. Instead, once this threshold is
+ * surpassed, we begin processing pages without attempting to retrieve additional
+ * blocks until the read stream is exhausted. While this approach may increase
+ * the memory usage, it typically doesn't pose a significant problem, as
+ * processing a few 10s-100s buffers doesn't substantially increase the size
+ * of dead_items TIDs. The workers' parallel scan descriptions,
+ * ParallelLVScanWorkerData, are stored in the DSM space, enabling different
+ * parallel workers to resume phase I from their previous state.
+ *
+ * If the leader launches fewer workers than the previous time to resume the
+ * parallel lazy heap scan, some block within chunks may remain un-scanned.
+ * To address this, the leader completes workers' unfinished scans at the end
+ * of the parallel lazy heap scan (see complete_unfinished_lazy_scan_heap()).
+ *
  * Dead TID Storage:
  *
  * The major space usage for vacuuming is storage for the dead tuple IDs that
@@ -147,6 +185,7 @@
 #include "common/pg_prng.h"
 #include "executor/instrument.h"
 #include "miscadmin.h"
+#include "optimizer/paths.h"	/* for min_parallel_table_scan_size */
 #include "pgstat.h"
 #include "portability/instr_time.h"
 #include "postmaster/autovacuum.h"
@@ -214,11 +253,22 @@
  */
 #define PREFETCH_SIZE			((BlockNumber) 32)
 
+/*
+ * DSM keys for parallel lazy vacuum. Unlike other parallel execution code, we
+ * we don't need to worry about DSM keys conflicting with plan_node_id, but need to
+ * avoid conflicting with DSM keys used in vacuumparallel.c.
+ */
+#define PARALLEL_LV_KEY_SHARED				0xFFFF0001
+#define PARALLEL_LV_KEY_SCANDESC			0xFFFF0002
+#define PARALLEL_LV_KEY_SCANWORKER			0xFFFF0003
+#define PARALLEL_LV_KEY_SCANDATA			0xFFFF0004
+
 /*
  * Macro to check if we are in a parallel vacuum.  If true, we are in the
  * parallel mode and the DSM segment is initialized.
  */
 #define ParallelVacuumIsActive(vacrel) ((vacrel)->pvs != NULL)
+#define ParallelHeapVacuumIsActive(vacrel) ((vacrel)->plvstate != NULL)
 
 /* Phases of vacuum during which we report error context. */
 typedef enum
@@ -249,6 +299,12 @@ typedef enum
  */
 #define EAGER_SCAN_REGION_SIZE 4096
 
+/*
+ * During parallel lazy scans, each worker (including the leader) retrieves
+ * a chunk consisting of PARALLEL_LV_CHUNK_SIZE blocks.
+ */
+#define PARALLEL_LV_CHUNK_SIZE	1024
+
 /*
  * heap_vac_scan_next_block() sets these flags to communicate information
  * about the block it read to the caller.
@@ -304,6 +360,121 @@ typedef struct LVScanData
 	bool		skippedallvis;
 } LVScanData;
 
+/*
+ * Struct for information that needs to be shared among parallel workers
+ * for parallel lazy vacuum. All fields are static, set by the leader
+ * process.
+ */
+typedef struct ParallelLVShared
+{
+	bool		aggressive;
+	bool		skipwithvm;
+
+	/* The current oldest extant XID/MXID shared by the leader process */
+	TransactionId NewRelfrozenXid;
+	MultiXactId NewRelminMxid;
+
+	/* VACUUM operation's cutoffs for freezing and pruning */
+	struct VacuumCutoffs cutoffs;
+
+	/*
+	 * The first chunk size varies depending on the first eager scan region
+	 * size. If eager scan is disabled, we use the default chunk size
+	 * PARALLEL_LV_CHUNK_SIZE for the first chunk.
+	 */
+	BlockNumber initial_chunk_size;
+
+	/*
+	 * Similar to LVRelState.eager_scan_max_fails_per_region but this is a
+	 * per-chunk failure counter.
+	 */
+	BlockNumber eager_scan_max_fails_per_chunk;
+
+	/*
+	 * Similar to LVRelState.eager_scan_remaining_successes but this is a
+	 * success counter per parallel worker.
+	 */
+	BlockNumber eager_scan_remaining_successes_per_worker;
+} ParallelLVShared;
+
+/*
+ * Shared scan description for parallel lazy scan.
+ */
+typedef struct ParallelLVScanDesc
+{
+	/* Number of blocks of the table at start of scan */
+	BlockNumber nblocks;
+
+	/* Number of blocks in to allocate in each I/O chunk */
+	BlockNumber chunk_size;
+
+	/* Number of blocks allocated to workers so far */
+	pg_atomic_uint64 nallocated;
+} ParallelLVScanDesc;
+
+/*
+ * Per-worker data for scan description, statistics counters, and
+ * miscellaneous data need to be shared with the leader.
+ */
+typedef struct ParallelLVScanWorkerData
+{
+	bool		inited;
+
+	/* Current number of blocks into the scan */
+	BlockNumber nallocated;
+
+	/* Number of blocks per chunk */
+	BlockNumber chunk_size;
+
+	/* Number of blocks left in this chunk */
+	uint32		chunk_remaining;
+
+	/* The last processed block number */
+	pg_atomic_uint32 last_blkno;
+
+	/* Eager scan state for resuming the scan */
+	BlockNumber remaining_fails_save;
+	BlockNumber remaining_successes_save;
+	BlockNumber next_region_start_save;
+} ParallelLVScanWorkerData;
+
+/*
+ * Struct to store parallel lazy vacuum working state.
+ */
+typedef struct ParallelLVState
+{
+	/* Shared static information */
+	ParallelLVShared *shared;
+
+	/* Parallel scan description shared among parallel workers */
+	ParallelLVScanDesc *scandesc;
+
+	/* Per-worker scan data */
+	ParallelLVScanWorkerData *scanwork;
+} ParallelLVState;
+
+/*
+ * Struct for the leader process in parallel lazy vacuum.
+ */
+typedef struct ParallelLVLeader
+{
+	/* Shared memory size for each shared object */
+	Size		shared_len;
+	Size		scandesc_len;
+	Size		scanwork_len;
+	Size		scandata_len;
+
+	/* The number of workers launched for parallel lazy heap scan */
+	int			nworkers_launched;
+
+	/*
+	 * These fields point to the arrays of all per-worker scan states stored
+	 * in DSM.
+	 */
+	ParallelLVScanWorkerData *scanwork_array;
+	LVScanData *scandata_array;
+} ParallelLVLeader;
+
 typedef struct LVRelState
 {
 	/* Target heap relation and its indexes */
@@ -368,6 +539,12 @@ typedef struct LVRelState
 	/* Instrumentation counters */
 	int			num_index_scans;
 
+	/* Last processed block number */
+	BlockNumber last_blkno;
+
+	/* Next block to check for FSM vacuum */
+	BlockNumber next_fsm_block_to_vacuum;
+
 	/* State maintained by heap_vac_scan_next_block() */
 	BlockNumber current_block;	/* last block returned */
 	BlockNumber next_unskippable_block; /* next unskippable block */
@@ -375,6 +552,16 @@ typedef struct LVRelState
 	bool		next_unskippable_eager_scanned; /* if it was eagerly scanned */
 	Buffer		next_unskippable_vmbuffer;	/* buffer containing its VM bit */
 
+	/* Fields used for parallel lazy vacuum */
+
+	/* Parallel lazy vacuum working state */
+	ParallelLVState *plvstate;
+
+	/*
+	 * The leader state for parallel lazy vacuum. NULL for parallel workers.
+	 */
+	ParallelLVLeader *leader;
+
 	/* State related to managing eager scanning of all-visible pages */
 
 	/*
@@ -434,12 +621,19 @@ typedef struct LVSavedErrInfo
 
 /* non-export function prototypes */
 static void lazy_scan_heap(LVRelState *vacrel);
+static void do_lazy_scan_heap(LVRelState *vacrel, bool check_mem_usage);
 static void heap_vacuum_eager_scan_setup(LVRelState *vacrel,
 										 VacuumParams *params);
 static BlockNumber heap_vac_scan_next_block(ReadStream *stream,
 											void *callback_private_data,
 											void *per_buffer_data);
-static void find_next_unskippable_block(LVRelState *vacrel, bool *skipsallvis);
+static void parallel_lazy_scan_init_scan_worker(ParallelLVScanWorkerData *scanwork,
+												BlockNumber initial_chunk_size);
+static BlockNumber parallel_lazy_scan_get_nextpage(LVRelState *vacrel, Relation rel,
+												   ParallelLVScanDesc *scandesc,
+												   ParallelLVScanWorkerData *scanwork);
+static bool find_next_unskippable_block(LVRelState *vacrel, bool *skipsallvis,
+										BlockNumber start_blk, BlockNumber end_blk);
 static bool lazy_scan_new_or_empty(LVRelState *vacrel, Buffer buf,
 								   BlockNumber blkno, Page page,
 								   bool sharelock, Buffer vmbuffer);
@@ -450,6 +644,12 @@ static void lazy_scan_prune(LVRelState *vacrel, Buffer buf,
 static bool lazy_scan_noprune(LVRelState *vacrel, Buffer buf,
 							  BlockNumber blkno, Page page,
 							  bool *has_lpdead_items);
+static void do_parallel_lazy_scan_heap(LVRelState *vacrel);
+static BlockNumber parallel_lazy_scan_compute_min_scan_block(LVRelState *vacrel);
+static void complete_unfinished_lazy_scan_heap(LVRelState *vacrel);
+static void parallel_lazy_scan_heap_begin(LVRelState *vacrel);
+static void parallel_lazy_scan_heap_end(LVRelState *vacrel);
+static void parallel_lazy_scan_gather_results(LVRelState *vacrel);
 static void lazy_vacuum(LVRelState *vacrel);
 static bool lazy_vacuum_all_indexes(LVRelState *vacrel);
 static void lazy_vacuum_heap_rel(LVRelState *vacrel);
@@ -474,6 +674,7 @@ static BlockNumber count_nondeletable_pages(LVRelState *vacrel,
 static void dead_items_alloc(LVRelState *vacrel, int nworkers);
 static void dead_items_add(LVRelState *vacrel, BlockNumber blkno, OffsetNumber *offsets,
 						   int num_offsets);
+static bool dead_items_check_memory_limit(LVRelState *vacrel);
 static void dead_items_reset(LVRelState *vacrel);
 static void dead_items_cleanup(LVRelState *vacrel);
 static bool heap_page_is_all_visible(LVRelState *vacrel, Buffer buf,
@@ -770,6 +971,7 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
 
 	/* Initialize remaining counters (be tidy) */
 	vacrel->num_index_scans = 0;
+	vacrel->next_fsm_block_to_vacuum = 0;
 
 	/* dead_items_alloc allocates vacrel->dead_items later on */
 
@@ -1215,13 +1417,7 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
 static void
 lazy_scan_heap(LVRelState *vacrel)
 {
-	ReadStream *stream;
-	BlockNumber rel_pages = vacrel->rel_pages,
-				blkno = 0,
-				next_fsm_block_to_vacuum = 0;
-	BlockNumber orig_eager_scan_success_limit =
-		vacrel->eager_scan_remaining_successes; /* for logging */
-	Buffer		vmbuffer = InvalidBuffer;
+	BlockNumber rel_pages = vacrel->rel_pages;
 	const int	initprog_index[] = {
 		PROGRESS_VACUUM_PHASE,
 		PROGRESS_VACUUM_TOTAL_HEAP_BLKS,
@@ -1242,6 +1438,80 @@ lazy_scan_heap(LVRelState *vacrel)
 	vacrel->next_unskippable_eager_scanned = false;
 	vacrel->next_unskippable_vmbuffer = InvalidBuffer;
 
+	/* Do the actual work */
+	if (ParallelHeapVacuumIsActive(vacrel))
+		do_parallel_lazy_scan_heap(vacrel);
+	else
+		do_lazy_scan_heap(vacrel, true);
+
+	/*
+	 * Report that everything is now scanned. We never skip scanning the last
+	 * block in the relation, so we can pass rel_pages here.
+	 */
+	pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_SCANNED,
+								 rel_pages);
+
+	/* now we can compute the new value for pg_class.reltuples */
+	vacrel->new_live_tuples = vac_estimate_reltuples(vacrel->rel, rel_pages,
+													 vacrel->scan_data->scanned_pages,
+													 vacrel->scan_data->live_tuples);
+
+	/*
+	 * Also compute the total number of surviving heap entries.  In the
+	 * (unlikely) scenario that new_live_tuples is -1, take it as zero.
+	 */
+	vacrel->new_rel_tuples =
+		Max(vacrel->new_live_tuples, 0) + vacrel->scan_data->recently_dead_tuples +
+		vacrel->scan_data->missed_dead_tuples;
+
+	/*
+	 * Do index vacuuming (call each index's ambulkdelete routine), then do
+	 * related heap vacuuming
+	 */
+	if (vacrel->dead_items_info->num_items > 0)
+		lazy_vacuum(vacrel);
+
+	/*
+	 * Vacuum the remainder of the Free Space Map.  We must do this whether or
+	 * not there were indexes, and whether or not we bypassed index vacuuming.
+	 * We can pass rel_pages here because we never skip scanning the last
+	 * block of the relation.
+	 */
+	if (rel_pages > vacrel->next_fsm_block_to_vacuum)
+		FreeSpaceMapVacuumRange(vacrel->rel, vacrel->next_fsm_block_to_vacuum, rel_pages);
+
+	/* report all blocks vacuumed */
+	pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_VACUUMED, rel_pages);
+
+	/* Do final index cleanup (call each index's amvacuumcleanup routine) */
+	if (vacrel->nindexes > 0 && vacrel->do_index_cleanup)
+		lazy_cleanup_all_indexes(vacrel);
+}
+
+/*
+ * Workhorse for lazy_scan_heap().
+ *
+ * If check_mem_usage is true, we check the memory usage during the heap scan.
+ * If the space of dead_items TIDs exceeds the limit, we stop the lazy heap scan
+ * and invoke a cycle of index vacuuming and heap vacuuming, and then resume the
+ * scan. If it's false, we continue doing lazy heap scan until the read stream
+ * is exhausted.
+ */
+static void
+do_lazy_scan_heap(LVRelState *vacrel, bool check_mem_usage)
+{
+	ReadStream *stream;
+	BlockNumber blkno = InvalidBlockNumber;
+	BlockNumber orig_eager_scan_success_limit =
+		vacrel->eager_scan_remaining_successes; /* for logging */
+	Buffer		vmbuffer = InvalidBuffer;
+
+	/*
+	 * We should not set check_mem_usage to false unless during parallel heap
+	 * vacuum.
+	 */
+	Assert(check_mem_usage || ParallelHeapVacuumIsActive(vacrel));
+
 	/*
 	 * Set up the read stream for vacuum's first pass through the heap.
 	 *
@@ -1276,8 +1546,11 @@ lazy_scan_heap(LVRelState *vacrel)
 		 * that point.  This check also provides failsafe coverage for the
 		 * one-pass strategy, and the two-pass strategy with the index_cleanup
 		 * param set to 'off'.
+		 *
+		 * The failsafe check is done only by the leader process.
 		 */
-		if (vacrel->scan_data->scanned_pages > 0 &&
+		if (!IsParallelWorker() &&
+			vacrel->scan_data->scanned_pages > 0 &&
 			vacrel->scan_data->scanned_pages % FAILSAFE_EVERY_PAGES == 0)
 			lazy_check_wraparound_failsafe(vacrel);
 
@@ -1285,12 +1558,9 @@ lazy_scan_heap(LVRelState *vacrel)
 		 * Consider if we definitely have enough space to process TIDs on page
 		 * already.  If we are close to overrunning the available space for
 		 * dead_items TIDs, pause and do a cycle of vacuuming before we tackle
-		 * this page. However, let's force at least one page-worth of tuples
-		 * to be stored as to ensure we do at least some work when the memory
-		 * configured is so low that we run out before storing anything.
+		 * this page.
 		 */
-		if (vacrel->dead_items_info->num_items > 0 &&
-			TidStoreMemoryUsage(vacrel->dead_items) > vacrel->dead_items_info->max_bytes)
+		if (check_mem_usage && dead_items_check_memory_limit(vacrel))
 		{
 			/*
 			 * Before beginning index vacuuming, we release any pin we may
@@ -1313,15 +1583,16 @@ lazy_scan_heap(LVRelState *vacrel)
 			 * upper-level FSM pages. Note that blkno is the previously
 			 * processed block.
 			 */
-			FreeSpaceMapVacuumRange(vacrel->rel, next_fsm_block_to_vacuum,
+			FreeSpaceMapVacuumRange(vacrel->rel, vacrel->next_fsm_block_to_vacuum,
 									blkno + 1);
-			next_fsm_block_to_vacuum = blkno;
+			vacrel->next_fsm_block_to_vacuum = blkno;
 
 			/* Report that we are once again scanning the heap */
 			pgstat_progress_update_param(PROGRESS_VACUUM_PHASE,
 										 PROGRESS_VACUUM_PHASE_SCAN_HEAP);
 		}
 
+		/* Read the next block to process */
 		buf = read_stream_next_buffer(stream, &per_buffer_data);
 
 		/* The relation is exhausted. */
@@ -1331,7 +1602,7 @@ lazy_scan_heap(LVRelState *vacrel)
 		blk_info = *((uint8 *) per_buffer_data);
 		CheckBufferIsPinnedOnce(buf);
 		page = BufferGetPage(buf);
-		blkno = BufferGetBlockNumber(buf);
+		blkno = vacrel->last_blkno = BufferGetBlockNumber(buf);
 
 		vacrel->scan_data->scanned_pages++;
 		if (blk_info & VAC_BLK_WAS_EAGER_SCANNED)
@@ -1496,13 +1767,34 @@ lazy_scan_heap(LVRelState *vacrel)
 			 * visible on upper FSM pages. This is done after vacuuming if the
 			 * table has indexes. There will only be newly-freed space if we
 			 * held the cleanup lock and lazy_scan_prune() was called.
+			 *
+			 * During parallel lazy heap scanning, only the leader process
+			 * vacuums the FSM. However, we cannot vacuum the FSM for blocks
+			 * up to 'blk' because there may be un-scanned blocks or blocks
+			 * being processed by workers before this point. Instead, parallel
+			 * workers advertise the block numbers they have just processed,
+			 * and the leader vacuums the FSM up to the smallest block number
+			 * among them. This approach ensures we vacuum the FSM for
+			 * consecutive processed blocks.
 			 */
 			if (got_cleanup_lock && vacrel->nindexes == 0 && has_lpdead_items &&
-				blkno - next_fsm_block_to_vacuum >= VACUUM_FSM_EVERY_PAGES)
+				blkno - vacrel->next_fsm_block_to_vacuum >= VACUUM_FSM_EVERY_PAGES)
 			{
-				FreeSpaceMapVacuumRange(vacrel->rel, next_fsm_block_to_vacuum,
+				if (IsParallelWorker())
+					pg_atomic_write_u32(&(vacrel->plvstate->scanwork->last_blkno),
 										blkno);
-				next_fsm_block_to_vacuum = blkno;
+				else
+				{
+					BlockNumber fsmvac_upto = blkno;
+
+					if (ParallelHeapVacuumIsActive(vacrel))
+						fsmvac_upto = parallel_lazy_scan_compute_min_scan_block(vacrel);
+
+					FreeSpaceMapVacuumRange(vacrel->rel, vacrel->next_fsm_block_to_vacuum,
+											fsmvac_upto);
+				}
+
+				vacrel->next_fsm_block_to_vacuum = blkno;
 			}
 		}
 		else
@@ -1513,50 +1805,7 @@ lazy_scan_heap(LVRelState *vacrel)
 	if (BufferIsValid(vmbuffer))
 		ReleaseBuffer(vmbuffer);
 
-	/*
-	 * Report that everything is now scanned. We never skip scanning the last
-	 * block in the relation, so we can pass rel_pages here.
-	 */
-	pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_SCANNED,
-								 rel_pages);
-
-	/* now we can compute the new value for pg_class.reltuples */
-	vacrel->new_live_tuples = vac_estimate_reltuples(vacrel->rel, rel_pages,
-													 vacrel->scan_data->scanned_pages,
-													 vacrel->scan_data->live_tuples);
-
-	/*
-	 * Also compute the total number of surviving heap entries.  In the
-	 * (unlikely) scenario that new_live_tuples is -1, take it as zero.
-	 */
-	vacrel->new_rel_tuples =
-		Max(vacrel->new_live_tuples, 0) + vacrel->scan_data->recently_dead_tuples +
-		vacrel->scan_data->missed_dead_tuples;
-
 	read_stream_end(stream);
-
-	/*
-	 * Do index vacuuming (call each index's ambulkdelete routine), then do
-	 * related heap vacuuming
-	 */
-	if (vacrel->dead_items_info->num_items > 0)
-		lazy_vacuum(vacrel);
-
-	/*
-	 * Vacuum the remainder of the Free Space Map.  We must do this whether or
-	 * not there were indexes, and whether or not we bypassed index vacuuming.
-	 * We can pass rel_pages here because we never skip scanning the last
-	 * block of the relation.
-	 */
-	if (rel_pages > next_fsm_block_to_vacuum)
-		FreeSpaceMapVacuumRange(vacrel->rel, next_fsm_block_to_vacuum, rel_pages);
-
-	/* report all blocks vacuumed */
-	pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_VACUUMED, rel_pages);
-
-	/* Do final index cleanup (call each index's amvacuumcleanup routine) */
-	if (vacrel->nindexes > 0 && vacrel->do_index_cleanup)
-		lazy_cleanup_all_indexes(vacrel);
 }
 
 /*
@@ -1570,7 +1819,8 @@ lazy_scan_heap(LVRelState *vacrel)
  * heap_vac_scan_next_block() uses the visibility map, vacuum options, and
  * various thresholds to skip blocks which do not need to be processed and
  * returns the next block to process or InvalidBlockNumber if there are no
- * remaining blocks.
+ * remaining blocks or the space of dead_items TIDs reaches the limit (only
+ * in parallel lazy vacuum cases).
  *
  * The visibility status of the next block to process and whether or not it
  * was eager scanned is set in the per_buffer_data.
@@ -1592,8 +1842,42 @@ heap_vac_scan_next_block(ReadStream *stream,
 	LVRelState *vacrel = callback_private_data;
 	uint8		blk_info = 0;
 
-	/* relies on InvalidBlockNumber + 1 overflowing to 0 on first call */
-	next_block = vacrel->current_block + 1;
+retry:
+	next_block = InvalidBlockNumber;
+
+	/* Get the next block to process */
+	if (ParallelHeapVacuumIsActive(vacrel))
+	{
+		/*
+		 * Stop returning the next block to the read stream if we are close to
+		 * overrunning the available space for dead_items TIDs so that the
+		 * read stream returns pinned buffers in its buffers queue until the
+		 * stream is exhausted. See the comments atop this file for details.
+		 */
+		if (dead_items_check_memory_limit(vacrel))
+		{
+			if (BufferIsValid(vacrel->next_unskippable_vmbuffer))
+			{
+				ReleaseBuffer(vacrel->next_unskippable_vmbuffer);
+				vacrel->next_unskippable_vmbuffer = InvalidBuffer;
+			}
+
+			return InvalidBlockNumber;
+
+		}
+
+		next_block = parallel_lazy_scan_get_nextpage(vacrel,
+													 vacrel->rel,
+													 vacrel->plvstate->scandesc,
+													 vacrel->plvstate->scanwork);
+	}
+	else
+	{
+		/* relies on InvalidBlockNumber + 1 overflowing to 0 on first call */
+		next_block = vacrel->current_block + 1;
+	}
+
+	Assert(BlockNumberIsValid(next_block));
 
 	/* Have we reached the end of the relation? */
 	if (next_block >= vacrel->rel_pages)
@@ -1618,8 +1902,41 @@ heap_vac_scan_next_block(ReadStream *stream,
 		 * visibility map.
 		 */
 		bool		skipsallvis;
+		bool		found;
+		BlockNumber end_block;
+		BlockNumber nblocks_skip;
 
-		find_next_unskippable_block(vacrel, &skipsallvis);
+		if (ParallelHeapVacuumIsActive(vacrel))
+		{
+			/* We look for the next unskippable block within the chunk */
+			end_block = next_block + vacrel->plvstate->scanwork->chunk_remaining + 1;
+		}
+		else
+			end_block = vacrel->rel_pages;
+
+		found = find_next_unskippable_block(vacrel, &skipsallvis, next_block, end_block);
+
+		/*
+		 * We must have found the next unskippable block within the specified
+		 * range in non-parallel cases as the end_block is always the last
+		 * block + 1 and we must scan the last block.
+		 */
+		Assert(found || ParallelHeapVacuumIsActive(vacrel));
+
+		if (!found)
+		{
+			if (skipsallvis)
+				vacrel->scan_data->skippedallvis = true;
+
+			/*
+			 * Skip all remaining blocks in the current chunk, and retry with
+			 * the next chunk.
+			 */
+			vacrel->plvstate->scanwork->chunk_remaining = 0;
+			goto retry;
+		}
+
+		Assert(vacrel->next_unskippable_block < end_block);
 
 		/*
 		 * We now know the next block that we must process.  It can be the
@@ -1636,11 +1953,21 @@ heap_vac_scan_next_block(ReadStream *stream,
 		 * pages then skipping makes updating relfrozenxid unsafe, which is a
 		 * real downside.
 		 */
-		if (vacrel->next_unskippable_block - next_block >= SKIP_PAGES_THRESHOLD)
+		nblocks_skip = vacrel->next_unskippable_block - next_block;
+		if (nblocks_skip >= SKIP_PAGES_THRESHOLD)
 		{
-			next_block = vacrel->next_unskippable_block;
 			if (skipsallvis)
 				vacrel->scan_data->skippedallvis = true;
+
+			/* Tell the parallel scans to skip blocks */
+			if (ParallelHeapVacuumIsActive(vacrel))
+			{
+				vacrel->plvstate->scanwork->chunk_remaining -= nblocks_skip;
+				vacrel->plvstate->scanwork->nallocated += nblocks_skip;
+				Assert(vacrel->plvstate->scanwork->chunk_remaining > 0);
+			}
+
+			next_block = vacrel->next_unskippable_block;
 		}
 	}
 
@@ -1675,10 +2002,86 @@ heap_vac_scan_next_block(ReadStream *stream,
 	}
 }
 
+
 /*
- * Find the next unskippable block in a vacuum scan using the visibility map.
- * The next unskippable block and its visibility information is updated in
- * vacrel.
+ * Initialize scan state of the given ParallelLVScanWorkerData.
+ */
+static void
+parallel_lazy_scan_init_scan_worker(ParallelLVScanWorkerData *scanwork,
+									BlockNumber initial_chunk_size)
+{
+	Assert(BlockNumberIsValid(initial_chunk_size));
+
+	scanwork->inited = true;
+	scanwork->nallocated = 0;
+	scanwork->chunk_size = initial_chunk_size;
+	scanwork->chunk_remaining = 0;
+	pg_atomic_init_u32(&(scanwork->last_blkno), InvalidBlockNumber);
+}
+
+/*
+ * Return the next page to process for parallel lazy scan.
+ *
+ * If there is no block to scan for the worker, return the number of blocks in
+ * the relation.
+ */
+static BlockNumber
+parallel_lazy_scan_get_nextpage(LVRelState *vacrel, Relation rel,
+								ParallelLVScanDesc *scandesc,
+								ParallelLVScanWorkerData *scanwork)
+{
+	uint64		nallocated;
+
+	if (scanwork->chunk_remaining > 0)
+	{
+		/*
+		 * Give them the next block in the range and update the remaining
+		 * number of blocks.
+		 */
+		nallocated = ++scanwork->nallocated;
+		scanwork->chunk_remaining--;
+	}
+	else
+	{
+		/* Get the new chunk */
+		nallocated = scanwork->nallocated =
+			pg_atomic_fetch_add_u64(&scandesc->nallocated, scanwork->chunk_size);
+
+		/*
+		 * Set the remaining number of blocks in this chunk so that subsequent
+		 * calls from this worker continue on with this chunk until it's done.
+		 */
+		scanwork->chunk_remaining = scanwork->chunk_size - 1;
+
+		/* We use the fixed size chunk for subsequent scans */
+		scanwork->chunk_size = PARALLEL_LV_CHUNK_SIZE;
+
+		/*
+		 * Getting the new chunk also means to start the new eager scan
+		 * region.
+		 *
+		 * Update next_eager_scan_region_start to the first block in the chunk
+		 * so that we can reset the remaining_fails counter when checking the
+		 * visibility of the first block in this chunk in
+		 * find_next_unskippable_block().
+		 */
+		vacrel->next_eager_scan_region_start = nallocated;
+
+	}
+
+	/* Clear the chunk_remaining if there is no more blocks to process */
+	if (nallocated >= scandesc->nblocks)
+		scanwork->chunk_remaining = 0;
+
+	return Min(nallocated, scandesc->nblocks);
+}
+
+/*
+ * Find the next unskippable block in a vacuum scan using the visibility map,
+ * in a range of 'start' (inclusive) and 'end' (exclusive).
+ *
+ * If found, the next unskippable block and its visibility information is updated
+ * in vacrel. Otherwise, return false and reset the information in vacrel.
  *
  * Note: our opinion of which blocks can be skipped can go stale immediately.
  * It's okay if caller "misses" a page whose all-visible or all-frozen marking
@@ -1688,22 +2091,32 @@ heap_vac_scan_next_block(ReadStream *stream,
  * older XIDs/MXIDs.  The *skippedallvis flag will be set here when the choice
  * to skip such a range is actually made, making everything safe.)
  */
-static void
-find_next_unskippable_block(LVRelState *vacrel, bool *skipsallvis)
+static bool
+find_next_unskippable_block(LVRelState *vacrel, bool *skipsallvis,
+							BlockNumber start, BlockNumber end)
 {
 	BlockNumber rel_pages = vacrel->rel_pages;
-	BlockNumber next_unskippable_block = vacrel->next_unskippable_block + 1;
+	BlockNumber next_unskippable_block = start;
 	Buffer		next_unskippable_vmbuffer = vacrel->next_unskippable_vmbuffer;
 	bool		next_unskippable_eager_scanned = false;
 	bool		next_unskippable_allvis;
+	bool		found = true;
 
 	*skipsallvis = false;
 
 	for (;; next_unskippable_block++)
 	{
-		uint8		mapbits = visibilitymap_get_status(vacrel->rel,
-													   next_unskippable_block,
-													   &next_unskippable_vmbuffer);
+		uint8		mapbits;
+
+		/* Reach the end of range? */
+		if (next_unskippable_block >= end)
+		{
+			found = false;
+			break;
+		}
+
+		mapbits = visibilitymap_get_status(vacrel->rel, next_unskippable_block,
+										   &next_unskippable_vmbuffer);
 
 		next_unskippable_allvis = (mapbits & VISIBILITYMAP_ALL_VISIBLE) != 0;
 
@@ -1779,11 +2192,285 @@ find_next_unskippable_block(LVRelState *vacrel, bool *skipsallvis)
 		*skipsallvis = true;
 	}
 
-	/* write the local variables back to vacrel */
-	vacrel->next_unskippable_block = next_unskippable_block;
-	vacrel->next_unskippable_allvis = next_unskippable_allvis;
-	vacrel->next_unskippable_eager_scanned = next_unskippable_eager_scanned;
-	vacrel->next_unskippable_vmbuffer = next_unskippable_vmbuffer;
+	if (found)
+	{
+		/* write the local variables back to vacrel */
+		vacrel->next_unskippable_block = next_unskippable_block;
+		vacrel->next_unskippable_allvis = next_unskippable_allvis;
+		vacrel->next_unskippable_eager_scanned = next_unskippable_eager_scanned;
+		vacrel->next_unskippable_vmbuffer = next_unskippable_vmbuffer;
+	}
+	else
+	{
+		if (BufferIsValid(next_unskippable_vmbuffer))
+			ReleaseBuffer(next_unskippable_vmbuffer);
+
+		/*
+		 * There is not unskippable block in the specified range. Reset the
+		 * related fields in vacrel.
+		 */
+		vacrel->next_unskippable_block = InvalidBlockNumber;
+		vacrel->next_unskippable_allvis = InvalidBlockNumber;
+		vacrel->next_unskippable_eager_scanned = false;
+		vacrel->next_unskippable_vmbuffer = InvalidBuffer;
+	}
+
+	return found;
+}
+
+/*
+ * A parallel variant of do_lazy_scan_heap(). The leader process launches
+ * parallel workers to scan the heap in parallel.
+*/
+static void
+do_parallel_lazy_scan_heap(LVRelState *vacrel)
+{
+	ParallelLVScanWorkerData scanwork;
+
+	Assert(ParallelHeapVacuumIsActive(vacrel));
+	Assert(!IsParallelWorker());
+
+	/* Setup the parallel scan description for the leader to join as a worker */
+	parallel_lazy_scan_init_scan_worker(&scanwork,
+										vacrel->plvstate->shared->initial_chunk_size);
+	vacrel->plvstate->scanwork = &scanwork;
+
+	/* Adjust the eager scan's success counter as a worker */
+	vacrel->eager_scan_remaining_successes =
+		vacrel->plvstate->shared->eager_scan_remaining_successes_per_worker;
+
+	for (;;)
+	{
+		BlockNumber fsmvac_upto;
+
+		/* Launch parallel workers */
+		parallel_lazy_scan_heap_begin(vacrel);
+
+		/*
+		 * Do lazy heap scan until the read stream is exhausted. We will stop
+		 * retrieving new blocks for the read stream once the space of
+		 * dead_items TIDs exceeds the limit.
+		 */
+		do_lazy_scan_heap(vacrel, false);
+
+		/* Wait for parallel workers to finish and gather scan results */
+		parallel_lazy_scan_heap_end(vacrel);
+
+		if (!dead_items_check_memory_limit(vacrel))
+			break;
+
+		/* Perform a round of index and heap vacuuming */
+		vacrel->consider_bypass_optimization = false;
+		lazy_vacuum(vacrel);
+
+		/* Compute the smallest processed block number */
+		fsmvac_upto = parallel_lazy_scan_compute_min_scan_block(vacrel);
+
+		/*
+		 * Vacuum the Free Space Map to make newly-freed space visible on
+		 * upper-level FSM pages.
+		 */
+		if (fsmvac_upto > vacrel->next_fsm_block_to_vacuum)
+		{
+			FreeSpaceMapVacuumRange(vacrel->rel, vacrel->next_fsm_block_to_vacuum,
+									fsmvac_upto);
+			vacrel->next_fsm_block_to_vacuum = fsmvac_upto;
+		}
+
+		/* Report that we are once again scanning the heap */
+		pgstat_progress_update_param(PROGRESS_VACUUM_PHASE,
+									 PROGRESS_VACUUM_PHASE_SCAN_HEAP);
+	}
+
+	/*
+	 * The parallel heap scan finished, but it's possible that some workers
+	 * have allocated blocks but not processed them yet. This can happen for
+	 * example when workers exit because they are full of dead_items TIDs and
+	 * the leader process launched fewer workers in the next cycle.
+	 */
+	complete_unfinished_lazy_scan_heap(vacrel);
+}
+
+/*
+ * Return the smallest block number that the leader and workers have scanned.
+ */
+static BlockNumber
+parallel_lazy_scan_compute_min_scan_block(LVRelState *vacrel)
+{
+	BlockNumber min_blk;
+
+	Assert(ParallelHeapVacuumIsActive(vacrel));
+
+	/* Initialized with the leader's value */
+	min_blk = vacrel->last_blkno;
+
+	for (int i = 0; i < vacrel->leader->nworkers_launched; i++)
+	{
+		ParallelLVScanWorkerData *scanwork = &(vacrel->leader->scanwork_array[i]);
+		BlockNumber blkno;
+
+		/* Skip if no worker has been initialized the scan state */
+		if (!scanwork->inited)
+			continue;
+
+		blkno = pg_atomic_read_u32(&(scanwork->last_blkno));
+
+		if (!BlockNumberIsValid(min_blk) || min_blk > blkno)
+			min_blk = blkno;
+	}
+
+	Assert(BlockNumberIsValid(min_blk));
+
+	return min_blk;
+}
+
+/*
+ * Complete parallel heaps scans that have remaining blocks in their
+ * chunks.
+ */
+static void
+complete_unfinished_lazy_scan_heap(LVRelState *vacrel)
+{
+	int			nworkers;
+
+	Assert(!IsParallelWorker());
+
+	nworkers = parallel_vacuum_get_nworkers_table(vacrel->pvs);
+
+	for (int i = 0; i < nworkers; i++)
+	{
+		ParallelLVScanWorkerData *scanwork = &(vacrel->leader->scanwork_array[i]);
+
+		if (!scanwork->inited)
+			continue;
+
+		if (scanwork->chunk_remaining == 0)
+			continue;
+
+		/* Attach the worker's scan state */
+		vacrel->plvstate->scanwork = scanwork;
+
+		vacrel->next_fsm_block_to_vacuum = pg_atomic_read_u32(&(scanwork->last_blkno));
+		vacrel->next_eager_scan_region_start = scanwork->next_region_start_save;
+		vacrel->eager_scan_remaining_fails = scanwork->remaining_fails_save;
+
+		/*
+		 * Complete the unfinished scan. Note that we might perform multiple
+		 * cycles of index and heap vacuuming while completing the scan.
+		 */
+		do_lazy_scan_heap(vacrel, true);
+	}
+
+	/*
+	 * We don't need to gather the scan results here because the leader's scan
+	 * state got updated directly.
+	 */
+}
+
+/*
+ * Helper routine to launch parallel workers for parallel lazy heap scan.
+ */
+static void
+parallel_lazy_scan_heap_begin(LVRelState *vacrel)
+{
+	Assert(ParallelHeapVacuumIsActive(vacrel));
+	Assert(!IsParallelWorker());
+
+	/* launcher workers */
+	vacrel->leader->nworkers_launched = parallel_vacuum_collect_dead_items_begin(vacrel->pvs);
+
+	ereport(vacrel->verbose ? INFO : DEBUG2,
+			(errmsg(ngettext("launched %d parallel vacuum worker for collecting dead tuples (planned: %d)",
+							 "launched %d parallel vacuum workers for collecting dead tuples (planned: %d)",
+							 vacrel->leader->nworkers_launched),
+					vacrel->leader->nworkers_launched,
+					parallel_vacuum_get_nworkers_table(vacrel->pvs))));
+}
+
+/*
+ * Helper routine to finish the parallel lazy heap scan.
+ */
+static void
+parallel_lazy_scan_heap_end(LVRelState *vacrel)
+{
+	/* Wait for all parallel workers to finish */
+	parallel_vacuum_collect_dead_items_end(vacrel->pvs);
+
+	/* Gather the workers' scan results */
+	parallel_lazy_scan_gather_results(vacrel);
+}
+
+/*
+ * Accumulate each worker's scan results into the leader's.
+*/
+static void
+parallel_lazy_scan_gather_results(LVRelState *vacrel)
+{
+	Assert(ParallelHeapVacuumIsActive(vacrel));
+	Assert(!IsParallelWorker());
+
+	/* Gather the workers' scan results */
+	for (int i = 0; i < vacrel->leader->nworkers_launched; i++)
+	{
+		LVScanData *data = &(vacrel->leader->scandata_array[i]);
+		ParallelLVScanWorkerData *scanwork = &(vacrel->leader->scanwork_array[i]);
+
+		/* Accumulate the counters collected by workers */
+#define ACCUM_COUNT(item) vacrel->scan_data->item += data->item
+		ACCUM_COUNT(scanned_pages);
+		ACCUM_COUNT(removed_pages);
+		ACCUM_COUNT(new_frozen_tuple_pages);
+		ACCUM_COUNT(vm_new_visible_pages);
+		ACCUM_COUNT(vm_new_visible_frozen_pages);
+		ACCUM_COUNT(vm_new_frozen_pages);
+		ACCUM_COUNT(lpdead_item_pages);
+		ACCUM_COUNT(missed_dead_pages);
+		ACCUM_COUNT(tuples_deleted);
+		ACCUM_COUNT(tuples_frozen);
+		ACCUM_COUNT(lpdead_items);
+		ACCUM_COUNT(live_tuples);
+		ACCUM_COUNT(recently_dead_tuples);
+		ACCUM_COUNT(missed_dead_tuples);
+#undef ACCUM_COUNT
+
+		/*
+		 * Track the greatest non-empty page among values the workers
+		 * collected as it's used to cut-off point of heap truncation.
+		 */
+		if (vacrel->scan_data->nonempty_pages < data->nonempty_pages)
+			vacrel->scan_data->nonempty_pages = data->nonempty_pages;
+
+		/*
+		 * All workers must have initialized both values with the values
+		 * passed by the leader.
+		 */
+		Assert(TransactionIdIsValid(data->NewRelfrozenXid));
+		Assert(MultiXactIdIsValid(data->NewRelminMxid));
+
+		/*
+		 * During parallel lazy scanning, since different workers process
+		 * separate blocks, they may observe different existing XIDs and
+		 * MXIDs. Therefore, we compute the oldest XID and MXID from the
+		 * values observed by each worker (including the leader). These
+		 * computations are crucial for correctly advancing both relfrozenxid
+		 * and relmminmxid values.
+		 */
+
+		if (TransactionIdPrecedes(data->NewRelfrozenXid, vacrel->scan_data->NewRelfrozenXid))
+			vacrel->scan_data->NewRelfrozenXid = data->NewRelfrozenXid;
+
+		if (MultiXactIdPrecedesOrEquals(data->NewRelminMxid, vacrel->scan_data->NewRelminMxid))
+			vacrel->scan_data->NewRelminMxid = data->NewRelminMxid;
+
+		/* Has any one of workers skipped all-visible page? */
+		vacrel->scan_data->skippedallvis |= data->skippedallvis;
+
+		/*
+		 * Gather the remaining success count so that we can distribute the
+		 * success counter again in the next parallel lazy scan.
+		 */
+		vacrel->eager_scan_remaining_successes += scanwork->remaining_successes_save;
+	}
 }
 
 /*
@@ -2072,7 +2759,8 @@ lazy_scan_prune(LVRelState *vacrel,
 
 	/* Can't truncate this page */
 	if (presult.hastup)
-		vacrel->scan_data->nonempty_pages = blkno + 1;
+		vacrel->scan_data->nonempty_pages =
+			Max(blkno + 1, vacrel->scan_data->nonempty_pages);
 
 	/* Did we find LP_DEAD items? */
 	*has_lpdead_items = (presult.lpdead_items > 0);
@@ -2445,7 +3133,8 @@ lazy_scan_noprune(LVRelState *vacrel,
 
 	/* Can't truncate this page */
 	if (hastup)
-		vacrel->scan_data->nonempty_pages = blkno + 1;
+		vacrel->scan_data->nonempty_pages =
+			Max(blkno + 1, vacrel->scan_data->nonempty_pages);
 
 	/* Did we find LP_DEAD items? */
 	*has_lpdead_items = (lpdead_items > 0);
@@ -3509,12 +4198,8 @@ dead_items_alloc(LVRelState *vacrel, int nworkers)
 		autovacuum_work_mem != -1 ?
 		autovacuum_work_mem : maintenance_work_mem;
 
-	/*
-	 * Initialize state for a parallel vacuum.  As of now, only one worker can
-	 * be used for an index, so we invoke parallelism only if there are at
-	 * least two indexes on a table.
-	 */
-	if (nworkers >= 0 && vacrel->nindexes > 1 && vacrel->do_index_vacuuming)
+	/* Initialize state for a parallel vacuum */
+	if (nworkers >= 0)
 	{
 		/*
 		 * Since parallel workers cannot access data in temporary tables, we
@@ -3532,11 +4217,17 @@ dead_items_alloc(LVRelState *vacrel, int nworkers)
 								vacrel->relname)));
 		}
 		else
+		{
+			/*
+			 * We initialize the parallel vacuum state for either lazy heap
+			 * scan, index vacuuming, or both.
+			 */
 			vacrel->pvs = parallel_vacuum_init(vacrel->rel, vacrel->indrels,
 											   vacrel->nindexes, nworkers,
 											   vac_work_mem,
 											   vacrel->verbose ? INFO : DEBUG2,
 											   vacrel->bstrategy, (void *) vacrel);
+		}
 
 		/*
 		 * If parallel mode started, dead_items and dead_items_info spaces are
@@ -3576,15 +4267,35 @@ dead_items_add(LVRelState *vacrel, BlockNumber blkno, OffsetNumber *offsets,
 	};
 	int64		prog_val[2];
 
+	if (ParallelHeapVacuumIsActive(vacrel))
+		TidStoreLockExclusive(vacrel->dead_items);
+
 	TidStoreSetBlockOffsets(vacrel->dead_items, blkno, offsets, num_offsets);
 	vacrel->dead_items_info->num_items += num_offsets;
 
+	if (ParallelHeapVacuumIsActive(vacrel))
+		TidStoreUnlock(vacrel->dead_items);
+
 	/* update the progress information */
 	prog_val[0] = vacrel->dead_items_info->num_items;
 	prog_val[1] = TidStoreMemoryUsage(vacrel->dead_items);
 	pgstat_progress_update_multi_param(2, prog_index, prog_val);
 }
 
+/*
+ * Check the memory usage of the collected dead items and return true
+ * if we are close to overrunning the available space for dead_items TIDs.
+ * However, let's force at least one page-worth of tuples to be stored as
+ * to ensure we do at least some work when the memory configured is so low
+ * that we run out before storing anything.
+ */
+static bool
+dead_items_check_memory_limit(LVRelState *vacrel)
+{
+	return vacrel->dead_items_info->num_items > 0 &&
+		TidStoreMemoryUsage(vacrel->dead_items) > vacrel->dead_items_info->max_bytes;
+}
+
 /*
  * Forget all collected dead items.
  */
@@ -3778,6 +4489,295 @@ update_relstats_all_indexes(LVRelState *vacrel)
 	}
 }
 
+/*
+ * Compute the number of workers for parallel heap vacuum.
+ */
+int
+heap_parallel_vacuum_compute_workers(Relation rel, int nworkers_requested,
+									 void *state)
+{
+	BlockNumber relpages = RelationGetNumberOfBlocks(rel);
+	int			parallel_workers = 0;
+
+	/*
+	 * Parallel heap vacuuming a small relation shouldn't take long. We use
+	 * two times the chunk size as the size cutoff because the leader is
+	 * assigned to one chunk.
+	 */
+	if (relpages < PARALLEL_LV_CHUNK_SIZE * 2 || relpages < min_parallel_table_scan_size)
+		return 0;
+
+	if (nworkers_requested == 0)
+	{
+		LVRelState *vacrel = (LVRelState *) state;
+		int			heap_parallel_threshold;
+		int			heap_pages;
+		BlockNumber allvisible;
+		BlockNumber allfrozen;
+
+		/*
+		 * Estimate the number of blocks that we're going to scan during
+		 * lazy_scan_heap().
+		 */
+		visibilitymap_count(rel, &allvisible, &allfrozen);
+		heap_pages = relpages - (vacrel->aggressive ? allfrozen : allvisible);
+
+		Assert(heap_pages >= 0);
+
+		/*
+		 * Select the number of workers based on the log of the number of
+		 * pages to scan. Note that the upper limit of the
+		 * min_parallel_table_scan_size GUC is chosen to prevent overflow
+		 * here.
+		 */
+		heap_parallel_threshold = PARALLEL_LV_CHUNK_SIZE;
+		while (heap_pages >= (BlockNumber) (heap_parallel_threshold * 3))
+		{
+			parallel_workers++;
+			heap_parallel_threshold *= 3;
+			if (heap_parallel_threshold > INT_MAX / 3)
+				break;
+		}
+	}
+	else
+		parallel_workers = nworkers_requested;
+
+	return parallel_workers;
+}
+
+/*
+ * Estimate shared memory size required for parallel heap vacuum.
+ */
+void
+heap_parallel_vacuum_estimate(Relation rel, ParallelContext *pcxt, int nworkers,
+							  void *state)
+{
+	LVRelState *vacrel = (LVRelState *) state;
+	Size		size = 0;
+
+	vacrel->leader = palloc(sizeof(ParallelLVLeader));
+
+	/* Estimate space for ParallelLVShared */
+	size = add_size(size, sizeof(ParallelLVShared));
+	vacrel->leader->shared_len = size;
+	shm_toc_estimate_chunk(&pcxt->estimator, vacrel->leader->shared_len);
+	shm_toc_estimate_keys(&pcxt->estimator, 1);
+
+	/* Estimate space for ParallelLVScanDesc */
+	vacrel->leader->scandesc_len = sizeof(ParallelLVScanDesc);
+	shm_toc_estimate_chunk(&pcxt->estimator, vacrel->leader->scandesc_len);
+	shm_toc_estimate_keys(&pcxt->estimator, 1);
+
+	/* Estimate space for an array of ParallelLVScanWorkerData */
+	vacrel->leader->scanwork_len = mul_size(sizeof(ParallelLVScanWorkerData),
+											nworkers);
+	shm_toc_estimate_chunk(&pcxt->estimator, vacrel->leader->scanwork_len);
+	shm_toc_estimate_keys(&pcxt->estimator, 1);
+
+	/* Estimate space for an array of LVScanData */
+	vacrel->leader->scandata_len = mul_size(sizeof(LVScanData), nworkers);
+	shm_toc_estimate_chunk(&pcxt->estimator, vacrel->leader->scandata_len);
+	shm_toc_estimate_keys(&pcxt->estimator, 1);
+}
+
+/*
+ * Set up shared memory for parallel heap vacuum.
+ */
+void
+heap_parallel_vacuum_initialize(Relation rel, ParallelContext *pcxt, int nworkers,
+								void *state)
+{
+	LVRelState *vacrel = (LVRelState *) state;
+	ParallelLVShared *shared;
+	ParallelLVScanDesc *scandesc;
+	ParallelLVScanWorkerData *scanwork;
+	LVScanData *scandata;
+
+	vacrel->plvstate = palloc0(sizeof(ParallelLVState));
+
+	/* Initialize ParallelLVShared */
+
+	shared = shm_toc_allocate(pcxt->toc, vacrel->leader->shared_len);
+	MemSet(shared, 0, vacrel->leader->shared_len);
+	shared->aggressive = vacrel->aggressive;
+	shared->skipwithvm = vacrel->skipwithvm;
+	shared->cutoffs = vacrel->cutoffs;
+	shared->NewRelfrozenXid = vacrel->scan_data->NewRelfrozenXid;
+	shared->NewRelminMxid = vacrel->scan_data->NewRelminMxid;
+	shared->initial_chunk_size = BlockNumberIsValid(vacrel->next_eager_scan_region_start)
+		? vacrel->next_eager_scan_region_start
+		: PARALLEL_LV_CHUNK_SIZE;
+
+	/* Calculate the per-chunk maximum failure count */
+	shared->eager_scan_max_fails_per_chunk =
+		(BlockNumber) (vacrel->eager_scan_max_fails_per_region *
+					   ((float) PARALLEL_LV_CHUNK_SIZE / EAGER_SCAN_REGION_SIZE));
+
+	/* including the leader too */
+	shared->eager_scan_remaining_successes_per_worker =
+		vacrel->eager_scan_remaining_successes / (nworkers + 1);
+
+	shm_toc_insert(pcxt->toc, PARALLEL_LV_KEY_SHARED, shared);
+	vacrel->plvstate->shared = shared;
+
+	/* Initialize ParallelLVScanDesc */
+	scandesc = shm_toc_allocate(pcxt->toc, vacrel->leader->scandesc_len);
+	scandesc->nblocks = RelationGetNumberOfBlocks(rel);
+	pg_atomic_init_u64(&scandesc->nallocated, 0);
+	shm_toc_insert(pcxt->toc, PARALLEL_LV_KEY_SCANDESC, scandesc);
+	vacrel->plvstate->scandesc = scandesc;
+
+	/* Initialize the array of ParallelLVScanWorkerData */
+	scanwork = shm_toc_allocate(pcxt->toc, vacrel->leader->scanwork_len);
+	MemSet(scanwork, 0, vacrel->leader->scanwork_len);
+	shm_toc_insert(pcxt->toc, PARALLEL_LV_KEY_SCANWORKER, scanwork);
+	vacrel->leader->scanwork_array = scanwork;
+
+	/* Initialize the array of LVScanData */
+	scandata = shm_toc_allocate(pcxt->toc, vacrel->leader->scandata_len);
+	shm_toc_insert(pcxt->toc, PARALLEL_LV_KEY_SCANDATA, scandata);
+	vacrel->leader->scandata_array = scandata;
+}
+
+/*
+ * Initialize lazy vacuum state with the information retrieved from
+ * shared memory.
+ */
+void
+heap_parallel_vacuum_initialize_worker(Relation rel, ParallelVacuumState *pvs,
+									   ParallelWorkerContext *pwcxt,
+									   void **state_out)
+{
+	LVRelState *vacrel;
+	ParallelLVState *plvstate;
+	ParallelLVShared *shared;
+	ParallelLVScanDesc *scandesc;
+	ParallelLVScanWorkerData *scanwork_array;
+	LVScanData *scandata_array;
+
+	/* Initialize ParallelLVState and prepare the related objects */
+
+	plvstate = palloc0(sizeof(ParallelLVState));
+
+	/* Prepare ParallelLVShared */
+	shared = (ParallelLVShared *) shm_toc_lookup(pwcxt->toc, PARALLEL_LV_KEY_SHARED, false);
+	plvstate->shared = shared;
+
+	/* Prepare ParallelLVScanDesc */
+	scandesc = shm_toc_lookup(pwcxt->toc, PARALLEL_LV_KEY_SCANDESC, false);
+	plvstate->scandesc = scandesc;
+
+	/* Prepare ParallelLVScanWorkerData */
+	scanwork_array = shm_toc_lookup(pwcxt->toc, PARALLEL_LV_KEY_SCANWORKER, false);
+	plvstate->scanwork = &(scanwork_array[ParallelWorkerNumber]);
+
+	/* Initialize LVRelState and prepare fields required by lazy scan heap */
+	vacrel = palloc0(sizeof(LVRelState));
+	vacrel->rel = rel;
+	vacrel->indrels = parallel_vacuum_get_table_indexes(pvs,
+														&vacrel->nindexes);
+	vacrel->bstrategy = parallel_vacuum_get_bstrategy(pvs);
+	vacrel->pvs = pvs;
+	vacrel->aggressive = shared->aggressive;
+	vacrel->skipwithvm = shared->skipwithvm;
+	vacrel->vistest = GlobalVisTestFor(rel);
+	vacrel->cutoffs = shared->cutoffs;
+	vacrel->dead_items = parallel_vacuum_get_dead_items(pvs,
+														&vacrel->dead_items_info);
+	vacrel->rel_pages = RelationGetNumberOfBlocks(rel);
+
+	/*
+	 * Set the per-region failure counter and per-worker success counter,
+	 * which are not changed during parallel heap vacuum.
+	 */
+	vacrel->eager_scan_max_fails_per_region =
+		plvstate->shared->eager_scan_max_fails_per_chunk;
+	vacrel->eager_scan_remaining_successes =
+		plvstate->shared->eager_scan_remaining_successes_per_worker;
+
+	/* Does this worker have un-scanned blocks in a chunk? */
+	if (plvstate->scanwork->chunk_remaining > 0)
+	{
+		/*
+		 * We restore the previous eager scan state of the already allocated
+		 * chunk, if the worker's previous scan suspended due to the full of
+		 * dead_items TIDs space.
+		 */
+		vacrel->next_eager_scan_region_start = plvstate->scanwork->next_region_start_save;
+		vacrel->eager_scan_remaining_fails = plvstate->scanwork->remaining_fails_save;
+	}
+	else
+	{
+		/*
+		 * next_eager_scan_region_start will be set when the first chunk is
+		 * assigned
+		 */
+		vacrel->next_eager_scan_region_start = InvalidBlockNumber;
+		vacrel->eager_scan_remaining_fails = vacrel->eager_scan_max_fails_per_region;
+	}
+
+	vacrel->plvstate = plvstate;
+
+	/* Prepare LVScanData */
+	scandata_array = shm_toc_lookup(pwcxt->toc, PARALLEL_LV_KEY_SCANDATA, false);
+	vacrel->scan_data = &(scandata_array[ParallelWorkerNumber]);
+	MemSet(vacrel->scan_data, 0, sizeof(LVScanData));
+	vacrel->scan_data->NewRelfrozenXid = shared->NewRelfrozenXid;
+	vacrel->scan_data->NewRelminMxid = shared->NewRelminMxid;
+	vacrel->scan_data->skippedallvis = false;
+
+	/*
+	 * Initialize the scan state if not yet. The chunk of blocks will be
+	 * allocated when to get the scan block for the first time.
+	 */
+	if (!vacrel->plvstate->scanwork->inited)
+		parallel_lazy_scan_init_scan_worker(vacrel->plvstate->scanwork,
+											vacrel->plvstate->shared->initial_chunk_size);
+
+	*state_out = (void *) vacrel;
+}
+
+/*
+ * Parallel heap vacuum callback for collecting dead items (i.e., lazy heap scan).
+ */
+void
+heap_parallel_vacuum_collect_dead_items(Relation rel, ParallelVacuumState *pvs,
+										void *state)
+{
+	LVRelState *vacrel = (LVRelState *) state;
+	ErrorContextCallback errcallback;
+
+	Assert(ParallelHeapVacuumIsActive(vacrel));
+
+	/*
+	 * Setup error traceback support for ereport() for parallel table vacuum
+	 * workers
+	 */
+	vacrel->dbname = get_database_name(MyDatabaseId);
+	vacrel->relnamespace = get_database_name(RelationGetNamespace(rel));
+	vacrel->relname = pstrdup(RelationGetRelationName(rel));
+	vacrel->indname = NULL;
+	vacrel->phase = VACUUM_ERRCB_PHASE_SCAN_HEAP;
+	errcallback.callback = vacuum_error_callback;
+	errcallback.arg = &vacrel;
+	errcallback.previous = error_context_stack;
+	error_context_stack = &errcallback;
+
+	/* Join the parallel heap vacuum */
+	do_lazy_scan_heap(vacrel, false);
+
+	/* Advertise the last processed block number */
+	pg_atomic_write_u32(&(vacrel->plvstate->scanwork->last_blkno), vacrel->last_blkno);
+
+	/* Save the eager scan state */
+	vacrel->plvstate->scanwork->remaining_fails_save = vacrel->eager_scan_remaining_fails;
+	vacrel->plvstate->scanwork->remaining_successes_save = vacrel->eager_scan_remaining_successes;
+	vacrel->plvstate->scanwork->next_region_start_save = vacrel->next_eager_scan_region_start;
+
+	/* Pop the error context stack */
+	error_context_stack = errcallback.previous;
+}
+
 /*
  * Error context callback for errors occurring during vacuum.  The error
  * context messages for index phases should match the messages set in parallel
diff --git a/src/backend/commands/vacuumparallel.c b/src/backend/commands/vacuumparallel.c
index 3726fb41028..49e43b95132 100644
--- a/src/backend/commands/vacuumparallel.c
+++ b/src/backend/commands/vacuumparallel.c
@@ -504,6 +504,35 @@ parallel_vacuum_end(ParallelVacuumState *pvs, IndexBulkDeleteResult **istats)
 	pfree(pvs);
 }
 
+/*
+ * Return the number of parallel workers initialized for parallel table vacuum.
+ */
+int
+parallel_vacuum_get_nworkers_table(ParallelVacuumState *pvs)
+{
+	return pvs->nworkers_for_table;
+}
+
+/*
+ * Return the array of indexes associated to the given table to be vacuumed.
+ */
+Relation *
+parallel_vacuum_get_table_indexes(ParallelVacuumState *pvs, int *nindexes)
+{
+	*nindexes = pvs->nindexes;
+
+	return pvs->indrels;
+}
+
+/*
+ * Return the buffer strategy for parallel vacuum.
+ */
+BufferAccessStrategy
+parallel_vacuum_get_bstrategy(ParallelVacuumState *pvs)
+{
+	return pvs->bstrategy;
+}
+
 /*
  * Returns the dead items space and dead items information.
  */
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index e48fe434cd3..724cab73698 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -15,6 +15,7 @@
 #define HEAPAM_H
 
 #include "access/heapam_xlog.h"
+#include "access/parallel.h"
 #include "access/relation.h"	/* for backward compatibility */
 #include "access/relscan.h"
 #include "access/sdir.h"
@@ -397,8 +398,20 @@ extern void log_heap_prune_and_freeze(Relation relation, Buffer buffer,
 
 /* in heap/vacuumlazy.c */
 struct VacuumParams;
+struct ParallelVacuumState;
 extern void heap_vacuum_rel(Relation rel,
 							struct VacuumParams *params, BufferAccessStrategy bstrategy);
+extern int heap_parallel_vacuum_compute_workers(Relation rel, int nworkers_requested,
+												void *state);
+extern void heap_parallel_vacuum_estimate(Relation rel, ParallelContext *pcxt, int nworkers,
+										  void *state);
+extern void heap_parallel_vacuum_initialize(Relation rel, ParallelContext *pcxt,
+											int nworkers, void *state);
+extern void heap_parallel_vacuum_initialize_worker(Relation rel, struct ParallelVacuumState *pvs,
+												   ParallelWorkerContext *pwcxt,
+												   void **state_out);
+extern void heap_parallel_vacuum_collect_dead_items(Relation rel, struct ParallelVacuumState *pvs,
+													void *state);
 
 /* in heap/heapam_visibility.c */
 extern bool HeapTupleSatisfiesVisibility(HeapTuple htup, Snapshot snapshot,
diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h
index e785a4a583f..849cb4dcc74 100644
--- a/src/include/commands/vacuum.h
+++ b/src/include/commands/vacuum.h
@@ -385,6 +385,9 @@ extern ParallelVacuumState *parallel_vacuum_init(Relation rel, Relation *indrels
 												 BufferAccessStrategy bstrategy,
 												 void *state);
 extern void parallel_vacuum_end(ParallelVacuumState *pvs, IndexBulkDeleteResult **istats);
+extern int	parallel_vacuum_get_nworkers_table(ParallelVacuumState *pvs);
+extern Relation *parallel_vacuum_get_table_indexes(ParallelVacuumState *pvs, int *nindexes);
+extern BufferAccessStrategy parallel_vacuum_get_bstrategy(ParallelVacuumState *pvs);
 extern TidStore *parallel_vacuum_get_dead_items(ParallelVacuumState *pvs,
 												VacDeadItemsInfo **dead_items_info_p);
 extern void parallel_vacuum_reset_dead_items(ParallelVacuumState *pvs);
diff --git a/src/test/regress/expected/vacuum_parallel.out b/src/test/regress/expected/vacuum_parallel.out
index ddf0ee544b7..b793d8093c2 100644
--- a/src/test/regress/expected/vacuum_parallel.out
+++ b/src/test/regress/expected/vacuum_parallel.out
@@ -1,5 +1,6 @@
 SET max_parallel_maintenance_workers TO 4;
 SET min_parallel_index_scan_size TO '128kB';
+SET min_parallel_table_scan_size TO '128kB';
 -- Bug #17245: Make sure that we don't totally fail to VACUUM individual indexes that
 -- happen to be below min_parallel_index_scan_size during parallel VACUUM:
 CREATE TABLE parallel_vacuum_table (a int) WITH (autovacuum_enabled = off);
@@ -43,7 +44,13 @@ VACUUM (PARALLEL 4, INDEX_CLEANUP ON) parallel_vacuum_table;
 -- Since vacuum_in_leader_small_index uses deduplication, we expect an
 -- assertion failure with bug #17245 (in the absence of bugfix):
 INSERT INTO parallel_vacuum_table SELECT i FROM generate_series(1, 10000) i;
+-- Insert more tuples to use parallel heap vacuum.
+INSERT INTO parallel_vacuum_table SELECT i FROM generate_series(1, 500_000) i;
+VACUUM (PARALLEL 2) parallel_vacuum_table;
+DELETE FROM parallel_vacuum_table WHERE a < 1000;
+VACUUM (PARALLEL 1) parallel_vacuum_table;
 RESET max_parallel_maintenance_workers;
 RESET min_parallel_index_scan_size;
+RESET min_parallel_table_scan_size;
 -- Deliberately don't drop table, to get further coverage from tools like
 -- pg_amcheck in some testing scenarios
diff --git a/src/test/regress/sql/vacuum_parallel.sql b/src/test/regress/sql/vacuum_parallel.sql
index 1d23f33e39c..5381023642f 100644
--- a/src/test/regress/sql/vacuum_parallel.sql
+++ b/src/test/regress/sql/vacuum_parallel.sql
@@ -1,5 +1,6 @@
 SET max_parallel_maintenance_workers TO 4;
 SET min_parallel_index_scan_size TO '128kB';
+SET min_parallel_table_scan_size TO '128kB';
 
 -- Bug #17245: Make sure that we don't totally fail to VACUUM individual indexes that
 -- happen to be below min_parallel_index_scan_size during parallel VACUUM:
@@ -39,8 +40,15 @@ VACUUM (PARALLEL 4, INDEX_CLEANUP ON) parallel_vacuum_table;
 -- assertion failure with bug #17245 (in the absence of bugfix):
 INSERT INTO parallel_vacuum_table SELECT i FROM generate_series(1, 10000) i;
 
+-- Insert more tuples to use parallel heap vacuum.
+INSERT INTO parallel_vacuum_table SELECT i FROM generate_series(1, 500_000) i;
+VACUUM (PARALLEL 2) parallel_vacuum_table;
+DELETE FROM parallel_vacuum_table WHERE a < 1000;
+VACUUM (PARALLEL 1) parallel_vacuum_table;
+
 RESET max_parallel_maintenance_workers;
 RESET min_parallel_index_scan_size;
+RESET min_parallel_table_scan_size;
 
 -- Deliberately don't drop table, to get further coverage from tools like
 -- pg_amcheck in some testing scenarios
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 931951aa44d..eda476f0cdf 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1956,6 +1956,11 @@ PLpgSQL_type
 PLpgSQL_type_type
 PLpgSQL_var
 PLpgSQL_variable
+ParallelLVLeader
+ParallelLVScanDesc
+ParallelLVScanWorkerData
+ParallelLVShared
+ParallelLVState
 PLwdatum
 PLword
 PLyArrayToOb
-- 
2.43.5

