Hi,

On 2026-04-02 12:52:13 +0200, Álvaro Herrera wrote:
> Here's low-hanging fruit I noticed while eyeballing a patch in the
> commitfest.  This removes pg_publication.h from utils/rel.h, which is
> really nice because pg_publication includes objectaddress.h which in
> turn includes parsenodes.h (an absolute disaster we have there, harder
> to cleanup; not in the mood).  But this here is nice and well contained.

These days including rel.h (indirectly) including objectaddress.h is
quite the disaster, because objectaddress.h recently grew an include of
syscache.h, as I complain about in [1].



I got pretty annoyed this cycle with how much rebuilding a simple change to
bufmgr.h triggers (due to hacking on it a lot).  I started to write a series
to improve that, but didn't get around to posting that yet due to encountering
the issue 771fe0948ca fixed while improving the situation.

During that I encountered the objectaddress.h include, as part of which I then
complained about the issue in [1].


After the attached patches, a change to bufmgr.h triggers rebuilding 213
files, before it was 323.  Not perfect, but better.

Would be nice to get rid of the bufmgr.h includes in access/nbtree.h and such,
but it looks like that'd be a bit more work.

I included your catalog/publication.h in it, as my version had surprisingly
extensive bitrot...

Greetings,

Andres Freund

[1] 
https://postgr.es/m/vlcexdcimsmvu3aplt2yxpfndkgtuvjsrms2fdl46rbw3k2kug%40drspkoxlaije
>From 74298db41eb8d2fa506c255183207be3e008cc49 Mon Sep 17 00:00:00 2001
From: Andres Freund <[email protected]>
Date: Tue, 17 Mar 2026 10:50:06 -0400
Subject: [PATCH v2 1/9] wip: Don't include read_stream.h in tableam.h

---
 src/include/access/tableam.h       | 2 +-
 src/backend/access/brin/brin.c     | 1 +
 src/backend/commands/analyze.c     | 1 +
 src/backend/utils/cache/relcache.c | 1 +
 4 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 4647785fd35..df00fee2229 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -21,7 +21,6 @@
 #include "access/sdir.h"
 #include "access/xact.h"
 #include "executor/tuptable.h"
-#include "storage/read_stream.h"
 #include "utils/rel.h"
 #include "utils/snapshot.h"
 
@@ -36,6 +35,7 @@ extern PGDLLIMPORT bool synchronize_seqscans;
 /* forward references in this file */
 typedef struct BulkInsertStateData BulkInsertStateData;
 typedef struct IndexInfo IndexInfo;
+typedef struct ReadStream ReadStream;
 typedef struct SampleScanState SampleScanState;
 typedef struct ScanKeyData ScanKeyData;
 typedef struct ValidateIndexState ValidateIndexState;
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index bdb30752e09..5ec99d44d59 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -35,6 +35,7 @@
 #include "storage/bufmgr.h"
 #include "storage/condition_variable.h"
 #include "storage/freespace.h"
+#include "storage/read_stream.h"
 #include "storage/proc.h"
 #include "tcop/tcopprot.h"
 #include "utils/acl.h"
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 49a5cdf579c..e5d38322753 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -45,6 +45,7 @@
 #include "statistics/statistics.h"
 #include "storage/bufmgr.h"
 #include "storage/procarray.h"
+#include "storage/read_stream.h"
 #include "utils/attoptcache.h"
 #include "utils/datum.h"
 #include "utils/guc.h"
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index e19f0d3e51c..5e2730d92b9 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -75,6 +75,7 @@
 #include "pgstat.h"
 #include "rewrite/rewriteDefine.h"
 #include "rewrite/rowsecurity.h"
+#include "storage/bufmgr.h"
 #include "storage/fd.h"
 #include "storage/lmgr.h"
 #include "storage/lock.h"
-- 
2.53.0.1.gb2826b52eb

>From d09db7eab48cefb0598080b2dc1f44b6e0761d94 Mon Sep 17 00:00:00 2001
From: Andres Freund <[email protected]>
Date: Tue, 17 Mar 2026 11:00:26 -0400
Subject: [PATCH v2 2/9] wip: Don't include snapmgr.h in bufmgr.h

