From d38013b4abe14b69f4058337cd7231ab1150e12f Mon Sep 17 00:00:00 2001
From: Daniil Davidov <d.davydov@postgrespro.ru>
Date: Fri, 27 Feb 2026 16:15:34 +0700
Subject: [PATCH 3/3] fixes for 0004 patch

---
 src/backend/access/heap/vacuumlazy.c          |  2 +
 src/backend/commands/vacuumparallel.c         | 38 ++++++++-----------
 .../modules/test_autovacuum/t/001_basic.pl    | 21 ++--------
 3 files changed, 22 insertions(+), 39 deletions(-)

diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index 2498edcc0d5..6407c10524b 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -870,11 +870,13 @@ heap_vacuum_rel(Relation rel, const VacuumParams params,
 	lazy_check_wraparound_failsafe(vacrel);
 	dead_items_alloc(vacrel, params.nworkers);
 
+#ifdef USE_INJECTION_POINTS
 	/*
 	 * Trigger injection point, if parallel autovacuum is about to be started.
 	 */
 	if (AmAutoVacuumWorkerProcess() && ParallelVacuumIsActive(vacrel))
 		INJECTION_POINT("autovacuum-start-parallel-vacuum", NULL);
+#endif
 
 	/*
 	 * Call lazy_scan_heap to perform all required heap pruning, index
diff --git a/src/backend/commands/vacuumparallel.c b/src/backend/commands/vacuumparallel.c
index 88842c5cec9..78ccfede031 100644
--- a/src/backend/commands/vacuumparallel.c
+++ b/src/backend/commands/vacuumparallel.c
@@ -308,7 +308,7 @@ static bool parallel_vacuum_index_is_parallel_safe(Relation indrel, int num_inde
 static void parallel_vacuum_error_callback(void *arg);
 
 #ifdef USE_INJECTION_POINTS
-static void parallel_vacuum_report_cost_based_params(void);
+static inline void parallel_vacuum_report_cost_based_params(void);
 #endif
 
 /*
@@ -923,6 +923,7 @@ parallel_vacuum_process_all_indexes(ParallelVacuumState *pvs, int num_index_scan
 							pvs->pcxt->nworkers_launched, nworkers)));
 	}
 
+#ifdef USE_INJECTION_POINTS
 	/*
 	 * To be able to exercise whether all reserved parallel workers are being
 	 * released anyway, allow injection points to trigger a failure at this
@@ -933,6 +934,7 @@ parallel_vacuum_process_all_indexes(ParallelVacuumState *pvs, int num_index_scan
 	 */
 	if (nworkers > 0)
 		INJECTION_POINT("autovacuum-leader-before-indexes-processing", NULL);
+#endif
 
 	/* Vacuum the indexes that can be processed by only leader process */
 	parallel_vacuum_process_unsafe_indexes(pvs);
@@ -1317,7 +1319,7 @@ parallel_vacuum_main(dsm_segment *seg, shm_toc *toc)
 	 * during index processing (via vacuum_delay_point call). This logging
 	 * allows tests to ensure this.
 	 */
-	if (shared->am_parallel_autovacuum)
+	if (shared->is_autovacuum)
 		parallel_vacuum_report_cost_based_params();
 #endif
 
@@ -1376,29 +1378,21 @@ parallel_vacuum_error_callback(void *arg)
 
 #ifdef USE_INJECTION_POINTS
 /*
- * Log values of the related to cost-based delay parameters. It is used for
+ * Log values related to cost-based vacuum delay parameters. It is used for
  * testing purpose.
  */
-static void
+static inline void
 parallel_vacuum_report_cost_based_params(void)
 {
-	StringInfoData buf;
-
-	/* Simulate config reload during normal processing */
-	pg_atomic_add_fetch_u32(VacuumActiveNWorkers, 1);
-	vacuum_delay_point(false);
-	pg_atomic_sub_fetch_u32(VacuumActiveNWorkers, 1);
-
-	initStringInfo(&buf);
-
-	appendStringInfo(&buf, "Vacuum cost-based delay parameters of parallel worker:\n");
-	appendStringInfo(&buf, "vacuum_cost_limit = %d\n",vacuum_cost_limit);
-	appendStringInfo(&buf, "vacuum_cost_delay = %g\n", vacuum_cost_delay);
-	appendStringInfo(&buf, "vacuum_cost_page_miss = %d\n", VacuumCostPageMiss);
-	appendStringInfo(&buf, "vacuum_cost_page_dirty = %d\n", VacuumCostPageDirty);
-	appendStringInfo(&buf, "vacuum_cost_page_hit = %d\n", VacuumCostPageHit);
-
-	ereport(DEBUG2, errmsg("%s", buf.data));
-	pfree(buf.data);
+	const char *msg_format =
+		_("Parallel autovacuum worker cost params: cost_limit=%d, cost_delay=%g, cost_page_miss=%d, cost_page_dirty=%d, cost_page_hit=%d");
+
+	elog(DEBUG2,
+		 msg_format,
+		 vacuum_cost_limit,
+		 vacuum_cost_delay,
+		 VacuumCostPageMiss,
+		 VacuumCostPageDirty,
+		 VacuumCostPageHit);
 }
 #endif
diff --git a/src/test/modules/test_autovacuum/t/001_basic.pl b/src/test/modules/test_autovacuum/t/001_basic.pl
index b3d22361dcf..9b80d371f5c 100644
--- a/src/test/modules/test_autovacuum/t/001_basic.pl
+++ b/src/test/modules/test_autovacuum/t/001_basic.pl
@@ -109,8 +109,7 @@ $node->safe_psql('postgres', qq{
 # Wait until the parallel autovacuum on table is completed. At the same time,
 # we check that the required number of parallel workers has been started.
 $log_start = $node->wait_for_log(
-	qr/parallel index vacuum: 2 workers were planned, / .
-	qr/2 workers were reserved and 2 workers were launched in total/,
+	qr/parallel workers: index vacuum: 2 planned, 2 reserved, 2 launched/,
 	$log_start
 );
 
@@ -162,12 +161,8 @@ $node->wait_for_event(
 # Check whether parallel worker successfully updated all parameters during
 # index processing
 $log_start = $node->wait_for_log(
-	qr/Vacuum cost-based delay parameters of parallel worker:\n/ .
-	qr/\tvacuum_cost_limit = 500\n/ .
-	qr/\tvacuum_cost_delay = 2\n/ .
-	qr/\tvacuum_cost_page_miss = 10\n/ .
-	qr/\tvacuum_cost_page_dirty = 10\n/ .
-	qr/\tvacuum_cost_page_hit = 10\n/,
+	qr/Parallel autovacuum worker cost params: cost_limit=500, cost_delay=2, / .
+	qr/cost_page_miss=10, cost_page_dirty=10, cost_page_hit=10/,
 	$log_start
 );
 
@@ -219,8 +214,7 @@ $node->safe_psql('postgres', qq{
 
 # Wait until the end of parallel processing
 $log_start = $node->wait_for_log(
-	qr/parallel index vacuum: 2 workers were planned, / .
-	qr/2 workers were reserved and 2 workers were launched in total/,
+	qr/parallel workers: index vacuum: 2 planned, 2 reserved, 2 launched/,
 	$log_start
 );
 
@@ -296,13 +290,6 @@ my $av_pid = $node->safe_psql('postgres', qq{
 	LIMIT 1;
 });
 
-# Create role with pg_signal_autovacuum_worker for terminating autovacuum worker.
-$node->safe_psql('postgres', qq{
-	CREATE ROLE regress_worker_role;
-	GRANT pg_signal_autovacuum_worker TO regress_worker_role;
-	SET ROLE regress_worker_role;
-});
-
 $node->safe_psql('postgres', qq{
 	SELECT pg_terminate_backend('$av_pid');
 });
-- 
2.43.0

