Subject: [PATCH v8 4/5] refactor autovacuum subroutine in preparation for system view

From: Nathan Bossart <[email-masked]>
Date: Thu, 2 Apr 2026 14:17:11 -0500

---
 src/backend/postmaster/autovacuum.c | 44 ++++++++++++++++-------------
 1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 12c205e57ea..9ccd1861328 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -370,10 +370,12 @@ static void FreeWorkerInfo(int code, Datum arg);
 static autovac_table *table_recheck_autovac(Oid relid, HTAB *table_toast_map,
 											TupleDesc pg_class_desc,
 											int effective_multixact_freeze_max_age);
-static void recheck_relation_needs_vacanalyze(Oid relid, AutoVacOpts *avopts,
-											  Form_pg_class classForm,
-											  int effective_multixact_freeze_max_age,
-											  bool *dovacuum, bool *doanalyze, bool *wraparound);
+static void compute_autovacuum_scores(Oid relid, AutoVacOpts *avopts,
+									  Form_pg_class classForm,
+									  int effective_multixact_freeze_max_age,
+									  int elevel,
+									  bool *dovacuum, bool *doanalyze, bool *wraparound,
+									  AutoVacuumScores *scores);
 static void relation_needs_vacanalyze(Oid relid, AutoVacOpts *relopts,
 									  Form_pg_class classForm,
 									  PgStat_StatTabEntry *tabentry,
@@ -2834,6 +2836,7 @@ table_recheck_autovac(Oid relid, HTAB *table_toast_map,
 	bool		wraparound;
 	AutoVacOpts *avopts;
 	bool		free_avopts = false;
+	AutoVacuumScores scores;
 
 	/* fetch the relation's relcache entry */
 	classTup = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(relid));
@@ -2859,9 +2862,11 @@ table_recheck_autovac(Oid relid, HTAB *table_toast_map,
 			avopts = &hentry->ar_reloptions;
 	}
 
-	recheck_relation_needs_vacanalyze(relid, avopts, classForm,
-									  effective_multixact_freeze_max_age,
-									  &dovacuum, &doanalyze, &wraparound);
+	compute_autovacuum_scores(relid, avopts, classForm,
+							  effective_multixact_freeze_max_age,
+							  DEBUG3,
+							  &dovacuum, &doanalyze, &wraparound,
+							  &scores);
 
 	/* OK, it needs something done */
 	if (doanalyze || dovacuum)
@@ -2971,24 +2976,23 @@ table_recheck_autovac(Oid relid, HTAB *table_toast_map,
 }
 
 /*
- * recheck_relation_needs_vacanalyze
- *
- * Subroutine for table_recheck_autovac.
+ * compute_autovacuum_scores
  *
  * Fetch the pgstat of a relation and recheck whether a relation
  * needs to be vacuumed or analyzed.
  */
 static void
-recheck_relation_needs_vacanalyze(Oid relid,
-								  AutoVacOpts *avopts,
-								  Form_pg_class classForm,
-								  int effective_multixact_freeze_max_age,
-								  bool *dovacuum,
-								  bool *doanalyze,
-								  bool *wraparound)
+compute_autovacuum_scores(Oid relid,
+						  AutoVacOpts *avopts,
+						  Form_pg_class classForm,
+						  int effective_multixact_freeze_max_age,
+						  int elevel,
+						  bool *dovacuum,
+						  bool *doanalyze,
+						  bool *wraparound,
+						  AutoVacuumScores *scores)
 {
 	PgStat_StatTabEntry *tabentry;
-	AutoVacuumScores scores;
 
 	/* fetch the pgstat table entry */
 	tabentry = pgstat_fetch_stat_tabentry_ext(classForm->relisshared,
@@ -2996,9 +3000,9 @@ recheck_relation_needs_vacanalyze(Oid relid,
 
 	relation_needs_vacanalyze(relid, avopts, classForm, tabentry,
 							  effective_multixact_freeze_max_age,
-							  DEBUG3,
+							  elevel,
 							  dovacuum, doanalyze, wraparound,
-							  &scores);
+							  scores);
 
 	/* Release tabentry to avoid leakage */
 	if (tabentry)
-- 
2.50.1 (Apple Git-155)

--/vKBiHkEvphli8Mi
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
	filename=v8-0005-add-pg_stat_autovacuum_scores-system-view.patch