---
 src/include/access/nbtree.h               | 2 ++
 src/include/storage/bufmgr.h              | 1 -
 src/backend/access/brin/brin.c            | 1 +
 src/backend/access/gin/gininsert.c        | 1 +
 src/backend/access/gin/ginvacuum.c        | 1 +
 src/backend/access/heap/heapam.c          | 1 +
 src/backend/access/heap/heapam_handler.c  | 1 +
 src/backend/access/heap/vacuumlazy.c      | 1 +
 src/backend/access/nbtree/nbtree.c        | 1 +
 src/backend/access/nbtree/nbtvalidate.c   | 1 +
 src/backend/access/table/tableam.c        | 1 +
 src/backend/executor/nodeBitmapHeapscan.c | 1 +
 contrib/amcheck/verify_heapam.c           | 1 +
 13 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index da7503c57b6..bf166bf8ac9 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -17,6 +17,7 @@
 #include "access/amapi.h"
 #include "access/itup.h"
 #include "access/sdir.h"
+#include "access/transam.h"
 #include "catalog/pg_am_d.h"
 #include "catalog/pg_class.h"
 #include "catalog/pg_index.h"
@@ -24,6 +25,7 @@
 #include "storage/bufmgr.h"
 #include "storage/dsm.h"
 #include "storage/shm_toc.h"
+#include "utils/snapmgr.h"
 #include "utils/skipsupport.h"
 
 /* There's room for a 16-bit vacuum cycle ID in BTPageOpaqueData */
diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h
index aa61a39d9e6..c4b48c2aa4c 100644
--- a/src/include/storage/bufmgr.h
+++ b/src/include/storage/bufmgr.h
@@ -21,7 +21,6 @@
 #include "storage/bufpage.h"
 #include "storage/relfilelocator.h"
 #include "utils/relcache.h"
-#include "utils/snapmgr.h"
 
 typedef void *Block;
 
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 5ec99d44d59..9117dfb09a3 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -45,6 +45,7 @@
 #include "utils/index_selfuncs.h"
 #include "utils/memutils.h"
 #include "utils/rel.h"
+#include "utils/snapmgr.h"
 #include "utils/tuplesort.h"
 #include "utils/wait_event.h"
 
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index 9d83a495775..bdf2335f7f5 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -36,6 +36,7 @@
 #include "utils/memutils.h"
 #include "utils/builtins.h"
 #include "utils/rel.h"
+#include "utils/snapmgr.h"
 #include "utils/tuplesort.h"
 #include "utils/typcache.h"
 #include "utils/wait_event.h"
diff --git a/src/backend/access/gin/ginvacuum.c b/src/backend/access/gin/ginvacuum.c
index 840543eb664..fb7dd6e463f 100644
--- a/src/backend/access/gin/ginvacuum.c
+++ b/src/backend/access/gin/ginvacuum.c
@@ -24,6 +24,7 @@
 #include "storage/predicate.h"
 #include "storage/read_stream.h"
 #include "utils/memutils.h"
