On 2026-Mar-21, Álvaro Herrera wrote:

> I checked this, and found a couple of headers that can benefit from a
> removal, as shown in the attached patches.

I looked again and found some more; the first 14 patches attached here
do so.  A couple of them have no fallout to speak of, which I find
really surprising; for the majority we just need a couple of extra
includes somewhere or a typedef or two.  I unleashed CI on it to see
what would happen,
https://cirrus-ci.com/build/5522804717649920

The 15th one removes the inclusion of clog.h in proc.h.  Not really
related to this thread, but I noticed while looking at proc.h for
removal of lock.h.


> A special case (not modified here) is proc.h. It seems to me that
> lock.h _could_ be removed from there with some effort, but the amount
> of .c files that would benefit seems to me not large enough to justify
> the number of contortions needed.  Others could disagree though.

I looked at it again while doing the above and came to the same
conclusion.  In order to make it work we'd need half a dozen typedefs,
and it doesn't really look very pretty.

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
Syntax error: function hell() needs an argument.
Please choose what hell you want to involve.
>From fa3addb3e59e1e816b86fc8fdf80ebbc4cc2b119 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sat, 21 Mar 2026 20:33:10 +0100
Subject: [PATCH v2 01/15] procarray.h does not need storage/lock.h for
 anything

No fallout from this change.  Weird
---
 src/include/storage/procarray.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/include/storage/procarray.h b/src/include/storage/procarray.h
index c5ab1574fe3..abdf021e66e 100644
--- a/src/include/storage/procarray.h
+++ b/src/include/storage/procarray.h
@@ -14,7 +14,6 @@
 #ifndef PROCARRAY_H
 #define PROCARRAY_H
 
-#include "storage/lock.h"
 #include "storage/standby.h"
 #include "utils/relcache.h"
 #include "utils/snapshot.h"
-- 
2.47.3

>From 2a3617412f169efca8a044ad03daa047c8427cbd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sat, 21 Mar 2026 20:35:51 +0100
Subject: [PATCH v2 02/15] lmgr.h doesn't need the full lock.h

---
 src/backend/utils/activity/wait_event.c | 6 ++++--
 src/backend/utils/cache/syscache.c      | 1 +
 src/include/storage/lmgr.h              | 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/backend/utils/activity/wait_event.c b/src/backend/utils/activity/wait_event.c
index aca2c8fc742..c7e2d825120 100644
--- a/src/backend/utils/activity/wait_event.c
+++ b/src/backend/utils/activity/wait_event.c
@@ -22,9 +22,11 @@
  */
 #include "postgres.h"
 
-#include "storage/lmgr.h"		/* for GetLockNameFromTagType */
-#include "storage/lwlock.h"		/* for GetLWLockIdentifier */
+#include "storage/lmgr.h"
+#include "storage/lwlock.h"
+#include "storage/shmem.h"
 #include "storage/spin.h"
+#include "utils/hsearch.h"
 #include "utils/wait_event.h"
 
 
diff --git a/src/backend/utils/cache/syscache.c b/src/backend/utils/cache/syscache.c
index 007a9a15d71..f4233f9e31a 100644
--- a/src/backend/utils/cache/syscache.c
+++ b/src/backend/utils/cache/syscache.c
@@ -32,6 +32,7 @@
 #include "lib/qunique.h"
 #include "miscadmin.h"
 #include "storage/lmgr.h"
+#include "storage/lock.h"
 #include "utils/catcache.h"
 #include "utils/inval.h"
 #include "utils/lsyscache.h"
diff --git a/src/include/storage/lmgr.h b/src/include/storage/lmgr.h
index 74a398ffc00..2a985ce5e15 100644
--- a/src/include/storage/lmgr.h
+++ b/src/include/storage/lmgr.h
@@ -16,7 +16,7 @@
 
 #include "lib/stringinfo.h"
 #include "storage/itemptr.h"
-#include "storage/lock.h"
+#include "storage/locktag.h"
 #include "utils/rel.h"
 
 
-- 
2.47.3

>From 59bab523687d21ff8732c453693e45054b0e3def Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sat, 21 Mar 2026 20:49:41 +0100
Subject: [PATCH v2 03/15] namespace.h doesn't need lock.h, only lockdefs.h

