Subject: [PATCH v6 2/4] Make autovacuum_enabled a ternary reloption.

From: Nathan Bossart <[email-masked]>
Date: Mon, 8 Jun 2026 14:50:36 -0500

This commit reimplements autovacuum_enabled as a ternary, using the
support added in commit 4d6a66f675 and following the example of
vacuum_truncate.  This changes only the internal representation: an
unset value still behaves as enabled, and the option accepts the
same input as before.

This is preparatory work for a follow-up commit that will make use
of the new "unset" state.
---
 src/backend/access/common/reloptions.c | 19 +++++++++----------
 src/backend/catalog/index.c            |  3 ++-
 src/backend/postmaster/autovacuum.c    |  2 +-
 src/include/utils/rel.h                |  2 +-
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c
index 3e832c3797e..79834126f2f 100644
--- a/src/backend/access/common/reloptions.c
+++ b/src/backend/access/common/reloptions.c
@@ -107,15 +107,6 @@ static relopt_bool boolRelOpts[] =
 		},
 		false
 	},
-	{
-		{
-			"autovacuum_enabled",
-			"Enables autovacuum in this relation",
-			RELOPT_KIND_HEAP | RELOPT_KIND_TOAST,
-			ShareUpdateExclusiveLock
-		},
-		true
-	},
 	{
 		{
 			"user_catalog_table",
@@ -168,6 +159,14 @@ static relopt_bool boolRelOpts[] =
 
 static relopt_ternary ternaryRelOpts[] =
 {
+	{
+		{
+			"autovacuum_enabled",
+			"Enables autovacuum in this relation",
+			RELOPT_KIND_HEAP | RELOPT_KIND_TOAST,
+			ShareUpdateExclusiveLock
+		}
+	},
 	{
 		{
 			"vacuum_truncate",
@@ -1976,7 +1975,7 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
 {
 	static const relopt_parse_elt tab[] = {
 		{"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
-		{"autovacuum_enabled", RELOPT_TYPE_BOOL,
+		{"autovacuum_enabled", RELOPT_TYPE_TERNARY,
 		offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
 		{"autovacuum_parallel_workers", RELOPT_TYPE_INT,
 		offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, autovacuum_parallel_workers)},
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 7c1b94407a9..1cd1368984e 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -2897,7 +2897,8 @@ index_update_stats(Relation rel,
 		{
 			StdRdOptions *options = (StdRdOptions *) rel->rd_options;
 
-			if (options != NULL && !options->autovacuum.enabled)
+			if (options != NULL &&
+				options->autovacuum.enabled == PG_TERNARY_FALSE)
 				update_stats = false;
 		}
 		else
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index db1f5d0e575..c8a1b66ca2e 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -3141,7 +3141,7 @@ relation_needs_vacanalyze(Oid relid,
 		? Min(avopts->multixact_freeze_max_age, effective_multixact_freeze_max_age)
 		: effective_multixact_freeze_max_age;
 
-	av_enabled = (avopts ? avopts->enabled : true);
+	av_enabled = (avopts ? avopts->enabled != PG_TERNARY_FALSE : true);
 	av_enabled &= AutoVacuumingActive();
 
 	relfrozenxid = classForm->relfrozenxid;
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index 89c159b133f..2ee98e9c6cc 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -310,7 +310,7 @@ typedef struct ForeignKeyCacheInfo
  /* autovacuum-related reloptions. */
 typedef struct AutoVacOpts
 {
-	bool		enabled;
+	pg_ternary	enabled;
 
 	int			autovacuum_parallel_workers;
 	int			vacuum_threshold;
-- 
2.50.1 (Apple Git-155)

--RRYXFNkLLTDnSeAO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
	filename=v6-0003-Add-an-unset-value-for-vacuum_index_cleanup.patch