From 228149d6cae9b067e40a9c032937f7e2f5d5bda9 Mon Sep 17 00:00:00 2001
From: Matthias van de Meent <boekewurm+postgres@gmail.com>
Date: Fri, 9 Oct 2026 16:04:07 +0200
Subject: [PATCH v2 1/3] Split out TransamVariablesData from transam.h

This will allow TransamVariablesData to contain types not avialable on
FRONTEND builds, and will be used in a follow-up commit.
---
 contrib/amcheck/verify_heapam.c               |  1 +
 contrib/pg_visibility/pg_visibility.c         |  1 +
 src/backend/access/transam/clog.c             |  1 +
 src/backend/access/transam/commit_ts.c        |  1 +
 src/backend/access/transam/subtrans.c         |  1 +
 src/backend/access/transam/twophase.c         |  1 +
 src/backend/access/transam/varsup.c           |  1 +
 src/backend/access/transam/xlog.c             |  1 +
 src/backend/access/transam/xlogreader.c       |  5 ++
 src/backend/postmaster/datachecksum_state.c   |  1 +
 src/backend/storage/ipc/procarray.c           |  1 +
 src/backend/storage/lmgr/predicate.c          |  1 +
 src/backend/utils/adt/xid8funcs.c             |  1 +
 src/include/access/transam.h                  | 63 ---------------
 src/include/access/varsup.h                   | 80 +++++++++++++++++++
 .../modules/xid_wraparound/xid_wraparound.c   |  1 +
 16 files changed, 98 insertions(+), 63 deletions(-)
 create mode 100644 src/include/access/varsup.h

diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c
index 46942b3580e..2c5932e741b 100644
--- a/contrib/amcheck/verify_heapam.c
+++ b/contrib/amcheck/verify_heapam.c
@@ -18,6 +18,7 @@
 #include "access/table.h"
 #include "access/toast_compression.h"
 #include "access/toast_internals.h"
+#include "access/varsup.h"
 #include "access/visibilitymap.h"
 #include "access/xact.h"
 #include "catalog/pg_am.h"
diff --git a/contrib/pg_visibility/pg_visibility.c b/contrib/pg_visibility/pg_visibility.c
index 4292d077be1..9096373e704 100644
--- a/contrib/pg_visibility/pg_visibility.c
+++ b/contrib/pg_visibility/pg_visibility.c
@@ -12,6 +12,7 @@
 
 #include "access/heapam.h"
 #include "access/htup_details.h"
+#include "access/varsup.h"
 #include "access/visibilitymap.h"
 #include "access/xloginsert.h"
 #include "catalog/pg_type.h"
diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c
index 6f7f6b86eb6..6875d9b8255 100644
--- a/src/backend/access/transam/clog.c
+++ b/src/backend/access/transam/clog.c
@@ -36,6 +36,7 @@
 #include "access/clog.h"
 #include "access/slru.h"
 #include "access/transam.h"
+#include "access/varsup.h"
 #include "access/xlog.h"
 #include "access/xloginsert.h"
 #include "access/xlogutils.h"
diff --git a/src/backend/access/transam/commit_ts.c b/src/backend/access/transam/commit_ts.c
index 9e6fd5d4657..4d598431938 100644
--- a/src/backend/access/transam/commit_ts.c
+++ b/src/backend/access/transam/commit_ts.c
@@ -25,6 +25,7 @@
 #include "access/htup_details.h"
 #include "access/slru.h"
 #include "access/transam.h"
+#include "access/varsup.h"
 #include "access/xloginsert.h"
 #include "access/xlogutils.h"
 #include "funcapi.h"
diff --git a/src/backend/access/transam/subtrans.c b/src/backend/access/transam/subtrans.c
index b79e648b899..6e2b8673217 100644
--- a/src/backend/access/transam/subtrans.c
+++ b/src/backend/access/transam/subtrans.c
@@ -31,6 +31,7 @@
 #include "access/slru.h"
 #include "access/subtrans.h"
 #include "access/transam.h"
+#include "access/varsup.h"
 #include "miscadmin.h"
 #include "pg_trace.h"
 #include "storage/subsystems.h"
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 48e478a4ecb..1ace109d144 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -82,6 +82,7 @@
 #include "access/transam.h"
 #include "access/twophase.h"
 #include "access/twophase_rmgr.h"
+#include "access/varsup.h"
 #include "access/xact.h"
 #include "access/xlog.h"
 #include "access/xloginsert.h"
diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c
index 912f7cb1d2c..398fd8bb9e5 100644
--- a/src/backend/access/transam/varsup.c
+++ b/src/backend/access/transam/varsup.c
@@ -17,6 +17,7 @@
 #include "access/commit_ts.h"
 #include "access/subtrans.h"
 #include "access/transam.h"
