v11-0002-Add-vacuum-need-flag-to-AutoVacuumScores.patch

application/octet-stream

Filename: v11-0002-Add-vacuum-need-flag-to-AutoVacuumScores.patch
Type: application/octet-stream
Part: 0
Message: Re: Add pg_stat_autovacuum_priority

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v11-0002
Subject: Add vacuum need flag to AutoVacuumScores
File+
src/backend/postmaster/autovacuum.c 21 5
From 9b14c37136fdd3183e6a21a9a02f82c70c4b1600 Mon Sep 17 00:00:00 2001
From: Sami Imseih <samimseih@gmail.com>
Date: Sat, 4 Apr 2026 16:46:24 +0000
Subject: [PATCH v11 2/3] Add vacuum need flag to AutoVacuumScores

---
 src/backend/postmaster/autovacuum.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 1be1ba8a25f..1bcd4ac4a17 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -329,8 +329,13 @@ typedef struct
 	double		vac;			/* vacuum component */
 	double		vac_ins;		/* vacuum insert component */
 	double		anl;			/* analyze component */
+	int			needs;			/* What type of vacuuming is needed */
 } AutoVacuumScores;
 
+/* The flags for AutoVacuumScores->needs */
+#define NEEDS_VACUUM 0x1
+#define NEEDS_ANALYZE 0x2
+
 /*
  * This struct is used to track and sort the list of tables to process.
  */
@@ -3051,6 +3056,8 @@ relation_needs_vacanalyze(Oid relid,
 	PgStat_StatTabEntry *tabentry;
 	bool		force_vacuum;
 	bool		av_enabled;
+	bool		needs_vacuum;
+	bool		needs_vacuum_ins;
 
 	/* constants from reloptions or GUC variables */
 	int			vac_base_thresh,
@@ -3258,15 +3265,20 @@ relation_needs_vacanalyze(Oid relid,
 	scores->vac = (double) vactuples / Max(vacthresh, 1);
 	scores->vac *= autovacuum_vacuum_score_weight;
 	scores->max = Max(scores->max, scores->vac);
-	if (av_enabled && vactuples > vacthresh)
-		*dovacuum = true;
+	needs_vacuum = (vactuples > vacthresh);
 
 	if (vac_ins_base_thresh >= 0)
 	{
 		scores->vac_ins = (double) instuples / Max(vacinsthresh, 1);
 		scores->vac_ins *= autovacuum_vacuum_insert_score_weight;
 		scores->max = Max(scores->max, scores->vac_ins);
-		if (av_enabled && instuples > vacinsthresh)
+	}
+	needs_vacuum_ins = (vac_ins_base_thresh >= 0 && instuples > vacinsthresh);
+
+	if (needs_vacuum || needs_vacuum_ins)
+	{
+		scores->needs |= NEEDS_VACUUM;
+		if (av_enabled)
 			*dovacuum = true;
 	}
 
@@ -3280,8 +3292,12 @@ relation_needs_vacanalyze(Oid relid,
 		scores->anl = (double) anltuples / Max(anlthresh, 1);
 		scores->anl *= autovacuum_analyze_score_weight;
 		scores->max = Max(scores->max, scores->anl);
-		if (av_enabled && anltuples > anlthresh)
-			*doanalyze = true;
+		if (anltuples > anlthresh)
+		{
+			scores->needs |= NEEDS_ANALYZE;
+			if (av_enabled)
+				*doanalyze = true;
+		}
 
 		/*
 		 * For historical reasons, we analyze even when autovacuum is disabled
-- 
2.50.1