---
 src/backend/access/common/relation.c  | 1 +
 src/backend/commands/conversioncmds.c | 1 +
 src/backend/commands/discard.c        | 1 +
 src/backend/parser/parse_oper.c       | 1 +
 src/backend/utils/cache/ts_cache.c    | 1 +
 src/include/catalog/namespace.h       | 2 +-
 6 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/backend/access/common/relation.c b/src/backend/access/common/relation.c
index 92a6e37d8bd..2e3a37c9272 100644
--- a/src/backend/access/common/relation.c
+++ b/src/backend/access/common/relation.c
@@ -24,6 +24,7 @@
 #include "access/xact.h"
 #include "catalog/namespace.h"
 #include "pgstat.h"
+#include "storage/lock.h"
 #include "storage/lmgr.h"
 #include "utils/inval.h"
 #include "utils/syscache.h"
diff --git a/src/backend/commands/conversioncmds.c b/src/backend/commands/conversioncmds.c
index 61aa8bb9fd1..5f2022d3072 100644
--- a/src/backend/commands/conversioncmds.c
+++ b/src/backend/commands/conversioncmds.c
@@ -19,6 +19,7 @@
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
 #include "commands/conversioncmds.h"
+#include "fmgr.h"
 #include "mb/pg_wchar.h"
 #include "miscadmin.h"
 #include "parser/parse_func.h"
diff --git a/src/backend/commands/discard.c b/src/backend/commands/discard.c
index 7b5520b9abe..17d172df076 100644
--- a/src/backend/commands/discard.c
+++ b/src/backend/commands/discard.c
@@ -19,6 +19,7 @@
 #include "commands/discard.h"
 #include "commands/prepare.h"
 #include "commands/sequence.h"
+#include "storage/lock.h"
 #include "utils/guc.h"
 #include "utils/portal.h"
 
diff --git a/src/backend/parser/parse_oper.c b/src/backend/parser/parse_oper.c
index a6b402f2d7b..2f218c1ab8b 100644
--- a/src/backend/parser/parse_oper.c
+++ b/src/backend/parser/parse_oper.c
@@ -25,6 +25,7 @@
 #include "parser/parse_oper.h"
 #include "parser/parse_type.h"
 #include "utils/builtins.h"
+#include "utils/hsearch.h"
 #include "utils/inval.h"
 #include "utils/lsyscache.h"
 #include "utils/syscache.h"
diff --git a/src/backend/utils/cache/ts_cache.c b/src/backend/utils/cache/ts_cache.c
index 744c8e71d71..9e29f1386b0 100644
--- a/src/backend/utils/cache/ts_cache.c
+++ b/src/backend/utils/cache/ts_cache.c
@@ -44,6 +44,7 @@
 #include "utils/catcache.h"
 #include "utils/fmgroids.h"
 #include "utils/guc_hooks.h"
+#include "utils/hsearch.h"
 #include "utils/inval.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
diff --git a/src/include/catalog/namespace.h b/src/include/catalog/namespace.h
index 1a25973685c..9453a3e4932 100644
--- a/src/include/catalog/namespace.h
+++ b/src/include/catalog/namespace.h
@@ -15,7 +15,7 @@
 #define NAMESPACE_H
 
 #include "nodes/primnodes.h"
-#include "storage/lock.h"
+#include "storage/lockdefs.h"
 #include "storage/procnumber.h"
 
 
-- 
2.47.3

>From 605e2b8866607a1f3d79bda89d93678c91af6848 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sat, 21 Mar 2026 20:53:54 +0100
Subject: [PATCH v2 04/15] vacuum.h doesn't need lock.h

---
 src/backend/access/nbtree/nbtree.c    | 1 +
 src/backend/catalog/pg_subscription.c | 1 +
 src/include/commands/vacuum.h         | 1 -
 3 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index aed74590cf4..6d870e4ebe7 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -30,6 +30,7 @@
 #include "storage/indexfsm.h"
 #include "storage/ipc.h"
 #include "storage/lmgr.h"