+#include "access/varsup.h"
 #include "access/xact.h"
 #include "access/xlogutils.h"
 #include "miscadmin.h"
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index afbe068cd0a..37f60038b07 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -55,6 +55,7 @@
 #include "access/timeline.h"
 #include "access/transam.h"
 #include "access/twophase.h"
+#include "access/varsup.h"
 #include "access/xact.h"
 #include "access/xlog_internal.h"
 #include "access/xlogarchive.h"
diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index cc61f830982..83f4ae8dea0 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -26,6 +26,11 @@
 #endif
 
 #include "access/transam.h"
+
+#ifndef FRONTEND
+#include "access/varsup.h"
+#endif
+
 #include "access/xlog_internal.h"
 #include "access/xlogreader.h"
 #include "access/xlogrecord.h"
diff --git a/src/backend/postmaster/datachecksum_state.c b/src/backend/postmaster/datachecksum_state.c
index e2b673a96b5..048c92e58c6 100644
--- a/src/backend/postmaster/datachecksum_state.c
+++ b/src/backend/postmaster/datachecksum_state.c
@@ -207,6 +207,7 @@
 #include "access/genam.h"
 #include "access/heapam.h"
 #include "access/htup_details.h"
+#include "access/varsup.h"
 #include "access/xact.h"
 #include "access/xlog.h"
 #include "access/xloginsert.h"
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index b7e03134ed8..742547ceb54 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -50,6 +50,7 @@
 #include "access/subtrans.h"
 #include "access/transam.h"
 #include "access/twophase.h"
+#include "access/varsup.h"
 #include "access/xact.h"
 #include "access/xlogutils.h"
 #include "catalog/catalog.h"
diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c
index 0ae85b7d5b4..818ae298e04 100644
--- a/src/backend/storage/lmgr/predicate.c
+++ b/src/backend/storage/lmgr/predicate.c
@@ -198,6 +198,7 @@
 #include "access/transam.h"
 #include "access/twophase.h"
 #include "access/twophase_rmgr.h"
+#include "access/varsup.h"
 #include "access/xact.h"
 #include "access/xlog.h"
 #include "miscadmin.h"
diff --git a/src/backend/utils/adt/xid8funcs.c b/src/backend/utils/adt/xid8funcs.c
index c607e78d9ac..0c907a1a728 100644
--- a/src/backend/utils/adt/xid8funcs.c
+++ b/src/backend/utils/adt/xid8funcs.c
@@ -27,6 +27,7 @@
 #include "postgres.h"
 
 #include "access/transam.h"
+#include "access/varsup.h"
 #include "access/xact.h"
 #include "funcapi.h"
 #include "lib/qunique.h"
diff --git a/src/include/access/transam.h b/src/include/access/transam.h
index dbe228527a3..5e8f1c7c1cb 100644
--- a/src/include/access/transam.h
+++ b/src/include/access/transam.h
@@ -197,66 +197,6 @@ FullTransactionIdAdvance(FullTransactionId *dest)
 #define FirstUnpinnedObjectId	12000
 #define FirstNormalObjectId		16384
 
-/*
- * TransamVariables is a data structure in shared memory that is used to track
- * OID and XID assignment state.  For largely historical reasons, there is
- * just one struct with different fields that are protected by different
- * LWLocks.
- *
- * Note: xidWrapLimit and oldestXidDB are not "active" values, but are
- * used just to generate useful messages when xidWarnLimit or xidStopLimit
- * are exceeded.
- */
-typedef struct TransamVariablesData
-{
-	/*
-	 * These fields are protected by OidGenLock.
-	 */
-	Oid8		nextOid;		/* next OID (8 bytes) to assign */
-	uint32		oidCount;		/* OIDs available before must do XLOG work */
-
-	/*
-	 * These fields are protected by XidGenLock.
-	 */
-	FullTransactionId nextXid;	/* next XID to assign */
-
-	TransactionId oldestXid;	/* cluster-wide minimum datfrozenxid */
-	TransactionId xidVacLimit;	/* start forcing autovacuums here */
-	TransactionId xidWarnLimit; /* start complaining here */
-	TransactionId xidStopLimit; /* refuse to advance nextXid beyond here */
-	TransactionId xidWrapLimit; /* where the world ends */
-	Oid			oldestXidDB;	/* database with minimum datfrozenxid */
-
-	/*
-	 * These fields are protected by CommitTsLock
-	 */
-	TransactionId oldestCommitTsXid;
-	TransactionId newestCommitTsXid;
-
-	/*
-	 * These fields are protected by ProcArrayLock.
-	 */
-	FullTransactionId latestCompletedXid;	/* newest full XID that has
-											 * committed or aborted */
-
-	/*
-	 * Number of top-level transactions with xids (i.e. which may have
-	 * modified the database) that completed in some form since the start of
-	 * the server. This currently is solely used to check whether
-	 * GetSnapshotData() needs to recompute the contents of the snapshot, or
-	 * not. There are likely other users of this.  Always above 1.
-	 */
-	uint64		xactCompletionCount;
-
-	/*
-	 * These fields are protected by XactTruncationLock
-	 */
-	TransactionId oldestClogXid;	/* oldest it's safe to look up in clog */
-
-} TransamVariablesData;
-
-
-
 /*
  * TransactionIdPrecedes --- is id1 logically < id2?
  */