+#include "utils/snapmgr.h"
 
 struct GinVacuumState
 {
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 6bff0032db2..8c4fb04af19 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -52,6 +52,7 @@
 #include "utils/datum.h"
 #include "utils/injection_point.h"
 #include "utils/inval.h"
+#include "utils/snapmgr.h"
 #include "utils/spccache.h"
 #include "utils/syscache.h"
 
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 1be8ea4845a..ad8220cb0f0 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -46,6 +46,7 @@
 #include "storage/smgr.h"
 #include "utils/builtins.h"
 #include "utils/rel.h"
+#include "utils/snapmgr.h"
 #include "utils/tuplesort.h"
 
 static void reform_and_rewrite_tuple(HeapTuple tuple,
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index 88c71cd85b6..0da7ebe59e6 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -154,6 +154,7 @@
 #include "storage/read_stream.h"
 #include "utils/lsyscache.h"
 #include "utils/pg_rusage.h"
+#include "utils/snapmgr.h"
 #include "utils/timestamp.h"
 #include "utils/wait_event.h"
 
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index 6d870e4ebe7..d4aac844352 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -36,6 +36,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/index_selfuncs.h"
 #include "utils/memutils.h"
+#include "utils/snapmgr.h"
 #include "utils/wait_event.h"
 
 
diff --git a/src/backend/access/nbtree/nbtvalidate.c b/src/backend/access/nbtree/nbtvalidate.c
index b67c015a4e7..f4ee2988f1f 100644
--- a/src/backend/access/nbtree/nbtvalidate.c
+++ b/src/backend/access/nbtree/nbtvalidate.c
@@ -25,6 +25,7 @@
 #include "utils/builtins.h"
 #include "utils/lsyscache.h"
 #include "utils/regproc.h"
+#include "utils/snapmgr.h"
 #include "utils/syscache.h"
 
 
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index 68ff0966f1c..427be8f8f72 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -30,6 +30,7 @@
 #include "storage/bufmgr.h"
 #include "storage/shmem.h"
 #include "storage/smgr.h"
+#include "utils/snapmgr.h"
 
 /*
  * Constants to control the behavior of block allocation to parallel workers
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index 73831aed451..8004bb7b29a 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -47,6 +47,7 @@
 #include "storage/condition_variable.h"
 #include "utils/dsa.h"
 #include "utils/rel.h"
+#include "utils/snapmgr.h"
 #include "utils/spccache.h"
 #include "utils/wait_event.h"
 
diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c
index 20ff58aa782..6b2d7fb634f 100644
--- a/contrib/amcheck/verify_heapam.c
+++ b/contrib/amcheck/verify_heapam.c
@@ -30,6 +30,7 @@
 #include "utils/builtins.h"
 #include "utils/fmgroids.h"
 #include "utils/rel.h"
+#include "utils/snapmgr.h"
 #include "utils/tuplestore.h"
 
 PG_FUNCTION_INFO_V1(verify_heapam);
-- 
2.53.0.1.gb2826b52eb

>From a25e7c476416b30c335ae70d26122696c668159a Mon Sep 17 00:00:00 2001
From: Andres Freund <[email protected]>
Date: Tue, 17 Mar 2026 11:01:01 -0400
Subject: [PATCH v2 3/9] wip: Don't include relcache.h in bufmgr.h

---
 src/include/storage/bufmgr.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h
index c4b48c2aa4c..109182f9af9 100644
--- a/src/include/storage/bufmgr.h
+++ b/src/include/storage/bufmgr.h
@@ -20,9 +20,9 @@
 #include "storage/buf.h"
 #include "storage/bufpage.h"
 #include "storage/relfilelocator.h"
-#include "utils/relcache.h"
 
 typedef void *Block;
+typedef struct RelationData *Relation;
 
 /*
  * Possible arguments for GetAccessStrategy().
-- 
2.53.0.1.gb2826b52eb

>From 0c72862ca27635faa8f1f060cd9722001d4f1773 Mon Sep 17 00:00:00 2001
From: Andres Freund <[email protected]>
Date: Thu, 2 Apr 2026 11:56:01 -0400
Subject: [PATCH v2 4/9] Don't include snapshot.h in tableam.h

---
 src/include/access/tableam.h     | 3 ++-
 src/backend/executor/execUtils.c | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index df00fee2229..7f99203f965 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -22,7 +22,6 @@
 #include "access/xact.h"
 #include "executor/tuptable.h"
 #include "utils/rel.h"
-#include "utils/snapshot.h"
 
 
 #define DEFAULT_TABLE_ACCESS_METHOD	"heap"
@@ -38,6 +37,8 @@ typedef struct IndexInfo IndexInfo;
 typedef struct ReadStream ReadStream;
 typedef struct SampleScanState SampleScanState;
 typedef struct ScanKeyData ScanKeyData;
+typedef struct SnapshotData SnapshotData;
+typedef SnapshotData *Snapshot;
 typedef struct ValidateIndexState ValidateIndexState;
 typedef struct VacuumParams VacuumParams;
 
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c
index 1eb6b9f1f40..280364364dc 100644
--- a/src/backend/executor/execUtils.c
+++ b/src/backend/executor/execUtils.c
@@ -61,6 +61,7 @@
 #include "utils/builtins.h"
 #include "utils/memutils.h"
 #include "utils/rel.h"
+#include "utils/snapshot.h"
 #include "utils/typcache.h"
 
 
-- 
2.53.0.1.gb2826b52eb

>From 566868daf77315fd1792e3a79dd7d5ad9a0994af Mon Sep 17 00:00:00 2001
From: Andres Freund <[email protected]>
Date: Fri, 20 Mar 2026 12:28:40 -0400
Subject: [PATCH v2 5/9] Don't include xlogreader.h in xlog.h

xlogreader.h includes a bunch of lower level headers that most xact.h users
don't need. In particular, tableam.h includes xact.h (due to the checks added
by 7259736a6e5b), which exposes xlogreader.h far too widely.

Author:
Reviewed-by:
Discussion: https://postgr.es/m/
Backpatch:
---
 src/include/access/xact.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/include/access/xact.h b/src/include/access/xact.h
index f0b4d795071..250b6d92050 100644
--- a/src/include/access/xact.h
+++ b/src/include/access/xact.h
@@ -15,13 +15,16 @@
 #define XACT_H
 
 #include "access/transam.h"
-#include "access/xlogreader.h"
 #include "datatype/timestamp.h"
 #include "lib/stringinfo.h"
 #include "nodes/pg_list.h"
 #include "storage/relfilelocator.h"
 #include "storage/sinval.h"
 
+
+/* forward references in this file */
+typedef struct XLogReaderState XLogReaderState;
+
 /*
  * Maximum size of Global Transaction ID (including '\0').
  *
-- 
2.53.0.1.gb2826b52eb

>From 2e03f3cb40d3c13637671b6c6d8d050820b39bb5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Thu, 2 Apr 2026 12:33:56 +0200
Subject: [PATCH v2 6/9] Don't include catalog/publication.h in utils/rel.h

---
 src/include/access/tableam.h           | 1 +
 src/include/replication/logicalproto.h | 1 +
 src/include/storage/lmgr.h             | 1 +
 src/include/utils/rel.h                | 5 ++++-
 src/backend/catalog/pg_shdepend.c      | 1 +
 src/backend/commands/alter.c           | 1 +
 src/backend/commands/lockcmds.c        | 1 +
 src/backend/commands/tablecmds.c       | 1 +
 contrib/pg_surgery/heap_surgery.c      | 1 +
 contrib/pgrowlocks/pgrowlocks.c        | 1 +
 10 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 7f99203f965..61ba2476ed2 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -21,6 +21,7 @@
 #include "access/sdir.h"
 #include "access/xact.h"
 #include "executor/tuptable.h"
+#include "nodes/lockoptions.h"
 #include "utils/rel.h"
 
 
diff --git a/src/include/replication/logicalproto.h b/src/include/replication/logicalproto.h
index 058a955e20c..b4192b68174 100644
--- a/src/include/replication/logicalproto.h
+++ b/src/include/replication/logicalproto.h
@@ -14,6 +14,7 @@
 #define LOGICAL_PROTO_H
 
 #include "access/xact.h"
+#include "catalog/pg_publication.h"
 #include "executor/tuptable.h"
 #include "replication/reorderbuffer.h"
 #include "utils/rel.h"
diff --git a/src/include/storage/lmgr.h b/src/include/storage/lmgr.h
index 2a985ce5e15..9dae6a15560 100644
--- a/src/include/storage/lmgr.h
+++ b/src/include/storage/lmgr.h
@@ -16,6 +16,7 @@
 
 #include "lib/stringinfo.h"
 #include "storage/itemptr.h"
+#include "storage/lockdefs.h"
 #include "storage/locktag.h"
 #include "utils/rel.h"
 
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index 236830f6b93..9b4e4e00cc0 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -19,7 +19,6 @@
 #include "catalog/catalog.h"
 #include "catalog/pg_class.h"
 #include "catalog/pg_index.h"
-#include "catalog/pg_publication.h"
 #include "nodes/bitmapset.h"
 #include "partitioning/partdefs.h"
 #include "rewrite/prs2lock.h"
@@ -29,6 +28,10 @@
 #include "utils/relcache.h"
 #include "utils/reltrigger.h"
 
+/*
+ * forward references in this file
+ */
+typedef struct PublicationDesc PublicationDesc;
 
 /*
  * LockRelId and LockInfo really belong to lmgr.h, but it's more convenient
diff --git a/src/backend/catalog/pg_shdepend.c b/src/backend/catalog/pg_shdepend.c
index c9998531b2f..bbb60dd565a 100644
--- a/src/backend/catalog/pg_shdepend.c
+++ b/src/backend/catalog/pg_shdepend.c
@@ -38,6 +38,7 @@
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_proc.h"
+#include "catalog/pg_publication.h"
 #include "catalog/pg_shdepend.h"
 #include "catalog/pg_statistic_ext.h"
 #include "catalog/pg_subscription.h"
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c
index 74ceb5fe20d..6fbeb69ba96 100644
--- a/src/backend/commands/alter.c
+++ b/src/backend/commands/alter.c
@@ -35,6 +35,7 @@
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_proc.h"
+#include "catalog/pg_publication.h"
 #include "catalog/pg_statistic_ext.h"
 #include "catalog/pg_subscription.h"
 #include "catalog/pg_ts_config.h"
diff --git a/src/backend/commands/lockcmds.c b/src/backend/commands/lockcmds.c
index f66b8f17b9b..5a52f4acace 100644
--- a/src/backend/commands/lockcmds.c
+++ b/src/backend/commands/lockcmds.c
@@ -17,6 +17,7 @@
 #include "access/table.h"
 #include "access/xact.h"
 #include "catalog/namespace.h"
+#include "catalog/objectaddress.h"
 #include "catalog/pg_inherits.h"
 #include "commands/lockcmds.h"
 #include "miscadmin.h"
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 0ce2e81f9c2..aa6c0977ba2 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -48,6 +48,7 @@
 #include "catalog/pg_opclass.h"
 #include "catalog/pg_policy.h"
 #include "catalog/pg_proc.h"
+#include "catalog/pg_publication.h"
 #include "catalog/pg_publication_rel.h"
 #include "catalog/pg_rewrite.h"
 #include "catalog/pg_statistic_ext.h"
diff --git a/contrib/pg_surgery/heap_surgery.c b/contrib/pg_surgery/heap_surgery.c
index ae4e7c0136c..b69505c1488 100644
--- a/contrib/pg_surgery/heap_surgery.c
+++ b/contrib/pg_surgery/heap_surgery.c
@@ -16,6 +16,7 @@
 #include "access/relation.h"
 #include "access/visibilitymap.h"
 #include "access/xloginsert.h"
+#include "catalog/objectaddress.h"
 #include "catalog/pg_am_d.h"
 #include "miscadmin.h"
 #include "storage/bufmgr.h"
diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c
index d164c4c03ad..077ce61dd71 100644
--- a/contrib/pgrowlocks/pgrowlocks.c
+++ b/contrib/pgrowlocks/pgrowlocks.c
@@ -30,6 +30,7 @@
 #include "access/tableam.h"
 #include "access/xact.h"
 #include "catalog/namespace.h"
+#include "catalog/objectaddress.h"
 #include "catalog/pg_am_d.h"
 #include "catalog/pg_authid.h"
 #include "funcapi.h"
-- 
2.53.0.1.gb2826b52eb

>From bd2d6e0ce5f33b24547aa114cb475f6b0a3ae7c5 Mon Sep 17 00:00:00 2001
From: Andres Freund <[email protected]>
Date: Fri, 20 Mar 2026 13:01:49 -0400
Subject: [PATCH v2 7/9] Don't include tupdesc.h in relcache.h

Author:
Reviewed-by:
Discussion: https://postgr.es/m/
Backpatch:
---
 src/include/catalog/catalog.h | 1 +
 src/include/utils/relcache.h  | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/include/catalog/catalog.h b/src/include/catalog/catalog.h
index a9d6e8ea986..e7b76b5ffe3 100644
--- a/src/include/catalog/catalog.h
+++ b/src/include/catalog/catalog.h
@@ -14,6 +14,7 @@
 #ifndef CATALOG_H
 #define CATALOG_H
 
+#include "access/attnum.h"
 #include "catalog/pg_class.h"
 #include "utils/relcache.h"
 
diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h
index 2700224939a..35944da6577 100644
--- a/src/include/utils/relcache.h
+++ b/src/include/utils/relcache.h
@@ -14,9 +14,9 @@
 #ifndef RELCACHE_H
 #define RELCACHE_H
 
-#include "access/tupdesc.h"
 #include "common/relpath.h"
 #include "nodes/bitmapset.h"
+#include "nodes/pg_list.h"
 
 
 /*
@@ -24,7 +24,9 @@
  */
 #define RELCACHE_INIT_FILENAME	"pg_internal.init"
 
+/* forward references in this file */
 typedef struct RelationData *Relation;
+typedef struct TupleDescData *TupleDesc;
 
 /* ----------------
  *		RelationPtr is used in the executor to support index scans
-- 
2.53.0.1.gb2826b52eb

>From 5d92ff27ed1032ad4c215248803911ea2300c441 Mon Sep 17 00:00:00 2001
From: Andres Freund <[email protected]>
Date: Fri, 20 Mar 2026 13:02:38 -0400
Subject: [PATCH v2 8/9] Don't include relcache.h in rel.h

Author:
Reviewed-by:
Discussion: https://postgr.es/m/
Backpatch:
---
 src/include/utils/rel.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index 9b4e4e00cc0..d17286ee333 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -25,7 +25,6 @@
 #include "storage/block.h"
 #include "storage/relfilelocator.h"
 #include "storage/smgr.h"
-#include "utils/relcache.h"
 #include "utils/reltrigger.h"
 
 /*
-- 
2.53.0.1.gb2826b52eb

>From 3cfa833fa3d8252e6fb0b50507651fee4869cdd7 Mon Sep 17 00:00:00 2001
From: Andres Freund <[email protected]>
Date: Thu, 2 Apr 2026 12:17:12 -0400
Subject: [PATCH v2 9/9] Don't include read_stream.h in heapam.h

heapam.h is still quite widely included...
---
 src/include/access/heapam.h              | 2 +-
 src/backend/access/heap/heapam.c         | 2 ++
 src/backend/access/heap/heapam_handler.c | 1 +
 src/backend/executor/execReplication.c   | 1 +
 4 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 54067b828e4..0b9b379e20d 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -26,7 +26,6 @@
 #include "storage/bufpage.h"
 #include "storage/dsm.h"
 #include "storage/lockdefs.h"
-#include "storage/read_stream.h"
 #include "storage/shm_toc.h"
 #include "utils/relcache.h"
 #include "utils/snapshot.h"
@@ -49,6 +48,7 @@ typedef struct GlobalVisState GlobalVisState;
 typedef struct TupleTableSlot TupleTableSlot;
 typedef struct VacuumCutoffs VacuumCutoffs;
 typedef struct VacuumParams VacuumParams;
+typedef struct read_stream read_stream;
 
 #define MaxLockTupleMode	LockTupleExclusive
 
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 8c4fb04af19..18a3918f81b 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -45,10 +45,12 @@
 #include "commands/vacuum.h"
 #include "pgstat.h"
 #include "port/pg_bitutils.h"
+#include "storage/bufmgr.h"
 #include "storage/lmgr.h"
 #include "storage/predicate.h"
 #include "storage/proc.h"
 #include "storage/procarray.h"
+#include "storage/read_stream.h"
 #include "utils/datum.h"
 #include "utils/injection_point.h"
 #include "utils/inval.h"
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index ad8220cb0f0..4bf74d8ca89 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -43,6 +43,7 @@
 #include "storage/lock.h"
 #include "storage/predicate.h"
 #include "storage/procarray.h"
+#include "storage/read_stream.h"
 #include "storage/smgr.h"
 #include "utils/builtins.h"
 #include "utils/rel.h"
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index b2ca5cbf117..bb12d191216 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -29,6 +29,7 @@
 #include "executor/nodeModifyTable.h"
 #include "replication/conflict.h"
 #include "replication/logicalrelation.h"
+#include "storage/bufmgr.h"
 #include "storage/lmgr.h"
 #include "utils/builtins.h"
 #include "utils/lsyscache.h"
-- 
2.53.0.1.gb2826b52eb

Reply via email to