+#include "storage/lwlock.h"
 #include "storage/read_stream.h"
 #include "utils/datum.h"
 #include "utils/fmgrprotos.h"
diff --git a/src/backend/catalog/pg_subscription.c b/src/backend/catalog/pg_subscription.c
index 3673d4f0bc1..1d140c513d0 100644
--- a/src/backend/catalog/pg_subscription.c
+++ b/src/backend/catalog/pg_subscription.c
@@ -26,6 +26,7 @@
 #include "foreign/foreign.h"
 #include "miscadmin.h"
 #include "storage/lmgr.h"
+#include "storage/lock.h"
 #include "utils/acl.h"
 #include "utils/array.h"
 #include "utils/builtins.h"
diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h
index 953a506181e..1f45bca015c 100644
--- a/src/include/commands/vacuum.h
+++ b/src/include/commands/vacuum.h
@@ -23,7 +23,6 @@
 #include "catalog/pg_type.h"
 #include "parser/parse_node.h"
 #include "storage/buf.h"
-#include "storage/lock.h"
 #include "utils/relcache.h"
 
 /*
-- 
2.47.3

>From 30faaa8fe40d1f95480de3ad00b9576fd4ea7e1d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sun, 22 Mar 2026 17:52:12 +0100
Subject: [PATCH v2 05/15] standby.h doesn't need the full lock.h

---
 contrib/amcheck/verify_heapam.c | 1 +
 src/include/storage/lock.h      | 2 +-
 src/include/storage/standby.h   | 5 ++++-
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c
index ada782f98f5..20ff58aa782 100644
--- a/contrib/amcheck/verify_heapam.c
+++ b/contrib/amcheck/verify_heapam.c
@@ -24,6 +24,7 @@
 #include "funcapi.h"
 #include "miscadmin.h"
 #include "storage/bufmgr.h"
+#include "storage/lwlock.h"
 #include "storage/procarray.h"
 #include "storage/read_stream.h"
 #include "utils/builtins.h"
diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h
index 9505701a805..fa68e6ecece 100644
--- a/src/include/storage/lock.h
+++ b/src/include/storage/lock.h
@@ -59,7 +59,7 @@ extern PGDLLIMPORT bool Debug_deadlocks;
  * coding errors from trying to use struct assignment with it; instead use
  * GET_VXID_FROM_PGPROC().
  */