@@ -330,9 +270,6 @@ TransactionIdFollowsOrEquals(TransactionId id1, TransactionId id2)
 /* in transam/xact.c */
 extern bool TransactionStartedDuringRecovery(void);
 
-/* in transam/varsup.c */
-extern PGDLLIMPORT TransamVariablesData *TransamVariables;
-
 /*
  * prototypes for functions in transam/transam.c
  */
diff --git a/src/include/access/varsup.h b/src/include/access/varsup.h
new file mode 100644
index 00000000000..0ade9e62ccf
--- /dev/null
+++ b/src/include/access/varsup.h
@@ -0,0 +1,80 @@
+/*-------------------------------------------------------------------------
+*
+ * varsup.h
+ *
+ * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/access/varsup.h
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#ifndef VARSUP_H
+#define VARSUP_H
+
+#include "access/transam.h"
+
+
+/*
+ * TransamVariables is a data structure in shared memory that is used to track
+ * OID and XID assignment state.  For largely historical reasons, there is
+ * just one struct with different fields that are protected by different
+ * LWLocks.
+ *
+ * Note: xidWrapLimit and oldestXidDB are not "active" values, but are
+ * used just to generate useful messages when xidWarnLimit or xidStopLimit
+ * are exceeded.
+ */
+typedef struct TransamVariablesData
+{
+	/*
+	 * These fields are protected by OidGenLock.
+	 */
+	Oid8		nextOid;		/* next OID (8 bytes) to assign */
+	uint32		oidCount;		/* OIDs available before must do XLOG work */
+
+	/*
+	 * These fields are protected by XidGenLock.
+	 */
+	FullTransactionId nextXid;	/* next XID to assign */
+
+	TransactionId oldestXid;	/* cluster-wide minimum datfrozenxid */
+	TransactionId xidVacLimit;	/* start forcing autovacuums here */
+	TransactionId xidWarnLimit; /* start complaining here */
+	TransactionId xidStopLimit; /* refuse to advance nextXid beyond here */
+	TransactionId xidWrapLimit; /* where the world ends */
+	Oid			oldestXidDB;	/* database with minimum datfrozenxid */
+
+	/*
+	 * These fields are protected by CommitTsLock
+	 */
+	TransactionId oldestCommitTsXid;
+	TransactionId newestCommitTsXid;
+
+	/*
+	 * These fields are protected by ProcArrayLock.
+	 */
+	FullTransactionId latestCompletedXid;	/* newest full XID that has
+											 * committed or aborted */
+
+	/*
+	 * Number of top-level transactions with xids (i.e. which may have
+	 * modified the database) that completed in some form since the start of
+	 * the server. This currently is solely used to check whether
+	 * GetSnapshotData() needs to recompute the contents of the snapshot, or
+	 * not. There are likely other users of this.  Always above 1.
+	 */
+	uint64		xactCompletionCount;
+
+	/*
+	 * These fields are protected by XactTruncationLock
+	 */
+	TransactionId oldestClogXid;	/* oldest it's safe to look up in clog */
+
+} TransamVariablesData;
+
+
+extern PGDLLIMPORT TransamVariablesData *TransamVariables;
+
+#endif /* VARSUP_H */
diff --git a/src/test/modules/xid_wraparound/xid_wraparound.c b/src/test/modules/xid_wraparound/xid_wraparound.c
index ca25d7e0206..cf9fe0a355e 100644
--- a/src/test/modules/xid_wraparound/xid_wraparound.c
+++ b/src/test/modules/xid_wraparound/xid_wraparound.c
@@ -15,6 +15,7 @@
 #include "postgres.h"
 
 #include "access/xact.h"
+#include "access/varsup.h"
 #include "miscadmin.h"
 #include "storage/proc.h"
 #include "utils/xid8.h"
-- 
2.54.0 (Apple Git-157)