-typedef struct
+typedef struct VirtualTransactionId
 {
 	ProcNumber	procNumber;		/* proc number of the PGPROC */
 	LocalTransactionId localTransactionId;	/* lxid from PGPROC */
diff --git a/src/include/storage/standby.h b/src/include/storage/standby.h
index c63a4f2cc6a..6a314c693cd 100644
--- a/src/include/storage/standby.h
+++ b/src/include/storage/standby.h
@@ -15,10 +15,13 @@
 #define STANDBY_H
 
 #include "datatype/timestamp.h"
-#include "storage/lock.h"
+#include "storage/locktag.h"
 #include "storage/relfilelocator.h"
 #include "storage/standbydefs.h"
 
+typedef struct PGPROC PGPROC;
+typedef struct VirtualTransactionId VirtualTransactionId;
+
 /* User-settable GUC parameters */
 extern PGDLLIMPORT int max_standby_archive_delay;
 extern PGDLLIMPORT int max_standby_streaming_delay;
-- 
2.47.3

>From 1c8324331616a58bd9a14f77cc0bdd68c8e79239 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sun, 22 Mar 2026 17:53:31 +0100
Subject: [PATCH v2 06/15] tablecmds.h doesn't need the full lock.h

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

diff --git a/src/include/commands/tablecmds.h b/src/include/commands/tablecmds.h
index ed38b311ddf..c3d8518cb62 100644
--- a/src/include/commands/tablecmds.h
+++ b/src/include/commands/tablecmds.h
@@ -18,7 +18,7 @@
 #include "catalog/dependency.h"
 #include "catalog/objectaddress.h"
 #include "nodes/parsenodes.h"
-#include "storage/lock.h"
+#include "storage/lockdefs.h"
 #include "utils/relcache.h"
 
 typedef struct AlterTableUtilityContext AlterTableUtilityContext;	/* avoid including
-- 
2.47.3

>From d75283b1aaa586bc2c4965bca5adba5097ebe8db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sun, 22 Mar 2026 17:56:44 +0100
Subject: [PATCH v2 07/15] reloptions.h doesn't need lock.h at all

---
 src/backend/access/common/reloptions.c | 1 +
 src/backend/access/nbtree/nbtutils.c   | 1 +
 src/backend/commands/tablespace.c      | 1 +
 src/backend/utils/cache/relcache.c     | 1 +
 src/include/access/reloptions.h        | 1 -
 5 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c
index 237ab8d0ed9..a6002ae9b07 100644
--- a/src/backend/access/common/reloptions.c
+++ b/src/backend/access/common/reloptions.c
@@ -28,6 +28,7 @@
 #include "commands/defrem.h"
 #include "commands/tablespace.h"
 #include "nodes/makefuncs.h"
+#include "storage/lock.h"
 #include "utils/array.h"
 #include "utils/attoptcache.h"
 #include "utils/builtins.h"
diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c
index 9b091858997..732bc750c9e 100644
--- a/src/backend/access/nbtree/nbtutils.c
+++ b/src/backend/access/nbtree/nbtutils.c
@@ -24,6 +24,7 @@
 #include "common/int.h"
 #include "lib/qunique.h"
 #include "miscadmin.h"
+#include "storage/lwlock.h"
 #include "utils/datum.h"
 #include "utils/lsyscache.h"
 #include "utils/rel.h"
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index ed2a93a09db..d91fcf0facf 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -70,6 +70,7 @@
 #include "miscadmin.h"
 #include "postmaster/bgwriter.h"
 #include "storage/fd.h"
+#include "storage/lwlock.h"
 #include "storage/procsignal.h"
 #include "storage/standby.h"
 #include "utils/acl.h"
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 3a4f19e8d58..e19f0d3e51c 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -77,6 +77,7 @@
 #include "rewrite/rowsecurity.h"
 #include "storage/fd.h"
 #include "storage/lmgr.h"
+#include "storage/lock.h"
 #include "storage/smgr.h"
 #include "utils/array.h"
 #include "utils/builtins.h"
diff --git a/src/include/access/reloptions.h b/src/include/access/reloptions.h
index 0bd17b30ca7..c228147420a 100644
--- a/src/include/access/reloptions.h
+++ b/src/include/access/reloptions.h
@@ -23,7 +23,6 @@
 #include "access/htup.h"
 #include "access/tupdesc.h"
 #include "nodes/pg_list.h"
-#include "storage/lock.h"
 
 /* types supported by reloptions */
 typedef enum relopt_type
-- 
2.47.3

>From 7fa919aceab47698cf50e3b3a01ec17199f93a7e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sun, 22 Mar 2026 17:59:33 +0100
Subject: [PATCH v2 08/15] predicate.h almost doesn't need lock.h

---
 src/backend/access/heap/heapam_handler.c | 1 +
 src/backend/access/index/indexam.c       | 1 +
 src/include/storage/predicate.h          | 7 ++++++-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 253a735b6c1..d40878928e1 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -40,6 +40,7 @@
 #include "storage/bufmgr.h"
 #include "storage/bufpage.h"
 #include "storage/lmgr.h"
+#include "storage/lock.h"
 #include "storage/predicate.h"
 #include "storage/procarray.h"
 #include "storage/smgr.h"
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index 5eb7e99ad3e..fbfc33159eb 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -53,6 +53,7 @@
 #include "nodes/execnodes.h"
 #include "pgstat.h"
 #include "storage/lmgr.h"
+#include "storage/lock.h"
 #include "storage/predicate.h"
 #include "utils/ruleutils.h"
 #include "utils/snapmgr.h"
diff --git a/src/include/storage/predicate.h b/src/include/storage/predicate.h
index 607d7d84596..a5ac55b8f7e 100644
--- a/src/include/storage/predicate.h
+++ b/src/include/storage/predicate.h
@@ -14,11 +14,16 @@
 #ifndef PREDICATE_H
 #define PREDICATE_H
 
+#include "access/transam.h"
 #include "storage/itemptr.h"
-#include "storage/lock.h"
 #include "utils/relcache.h"
 #include "utils/snapshot.h"
 
+/*
+ * forward references in this file
+ */
+typedef struct VirtualTransactionId VirtualTransactionId;
+
 
 /*
  * GUC variables
-- 
2.47.3

>From 55903301eb5fccb5ce0fd2260a8d123e72c16951 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sun, 22 Mar 2026 19:29:21 +0100
Subject: [PATCH v2 09/15] twophase.h can mostly do without lock.h

---
 src/include/access/twophase.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/include/access/twophase.h b/src/include/access/twophase.h
index e312514ba87..b762170a041 100644
--- a/src/include/access/twophase.h
+++ b/src/include/access/twophase.h
@@ -17,7 +17,12 @@
 #include "access/xact.h"
 #include "access/xlogdefs.h"
 #include "datatype/timestamp.h"
-#include "storage/lock.h"
+
+/*
+ * forward references in this file
+ */
+typedef struct VirtualTransactionId VirtualTransactionId;
+typedef struct PGPROC PGPROC;
 
 /*
  * GlobalTransactionData is defined in twophase.c; other places have no
-- 
2.47.3

>From c43b71fdd3c18d804b23bb227d8b559091be010d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sun, 22 Mar 2026 19:30:40 +0100
Subject: [PATCH v2 10/15] sinvaladt.h doesn't need lock.h at all

---
 src/include/storage/sinvaladt.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/include/storage/sinvaladt.h b/src/include/storage/sinvaladt.h
index a1694500a85..122dbcdf19f 100644
--- a/src/include/storage/sinvaladt.h
+++ b/src/include/storage/sinvaladt.h
@@ -22,7 +22,6 @@
 #ifndef SINVALADT_H
 #define SINVALADT_H
 
-#include "storage/lock.h"
 #include "storage/sinval.h"
 
 /*
-- 
2.47.3

>From be0d5febb3865ce0204ec4fb53f24bde9955bf6f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sun, 22 Mar 2026 19:32:01 +0100
Subject: [PATCH v2 11/15] replication/worker_internal.h doesn't need lock.h at
 all

---
 src/backend/replication/logical/sequencesync.c | 1 +
 src/include/replication/worker_internal.h      | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/replication/logical/sequencesync.c b/src/backend/replication/logical/sequencesync.c
index 9c92fddd624..a4fb6783ba9 100644
--- a/src/backend/replication/logical/sequencesync.c
+++ b/src/backend/replication/logical/sequencesync.c
@@ -60,6 +60,7 @@
 #include "postmaster/interrupt.h"
 #include "replication/logicalworker.h"
 #include "replication/worker_internal.h"
+#include "storage/lwlock.h"
 #include "utils/acl.h"
 #include "utils/builtins.h"
 #include "utils/fmgroids.h"
diff --git a/src/include/replication/worker_internal.h b/src/include/replication/worker_internal.h
index 4ecbdcfadac..745b7d9e969 100644
--- a/src/include/replication/worker_internal.h
+++ b/src/include/replication/worker_internal.h
@@ -20,7 +20,6 @@
 #include "replication/walreceiver.h"
 #include "storage/buffile.h"
 #include "storage/fileset.h"
-#include "storage/lock.h"
 #include "storage/shm_mq.h"
 #include "storage/shm_toc.h"
 #include "storage/spin.h"
-- 
2.47.3

>From 230bfb7ffbb241b561d02ae2055227c640ac2ae3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sun, 22 Mar 2026 19:33:09 +0100
Subject: [PATCH v2 12/15] cluster.h can do with just lockdefs.h

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

diff --git a/src/include/commands/cluster.h b/src/include/commands/cluster.h
index 28741988478..c79cd2d0e19 100644
--- a/src/include/commands/cluster.h
+++ b/src/include/commands/cluster.h
@@ -15,7 +15,7 @@
 
 #include "nodes/parsenodes.h"
 #include "parser/parse_node.h"
-#include "storage/lock.h"
+#include "storage/lockdefs.h"
 #include "utils/relcache.h"
 
 
-- 
2.47.3

>From e063f8e6cfcef798c9873d1fe7b2a4fd29c0892c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sun, 22 Mar 2026 19:33:48 +0100
Subject: [PATCH v2 13/15] toasting.h only needs lockdefs.h

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

diff --git a/src/include/catalog/toasting.h b/src/include/catalog/toasting.h
index 7e0a9f8e9bf..0bc61a8fee9 100644
--- a/src/include/catalog/toasting.h
+++ b/src/include/catalog/toasting.h
@@ -14,7 +14,7 @@
 #ifndef TOASTING_H
 #define TOASTING_H
 
-#include "storage/lock.h"
+#include "storage/lockdefs.h"
 
 /*
  * toasting.c prototypes
-- 
2.47.3

>From a081c57217d6eb3beb418debc31bd016132da4a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sun, 22 Mar 2026 19:39:18 +0100
Subject: [PATCH v2 14/15] pg_inherits.h doesn't need the full lock.h

---
 src/backend/catalog/pg_inherits.c    | 1 +
 src/backend/optimizer/util/inherit.c | 2 ++
 src/include/catalog/pg_inherits.h    | 2 +-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/backend/catalog/pg_inherits.c b/src/backend/catalog/pg_inherits.c
index cef80633157..4b9802aafcc 100644
--- a/src/backend/catalog/pg_inherits.c
+++ b/src/backend/catalog/pg_inherits.c
@@ -28,6 +28,7 @@
 #include "storage/lmgr.h"
 #include "utils/builtins.h"
 #include "utils/fmgroids.h"
+#include "utils/hsearch.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
 
diff --git a/src/backend/optimizer/util/inherit.c b/src/backend/optimizer/util/inherit.c
index 8d623bf136d..6a7b9edff3f 100644
--- a/src/backend/optimizer/util/inherit.c
+++ b/src/backend/optimizer/util/inherit.c
@@ -14,6 +14,8 @@
  */
 #include "postgres.h"
 
+#include <limits.h>
+
 #include "access/sysattr.h"
 #include "access/table.h"
 #include "catalog/partition.h"
diff --git a/src/include/catalog/pg_inherits.h b/src/include/catalog/pg_inherits.h
index 7a36241d7b3..cc874abaabb 100644
--- a/src/include/catalog/pg_inherits.h
+++ b/src/include/catalog/pg_inherits.h
@@ -22,7 +22,7 @@
 #include "catalog/pg_inherits_d.h"	/* IWYU pragma: export */
 
 #include "nodes/pg_list.h"
-#include "storage/lock.h"
+#include "storage/lockdefs.h"
 
 /* ----------------
  *		pg_inherits definition.  cpp turns this into
-- 
2.47.3

>From e7f84cac2e77a4aa8d1c9b878aabf09e754494ea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <[email protected]>
Date: Sun, 22 Mar 2026 19:42:23 +0100
Subject: [PATCH v2 15/15] avoid including clog.h in proc.h

---
 src/backend/storage/lmgr/proc.c | 1 +
 src/include/storage/proc.h      | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index 8f5ce0e2a8a..1d389cf60ec 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -33,6 +33,7 @@
 #include <unistd.h>
 #include <sys/time.h>
 
+#include "access/clog.h"
 #include "access/transam.h"
 #include "access/twophase.h"
 #include "access/xlogutils.h"
diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h
index bf3094f0f7d..1dad125706e 100644
--- a/src/include/storage/proc.h
+++ b/src/include/storage/proc.h
@@ -14,7 +14,6 @@
 #ifndef _PROC_H_
 #define _PROC_H_
 
-#include "access/clog.h"
 #include "access/xlogdefs.h"
 #include "lib/ilist.h"
 #include "miscadmin.h"
@@ -24,6 +23,9 @@
 #include "storage/proclist_types.h"
 #include "storage/procnumber.h"
 
+/* Avoid including clog.h here */
+typedef int XidStatus;
+
 /*
  * Each backend advertises up to PGPROC_MAX_CACHED_SUBXIDS TransactionIds
  * for non-aborted subtransactions of its current top transaction.  These
-- 
2.47.3

Reply via email to