pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgstat include expansion
33+ messages / 7 participants
[nested] [flat]

* pgstat include expansion
@ 2026-02-13 22:14 Andres Freund <andres@anarazel.de>
  2026-02-15 23:19 ` Re: pgstat include expansion Chao Li <li.evan.chao@gmail.com>
  2026-02-16 04:36 ` Re: pgstat include expansion Michael Paquier <michael@paquier.xyz>
  2026-02-16 07:48 ` Re: pgstat include expansion Nisha Moond <nisha.moond412@gmail.com>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 12:55 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  0 siblings, 5 replies; 33+ messages in thread

From: Andres Freund @ 2026-02-13 22:14 UTC (permalink / raw)
  To: pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Alvaro Herrera <alvherre@kurilemu.de>; Michael Paquier <michael@paquier.xyz>

Hi,

A few recent-ish changes have substantially expanded the set of headers
included in pgstat.h.  As pgstat.h is pretty widely included, that strikes me
as bad.

commit f6a4c498dcf
Author: Amit Kapila <akapila@postgresql.org>
Date:   2025-11-07 08:05:08 +0000
 
    Add seq_sync_error_count to subscription statistics.

added an include of replication/worker_internal.h, which in turn includes a
lot of other headers.  It's also seems somewhat obvious that a header named
_internal.h shouldn't be included in something as widely included as pgstat.h


commit 7e638d7f509
Author: Álvaro Herrera <alvherre@kurilemu.de>
Date:   2025-09-25 14:45:08 +0200
 
    Don't include execnodes.h in replication/conflict.h

added an include of access/transam.h, which I don't love being included,
although it's less bad than some of the other cases. It's not actually to
blame for that though, as it shrank what was included noticeably.


commit 6c2b5edecc0
Author: Amit Kapila <akapila@postgresql.org>
Date:   2024-09-04 08:55:21 +0530
 
    Collect statistics about conflicts in logical replication.

added an include of conflict.h, which in turn includes utils/timestamp.h,
which includes fmgr.h (and a lot more, before 7e638d7f509).


I think now that we rely on C11, we actually could also forward-declare enum
typedefs. That would allow us to avoid including
worker_internal.h. Unfortunately I think C++ might throw a wrench in the mix
for that - IIUC it only allows forward declaring enums when using 'enum
class', but I don't think we can rely on that.  I think the best solution
would be to move the typedef to a more suitable header, but baring that, I
guess just passing an int would do.


By forward declaring FullTransactionId, we can avoid including
access/transam.h


conflict.h includes utils/timestamp.h, even though it only needs the
types. Using datatype/timestamp.h suffices (although it requires some fixups
elsewhere).


conflict.h includes nodes/pg_list.h, which does in turn include nodes/nodes.h,
which, while not the worst, seems unnecessary.  Another forward declaration
solves that.


The attached patch is just a prototype.


I also don't like that pgstat.h includes backend_status.h, which includes
things like pqcomm.h and miscadmin.h. But that's - leaving some moving around
aside - of a lot longer standing.  We probably should move BackendType out of
miscadmin.h one of these days.  Not sure what to do about the pqcomm.h
include...


Greetings,

Andres Freund

Attachments:

  [text/x-diff] v1-0001-WIP-Reduce-includes-in-pgstat.h.patch (6.6K, ../../aY-UE-4t7FiYgH3t@alap3.anarazel.de/2-v1-0001-WIP-Reduce-includes-in-pgstat.h.patch)
  download | inline diff:
From 92d8e460c4f65f8fca735d90f02fb128f53abeef Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Fri, 13 Feb 2026 17:05:15 -0500
Subject: [PATCH v1] WIP: Reduce includes in pgstat.h

---
 src/include/pgstat.h                                | 13 +++++++------
 src/include/replication/conflict.h                  |  5 +++--
 src/backend/commands/functioncmds.c                 |  1 +
 src/backend/executor/execReplication.c              |  1 +
 src/backend/replication/logical/conflict.c          |  1 +
 src/backend/storage/ipc/procsignal.c                |  1 +
 src/backend/utils/activity/pgstat_subscription.c    |  4 ++--
 .../test_custom_stats/test_custom_fixed_stats.c     |  2 +-
 .../test_custom_stats/test_custom_var_stats.c       |  1 +
 9 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index fff7ecc2533..a2021a0e66f 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -11,18 +11,20 @@
 #ifndef PGSTAT_H
 #define PGSTAT_H
 
-#include "access/transam.h"		/* for FullTransactionId */
 #include "datatype/timestamp.h"
 #include "portability/instr_time.h"
 #include "postmaster/pgarch.h"	/* for MAX_XFN_CHARS */
-#include "replication/conflict.h"
-#include "replication/worker_internal.h"
+#include "replication/conflict.h"	/* for CONFLICT_NUM_TYPES */
 #include "utils/backend_progress.h" /* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/backend_status.h"	/* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/pgstat_kind.h"
-#include "utils/relcache.h"
 #include "utils/wait_event.h"	/* for backward compatibility */	/* IWYU pragma: export */
 
+/* to avoid including access/transam.h, for FullTransactionId */
+typedef struct FullTransactionId FullTransactionId;
+
+/* to avoid including utils/relcache.h */
+typedef struct RelationData *Relation;
 
 /* ----------
  * Paths for the statistics files (relative to installation's $PGDATA).
@@ -775,8 +777,7 @@ extern PgStat_SLRUStats *pgstat_fetch_slru(void);
  * Functions in pgstat_subscription.c
  */
 
-extern void pgstat_report_subscription_error(Oid subid,
-											 LogicalRepWorkerType wtype);
+extern void pgstat_report_subscription_error(Oid subid, int wtype);
 extern void pgstat_report_subscription_conflict(Oid subid, ConflictType type);
 extern void pgstat_create_subscription(Oid subid);
 extern void pgstat_drop_subscription(Oid subid);
diff --git a/src/include/replication/conflict.h b/src/include/replication/conflict.h
index 1cade336c91..4e1a8a2303f 100644
--- a/src/include/replication/conflict.h
+++ b/src/include/replication/conflict.h
@@ -10,14 +10,15 @@
 #define CONFLICT_H
 
 #include "access/xlogdefs.h"
-#include "nodes/pg_list.h"
-#include "utils/timestamp.h"
+#include "datatype/timestamp.h"
 
 /* Avoid including execnodes.h here */
 typedef struct EState EState;
 typedef struct ResultRelInfo ResultRelInfo;
 typedef struct TupleTableSlot TupleTableSlot;
 
+/* To avoid including pg_list.h */
+typedef struct List List;
 
 /*
  * Conflict types that could occur while applying remote changes.
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index a516b037dea..242372b1e68 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -34,6 +34,7 @@
 
 #include "access/htup_details.h"
 #include "access/table.h"
+#include "access/xact.h"
 #include "catalog/catalog.h"
 #include "catalog/dependency.h"
 #include "catalog/indexing.h"
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 743b1ee2b28..c1007c1b41b 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -27,6 +27,7 @@
 #include "commands/trigger.h"
 #include "executor/executor.h"
 #include "executor/nodeModifyTable.h"
+#include "nodes/pg_list.h"
 #include "replication/conflict.h"
 #include "replication/logicalrelation.h"
 #include "storage/lmgr.h"
diff --git a/src/backend/replication/logical/conflict.c b/src/backend/replication/logical/conflict.c
index ca71a81c7bf..73cca04ffa5 100644
--- a/src/backend/replication/logical/conflict.c
+++ b/src/backend/replication/logical/conflict.c
@@ -17,6 +17,7 @@
 #include "access/commit_ts.h"
 #include "access/tableam.h"
 #include "executor/executor.h"
+#include "nodes/pg_list.h"
 #include "pgstat.h"
 #include "replication/conflict.h"
 #include "replication/worker_internal.h"
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index 5d33559926a..4e32a29766c 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -23,6 +23,7 @@
 #include "pgstat.h"
 #include "port/pg_bitutils.h"
 #include "replication/logicalworker.h"
+#include "replication/logicalctl.h"
 #include "replication/walsender.h"
 #include "storage/condition_variable.h"
 #include "storage/ipc.h"
diff --git a/src/backend/utils/activity/pgstat_subscription.c b/src/backend/utils/activity/pgstat_subscription.c
index 500b1899188..adeff040075 100644
--- a/src/backend/utils/activity/pgstat_subscription.c
+++ b/src/backend/utils/activity/pgstat_subscription.c
@@ -25,7 +25,7 @@
  * Report a subscription error.
  */
 void
-pgstat_report_subscription_error(Oid subid, LogicalRepWorkerType wtype)
+pgstat_report_subscription_error(Oid subid, int wtype)
 {
 	PgStat_EntryRef *entry_ref;
 	PgStat_BackendSubEntry *pending;
@@ -34,7 +34,7 @@ pgstat_report_subscription_error(Oid subid, LogicalRepWorkerType wtype)
 										  InvalidOid, subid, NULL);
 	pending = entry_ref->pending;
 
-	switch (wtype)
+	switch ((LogicalRepWorkerType) wtype)
 	{
 		case WORKERTYPE_APPLY:
 			pending->apply_error_count++;
diff --git a/src/test/modules/test_custom_stats/test_custom_fixed_stats.c b/src/test/modules/test_custom_stats/test_custom_fixed_stats.c
index 908bd18a7c7..fb74f3dc5ad 100644
--- a/src/test/modules/test_custom_stats/test_custom_fixed_stats.c
+++ b/src/test/modules/test_custom_stats/test_custom_fixed_stats.c
@@ -16,8 +16,8 @@
 #include "access/htup_details.h"
 #include "funcapi.h"
 #include "pgstat.h"
-#include "utils/builtins.h"
 #include "utils/pgstat_internal.h"
+#include "utils/timestamp.h"
 
 PG_MODULE_MAGIC_EXT(
 					.name = "test_custom_fixed_stats",
diff --git a/src/test/modules/test_custom_stats/test_custom_var_stats.c b/src/test/modules/test_custom_stats/test_custom_var_stats.c
index 64a8fe63cce..da28afbd929 100644
--- a/src/test/modules/test_custom_stats/test_custom_var_stats.c
+++ b/src/test/modules/test_custom_stats/test_custom_var_stats.c
@@ -12,6 +12,7 @@
  */
 #include "postgres.h"
 
+#include "access/htup_details.h"
 #include "common/hashfn.h"
 #include "funcapi.h"
 #include "storage/dsm_registry.h"
-- 
2.46.0.519.g2e7b89e038

^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
@ 2026-02-15 23:19 ` Chao Li <li.evan.chao@gmail.com>
  2026-02-16 05:35   ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  4 siblings, 1 reply; 33+ messages in thread

From: Chao Li @ 2026-02-15 23:19 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Alvaro Herrera <alvherre@kurilemu.de>; Michael Paquier <michael@paquier.xyz>



> On Feb 14, 2026, at 06:14, Andres Freund <andres@anarazel.de> wrote:
> 
> Hi,
> 
> A few recent-ish changes have substantially expanded the set of headers
> included in pgstat.h.  As pgstat.h is pretty widely included, that strikes me
> as bad.
> 
> commit f6a4c498dcf
> Author: Amit Kapila <akapila@postgresql.org>
> Date:   2025-11-07 08:05:08 +0000
> 
>    Add seq_sync_error_count to subscription statistics.
> 
> added an include of replication/worker_internal.h, which in turn includes a
> lot of other headers.  It's also seems somewhat obvious that a header named
> _internal.h shouldn't be included in something as widely included as pgstat.h
> 
> 
> commit 7e638d7f509
> Author: Álvaro Herrera <alvherre@kurilemu.de>
> Date:   2025-09-25 14:45:08 +0200
> 
>    Don't include execnodes.h in replication/conflict.h
> 
> added an include of access/transam.h, which I don't love being included,
> although it's less bad than some of the other cases. It's not actually to
> blame for that though, as it shrank what was included noticeably.
> 
> 
> commit 6c2b5edecc0
> Author: Amit Kapila <akapila@postgresql.org>
> Date:   2024-09-04 08:55:21 +0530
> 
>    Collect statistics about conflicts in logical replication.
> 
> added an include of conflict.h, which in turn includes utils/timestamp.h,
> which includes fmgr.h (and a lot more, before 7e638d7f509).
> 
> 
> I think now that we rely on C11, we actually could also forward-declare enum
> typedefs. That would allow us to avoid including
> worker_internal.h. Unfortunately I think C++ might throw a wrench in the mix
> for that - IIUC it only allows forward declaring enums when using 'enum
> class', but I don't think we can rely on that.  I think the best solution
> would be to move the typedef to a more suitable header, but baring that, I
> guess just passing an int would do.
> 
> 
> By forward declaring FullTransactionId, we can avoid including
> access/transam.h
> 
> 
> conflict.h includes utils/timestamp.h, even though it only needs the
> types. Using datatype/timestamp.h suffices (although it requires some fixups
> elsewhere).
> 
> 
> conflict.h includes nodes/pg_list.h, which does in turn include nodes/nodes.h,
> which, while not the worst, seems unnecessary.  Another forward declaration
> solves that.
> 
> 
> The attached patch is just a prototype.
> 
> 
> I also don't like that pgstat.h includes backend_status.h, which includes
> things like pqcomm.h and miscadmin.h. But that's - leaving some moving around
> aside - of a lot longer standing.  We probably should move BackendType out of
> miscadmin.h one of these days.  Not sure what to do about the pqcomm.h
> include...
> 
> 
> Greetings,
> 
> Andres Freund
> <v1-0001-WIP-Reduce-includes-in-pgstat.h.patch>

```
-pgstat_report_subscription_error(Oid subid, LogicalRepWorkerType wtype)
+pgstat_report_subscription_error(Oid subid, int wtype)
```

I am not a fan of changing LogicalRepWorkerType to int that feels like an unnecessary trade-off. LogicalRepWorkerType is defined in worker_internal.h, but as it’s used in pg_stat, it isn't “internal” anymore. So, maybe we should move the enum to a new worker_types.h and include that instead?

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/









^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-15 23:19 ` Re: pgstat include expansion Chao Li <li.evan.chao@gmail.com>
@ 2026-02-16 05:35   ` Amit Kapila <amit.kapila16@gmail.com>
  2026-02-16 05:47     ` Re: pgstat include expansion vignesh C <vignesh21@gmail.com>
  2026-02-16 07:59     ` Re: pgstat include expansion Michael Paquier <michael@paquier.xyz>
  2026-02-16 16:32     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  0 siblings, 3 replies; 33+ messages in thread

From: Amit Kapila @ 2026-02-16 05:35 UTC (permalink / raw)
  To: Chao Li <li.evan.chao@gmail.com>; +Cc: Andres Freund <andres@anarazel.de>; pgsql-hackers@postgresql.org, Alvaro Herrera <alvherre@kurilemu.de>; Michael Paquier <michael@paquier.xyz>

On Mon, Feb 16, 2026 at 4:49 AM Chao Li <li.evan.chao@gmail.com> wrote:
>
> > On Feb 14, 2026, at 06:14, Andres Freund <andres@anarazel.de> wrote:
> >
> > Hi,
> >
> > A few recent-ish changes have substantially expanded the set of headers
> > included in pgstat.h.  As pgstat.h is pretty widely included, that strikes me
> > as bad.
> >
> > commit f6a4c498dcf
> > Author: Amit Kapila <akapila@postgresql.org>
> > Date:   2025-11-07 08:05:08 +0000
> >
> >    Add seq_sync_error_count to subscription statistics.
> >
> > added an include of replication/worker_internal.h, which in turn includes a
> > lot of other headers.  It's also seems somewhat obvious that a header named
> > _internal.h shouldn't be included in something as widely included as pgstat.h
> >
> >
>
> ```
> -pgstat_report_subscription_error(Oid subid, LogicalRepWorkerType wtype)
> +pgstat_report_subscription_error(Oid subid, int wtype)
> ```
>
> I am not a fan of changing LogicalRepWorkerType to int that feels like an unnecessary trade-off. LogicalRepWorkerType is defined in worker_internal.h, but as it’s used in pg_stat, it isn't “internal” anymore. So, maybe we should move the enum to a new worker_types.h and include that instead?
>

How about moving LogicalRepWorkerType to logicalworker.h as in the
attached and then include that in pgstat.h? This requires few other
adjustments as previously some of the includes were working indirectly
via worker_internal.h.

Fixed few warnings via different includes after the above change:
*
procsignal.c: In function ‘ProcessProcSignalBarrier’:
procsignal.c:580:61: warning: implicit declaration of function
‘ProcessBarrierUpdateXLogLogicalInfo’
[-Wimplicit-function-declaration]
  580 |                                                 processed =
ProcessBarrierUpdateXLogLogicalInfo();
      |
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This warning appears because ProcessBarrierUpdateXLogLogicalInfo
declaration present in logicalctl.h was included in procsignal.c
through pgstat.h-
>worker_internal->walreceiver.h->xlog.h->logicalctl.h. Since the proposed patch removes worker_internal.h from pgstat.h this warning appears. For this, we need to include logicalctl.h in procsignal.c.

*
functioncmds.c: In function ‘compute_return_type’:
functioncmds.c:157:17: warning: implicit declaration of function
‘CommandCounterIncrement’ [-Wimplicit-function-declaration]
  157 |                 CommandCounterIncrement();


This warning appears because CommandCounterIncrement declaration
present in xact.h was getting included in functioncmds.c through
pgstat.h->worker_internal.h->logicalrelation.h->logicalproto.h->xact.h.
to fix this, we need to include "access/xact.h" in functioncmds.c.

*
On Windows:
[68/196] Compiling C object
src/test/modules/test_custom_stats/test_custom_var_stats.dll.p/test_custom_var_stats.c.obj
../src/test/modules/test_custom_stats/test_custom_var_stats.c(685):
warning C4047: '=': 'HeapTuple' differs in levels of indirection from
'int'

Previously HeapTuple seems to be detected via
pgstat_internal.h->pgstat.h->worker_internal.h->logicalrelation.h->index.h->execnodes.h->tupconvert.h->htup.h.
To fix, we need to include htup_details.h in test_custom_var_stats.c
similar to test_custom_fixed_stats.c.

-- 
With Regards,
Amit Kapila.

Attachments:

  [application/octet-stream] v1-0001-fix-header-inclusion.patch (4.5K, ../../CAA4eK1+ZOXJotnk+d4mxHFP_i2SEWGTdyJgkQadOCvMgEcPGVg@mail.gmail.com/2-v1-0001-fix-header-inclusion.patch)
  download | inline diff:
From 20d281f294fec26aa962c38f777dd1e8e36cb53e Mon Sep 17 00:00:00 2001
From: Amit Kapila <akapila@postgresql.org>
Date: Mon, 16 Feb 2026 09:29:23 +0530
Subject: [PATCH v1] fix header inclusion.

---
 src/backend/commands/functioncmds.c                   |  1 +
 src/backend/storage/ipc/procsignal.c                  |  1 +
 src/backend/utils/activity/pgstat_subscription.c      |  2 +-
 src/include/pgstat.h                                  |  2 +-
 src/include/replication/logicalworker.h               | 10 ++++++++++
 src/include/replication/worker_internal.h             | 11 +----------
 .../modules/test_custom_stats/test_custom_var_stats.c |  1 +
 7 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index a516b037dea..bcac267b78c 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -32,6 +32,7 @@
  */
 #include "postgres.h"
 
+#include "access/xact.h"
 #include "access/htup_details.h"
 #include "access/table.h"
 #include "catalog/catalog.h"
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index 5d33559926a..7505c9d3a37 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -22,6 +22,7 @@
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "port/pg_bitutils.h"
+#include "replication/logicalctl.h"
 #include "replication/logicalworker.h"
 #include "replication/walsender.h"
 #include "storage/condition_variable.h"
diff --git a/src/backend/utils/activity/pgstat_subscription.c b/src/backend/utils/activity/pgstat_subscription.c
index 500b1899188..8e97ef4c6e1 100644
--- a/src/backend/utils/activity/pgstat_subscription.c
+++ b/src/backend/utils/activity/pgstat_subscription.c
@@ -17,7 +17,7 @@
 
 #include "postgres.h"
 
-#include "replication/worker_internal.h"
+#include "replication/logicalworker.h"
 #include "utils/pgstat_internal.h"
 
 
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index fff7ecc2533..1af49ed144d 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -16,7 +16,7 @@
 #include "portability/instr_time.h"
 #include "postmaster/pgarch.h"	/* for MAX_XFN_CHARS */
 #include "replication/conflict.h"
-#include "replication/worker_internal.h"
+#include "replication/logicalworker.h"
 #include "utils/backend_progress.h" /* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/backend_status.h"	/* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/pgstat_kind.h"
diff --git a/src/include/replication/logicalworker.h b/src/include/replication/logicalworker.h
index 7d748a28da8..822349f5126 100644
--- a/src/include/replication/logicalworker.h
+++ b/src/include/replication/logicalworker.h
@@ -16,6 +16,16 @@
 
 extern PGDLLIMPORT volatile sig_atomic_t ParallelApplyMessagePending;
 
+/* Different types of worker */
+typedef enum LogicalRepWorkerType
+{
+	WORKERTYPE_UNKNOWN = 0,
+	WORKERTYPE_TABLESYNC,
+	WORKERTYPE_SEQUENCESYNC,
+	WORKERTYPE_APPLY,
+	WORKERTYPE_PARALLEL_APPLY,
+} LogicalRepWorkerType;
+
 extern void ApplyWorkerMain(Datum main_arg);
 extern void ParallelApplyWorkerMain(Datum main_arg);
 extern void TableSyncWorkerMain(Datum main_arg);
diff --git a/src/include/replication/worker_internal.h b/src/include/replication/worker_internal.h
index c1285fdd1bc..9c22b4ba467 100644
--- a/src/include/replication/worker_internal.h
+++ b/src/include/replication/worker_internal.h
@@ -17,6 +17,7 @@
 #include "datatype/timestamp.h"
 #include "miscadmin.h"
 #include "replication/logicalrelation.h"
+#include "replication/logicalworker.h"
 #include "replication/walreceiver.h"
 #include "storage/buffile.h"
 #include "storage/fileset.h"
@@ -25,16 +26,6 @@
 #include "storage/shm_toc.h"
 #include "storage/spin.h"
 
-/* Different types of worker */
-typedef enum LogicalRepWorkerType
-{
-	WORKERTYPE_UNKNOWN = 0,
-	WORKERTYPE_TABLESYNC,
-	WORKERTYPE_SEQUENCESYNC,
-	WORKERTYPE_APPLY,
-	WORKERTYPE_PARALLEL_APPLY,
-} LogicalRepWorkerType;
-
 typedef struct LogicalRepWorker
 {
 	/* What type of worker is this? */
diff --git a/src/test/modules/test_custom_stats/test_custom_var_stats.c b/src/test/modules/test_custom_stats/test_custom_var_stats.c
index 64a8fe63cce..da28afbd929 100644
--- a/src/test/modules/test_custom_stats/test_custom_var_stats.c
+++ b/src/test/modules/test_custom_stats/test_custom_var_stats.c
@@ -12,6 +12,7 @@
  */
 #include "postgres.h"
 
+#include "access/htup_details.h"
 #include "common/hashfn.h"
 #include "funcapi.h"
 #include "storage/dsm_registry.h"
-- 
2.52.0



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-15 23:19 ` Re: pgstat include expansion Chao Li <li.evan.chao@gmail.com>
  2026-02-16 05:35   ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
@ 2026-02-16 05:47     ` vignesh C <vignesh21@gmail.com>
  2 siblings, 0 replies; 33+ messages in thread

From: vignesh C @ 2026-02-16 05:47 UTC (permalink / raw)
  To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Chao Li <li.evan.chao@gmail.com>; Andres Freund <andres@anarazel.de>; pgsql-hackers@postgresql.org, Alvaro Herrera <alvherre@kurilemu.de>; Michael Paquier <michael@paquier.xyz>

On Mon, 16 Feb 2026 at 11:06, Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Mon, Feb 16, 2026 at 4:49 AM Chao Li <li.evan.chao@gmail.com> wrote:
> >
> > > On Feb 14, 2026, at 06:14, Andres Freund <andres@anarazel.de> wrote:
> > >
> > > Hi,
> > >
> > > A few recent-ish changes have substantially expanded the set of headers
> > > included in pgstat.h.  As pgstat.h is pretty widely included, that strikes me
> > > as bad.
> > >
> > > commit f6a4c498dcf
> > > Author: Amit Kapila <akapila@postgresql.org>
> > > Date:   2025-11-07 08:05:08 +0000
> > >
> > >    Add seq_sync_error_count to subscription statistics.
> > >
> > > added an include of replication/worker_internal.h, which in turn includes a
> > > lot of other headers.  It's also seems somewhat obvious that a header named
> > > _internal.h shouldn't be included in something as widely included as pgstat.h
> > >
> > >
> >
> > ```
> > -pgstat_report_subscription_error(Oid subid, LogicalRepWorkerType wtype)
> > +pgstat_report_subscription_error(Oid subid, int wtype)
> > ```
> >
> > I am not a fan of changing LogicalRepWorkerType to int that feels like an unnecessary trade-off. LogicalRepWorkerType is defined in worker_internal.h, but as it’s used in pg_stat, it isn't “internal” anymore. So, maybe we should move the enum to a new worker_types.h and include that instead?
> >
>
> How about moving LogicalRepWorkerType to logicalworker.h as in the
> attached and then include that in pgstat.h? This requires few other
> adjustments as previously some of the includes were working indirectly
> via worker_internal.h.
>
> Fixed few warnings via different includes after the above change:
> *
> procsignal.c: In function ‘ProcessProcSignalBarrier’:
> procsignal.c:580:61: warning: implicit declaration of function
> ‘ProcessBarrierUpdateXLogLogicalInfo’
> [-Wimplicit-function-declaration]
>   580 |                                                 processed =
> ProcessBarrierUpdateXLogLogicalInfo();
>       |
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> This warning appears because ProcessBarrierUpdateXLogLogicalInfo
> declaration present in logicalctl.h was included in procsignal.c
> through pgstat.h-
> >worker_internal->walreceiver.h->xlog.h->logicalctl.h. Since the proposed patch removes worker_internal.h from pgstat.h this warning appears. For this, we need to include logicalctl.h in procsignal.c.
>
> *
> functioncmds.c: In function ‘compute_return_type’:
> functioncmds.c:157:17: warning: implicit declaration of function
> ‘CommandCounterIncrement’ [-Wimplicit-function-declaration]
>   157 |                 CommandCounterIncrement();
>
>
> This warning appears because CommandCounterIncrement declaration
> present in xact.h was getting included in functioncmds.c through
> pgstat.h->worker_internal.h->logicalrelation.h->logicalproto.h->xact.h.
> to fix this, we need to include "access/xact.h" in functioncmds.c.
>
> *
> On Windows:
> [68/196] Compiling C object
> src/test/modules/test_custom_stats/test_custom_var_stats.dll.p/test_custom_var_stats.c.obj
> ../src/test/modules/test_custom_stats/test_custom_var_stats.c(685):
> warning C4047: '=': 'HeapTuple' differs in levels of indirection from
> 'int'
>
> Previously HeapTuple seems to be detected via
> pgstat_internal.h->pgstat.h->worker_internal.h->logicalrelation.h->index.h->execnodes.h->tupconvert.h->htup.h.
> To fix, we need to include htup_details.h in test_custom_var_stats.c
> similar to test_custom_fixed_stats.c.

One small comment, we should include access/xact.h after access/table.h:
diff --git a/src/backend/commands/functioncmds.c
b/src/backend/commands/functioncmds.c
index a516b037dea..bcac267b78c 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -32,6 +32,7 @@
  */
 #include "postgres.h"

+#include "access/xact.h"
 #include "access/htup_details.h"
 #include "access/table.h"
 #include "catalog/catalog.h"

Regards,
Vignesh





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-15 23:19 ` Re: pgstat include expansion Chao Li <li.evan.chao@gmail.com>
  2026-02-16 05:35   ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
@ 2026-02-16 07:59     ` Michael Paquier <michael@paquier.xyz>
  2 siblings, 0 replies; 33+ messages in thread

From: Michael Paquier @ 2026-02-16 07:59 UTC (permalink / raw)
  To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Chao Li <li.evan.chao@gmail.com>; Andres Freund <andres@anarazel.de>; pgsql-hackers@postgresql.org, Alvaro Herrera <alvherre@kurilemu.de>

On Mon, Feb 16, 2026 at 11:05:41AM +0530, Amit Kapila wrote:
> How about moving LogicalRepWorkerType to logicalworker.h as in the
> attached and then include that in pgstat.h? This requires few other
> adjustments as previously some of the includes were working indirectly
> via worker_internal.h.

Yep, this feels much cleaner.  I am not sure we really need to limit
LogicalRepWorkerType to be in an internal header knowing that it is
exposed in the pgstat layer.
--
Michael

Attachments:

  [application/pgp-signature] signature.asc (832B, ../../aZLOdXS-L_D7Nvl6@paquier.xyz/2-signature.asc)
  download

^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-15 23:19 ` Re: pgstat include expansion Chao Li <li.evan.chao@gmail.com>
  2026-02-16 05:35   ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
@ 2026-02-16 16:32     ` Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:50       ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2 siblings, 1 reply; 33+ messages in thread

From: Alvaro Herrera @ 2026-02-16 16:32 UTC (permalink / raw)
  To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Chao Li <li.evan.chao@gmail.com>; Andres Freund <andres@anarazel.de>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>

On 2026-Feb-16, Amit Kapila wrote:

> How about moving LogicalRepWorkerType to logicalworker.h as in the
> attached and then include that in pgstat.h? This requires few other
> adjustments as previously some of the includes were working indirectly
> via worker_internal.h.

Yeah, I think the inclusion of worker_internal.h in pgstat.h is
catastrophic, and the additions of .h files that you propose to fix them
after the removal look OK to me, though I didn't try to compile or run
headerscheck, though you should before pushing.

I'm not sure about including logicalworker.h in pgstat.h though, given
the prototypes you have there ... the logical worker type enum does not
fit together with those IMO.

Maybe it'd be better to add a new file for pgstat_subscription.c and
pgstat.h to use, where this enum lives.  (Maybe something like
src/include/replication/pgstat_worker.h or
src/include/replication/worker_stat.h ?)

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"La espina, desde que nace, ya pincha" (Proverbio africano)





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-15 23:19 ` Re: pgstat include expansion Chao Li <li.evan.chao@gmail.com>
  2026-02-16 05:35   ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  2026-02-16 16:32     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
@ 2026-02-16 17:50       ` Andres Freund <andres@anarazel.de>
  2026-02-17 04:45         ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  0 siblings, 1 reply; 33+ messages in thread

From: Andres Freund @ 2026-02-16 17:50 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@kurilemu.de>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Chao Li <li.evan.chao@gmail.com>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>

Hi,

On 2026-02-16 17:32:27 +0100, Alvaro Herrera wrote:
> On 2026-Feb-16, Amit Kapila wrote:
> 
> > How about moving LogicalRepWorkerType to logicalworker.h as in the
> > attached and then include that in pgstat.h? This requires few other
> > adjustments as previously some of the includes were working indirectly
> > via worker_internal.h.
> 
> Yeah, I think the inclusion of worker_internal.h in pgstat.h is
> catastrophic, and the additions of .h files that you propose to fix them
> after the removal look OK to me, though I didn't try to compile or run
> headerscheck, though you should before pushing.

> I'm not sure about including logicalworker.h in pgstat.h though, given
> the prototypes you have there ... the logical worker type enum does not
> fit together with those IMO.

It sometimes is unavoidable, because of needing to influence the size of an
array or such, but that's not the case here.


> Maybe it'd be better to add a new file for pgstat_subscription.c and
> pgstat.h to use, where this enum lives.  (Maybe something like
> src/include/replication/pgstat_worker.h or
> src/include/replication/worker_stat.h ?)

I think we should simply not pass the worker type. The only reason the worker
type passed is that that is used as a proxy for what kind of error occurred:


/*
 * Report a subscription error.
 */
void
pgstat_report_subscription_error(Oid subid, int wtype)
{
    PgStat_EntryRef *entry_ref;
    PgStat_BackendSubEntry *pending;

    entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_SUBSCRIPTION,
                                          InvalidOid, subid, NULL);
    pending = entry_ref->pending;

    switch ((LogicalRepWorkerType) wtype)
    {
        case WORKERTYPE_APPLY:
            pending->apply_error_count++;
            break;

        case WORKERTYPE_SEQUENCESYNC:
            pending->sync_seq_error_count++;
            break;

        case WORKERTYPE_TABLESYNC:
            pending->sync_table_error_count++;
            break;

        default:
            /* Should never happen. */
            Assert(0);
            break;
    }
}


It doesn't seem like the right thing to have pgstat_subscription.c translate
the worker type to the concrete error this way. Afaict each of the callsites
of pgstat_report_subscription_error() actually knows what kind of error its
reporting, but just uses the worker type to do so.

I'd either change the signature to have one argument for each of the error
types, i.e.
    pgstat_report_subscription_error(int subid,
                                     bool apply_error,
                                     bool sequencesync_error,
                                     bool_tablesync_error);

or split the function into three, and have
    pgstat_report_subscription_{apply,sequence,tablesync}(int subid);


Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-15 23:19 ` Re: pgstat include expansion Chao Li <li.evan.chao@gmail.com>
  2026-02-16 05:35   ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  2026-02-16 16:32     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:50       ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
@ 2026-02-17 04:45         ` Amit Kapila <amit.kapila16@gmail.com>
  2026-02-17 07:00           ` Re: pgstat include expansion Nisha Moond <nisha.moond412@gmail.com>
  0 siblings, 1 reply; 33+ messages in thread

From: Amit Kapila @ 2026-02-17 04:45 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: Alvaro Herrera <alvherre@kurilemu.de>; Chao Li <li.evan.chao@gmail.com>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>

On Mon, Feb 16, 2026 at 11:20 PM Andres Freund <andres@anarazel.de> wrote:
>
> I think we should simply not pass the worker type. The only reason the worker
> type passed is that that is used as a proxy for what kind of error occurred:
>
>
> /*
>  * Report a subscription error.
>  */
> void
> pgstat_report_subscription_error(Oid subid, int wtype)
> {
>     PgStat_EntryRef *entry_ref;
>     PgStat_BackendSubEntry *pending;
>
>     entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_SUBSCRIPTION,
>                                           InvalidOid, subid, NULL);
>     pending = entry_ref->pending;
>
>     switch ((LogicalRepWorkerType) wtype)
>     {
>         case WORKERTYPE_APPLY:
>             pending->apply_error_count++;
>             break;
>
>         case WORKERTYPE_SEQUENCESYNC:
>             pending->sync_seq_error_count++;
>             break;
>
>         case WORKERTYPE_TABLESYNC:
>             pending->sync_table_error_count++;
>             break;
>
>         default:
>             /* Should never happen. */
>             Assert(0);
>             break;
>     }
> }
>
>
> It doesn't seem like the right thing to have pgstat_subscription.c translate
> the worker type to the concrete error this way. Afaict each of the callsites
> of pgstat_report_subscription_error() actually knows what kind of error its
> reporting, but just uses the worker type to do so.
>
> I'd either change the signature to have one argument for each of the error
> types, i.e.
>     pgstat_report_subscription_error(int subid,
>                                      bool apply_error,
>                                      bool sequencesync_error,
>                                      bool_tablesync_error);
>
> or split the function into three, and have
>     pgstat_report_subscription_{apply,sequence,tablesync}(int subid);
>

Good idea. +1 for the second approach to split the function. We can
name them as pgstat_report_subscription_apply_error(int subid),
pgstat_report_subscription_sequence_error(int subid),
pgstat_report_subscription_tablesync_error(int subid).

With Regards,
Amit Kapila.





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-15 23:19 ` Re: pgstat include expansion Chao Li <li.evan.chao@gmail.com>
  2026-02-16 05:35   ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  2026-02-16 16:32     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:50       ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-17 04:45         ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
@ 2026-02-17 07:00           ` Nisha Moond <nisha.moond412@gmail.com>
  2026-02-17 11:14             ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  0 siblings, 1 reply; 33+ messages in thread

From: Nisha Moond @ 2026-02-17 07:00 UTC (permalink / raw)
  To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Andres Freund <andres@anarazel.de>; Alvaro Herrera <alvherre@kurilemu.de>; Chao Li <li.evan.chao@gmail.com>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>

On Tue, Feb 17, 2026 at 10:15 AM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Mon, Feb 16, 2026 at 11:20 PM Andres Freund <andres@anarazel.de> wrote:
> >
> > I think we should simply not pass the worker type. The only reason the worker
> > type passed is that that is used as a proxy for what kind of error occurred:
> >
> >
> > /*
> >  * Report a subscription error.
> >  */
> > void
> > pgstat_report_subscription_error(Oid subid, int wtype)
> > {
> >     PgStat_EntryRef *entry_ref;
> >     PgStat_BackendSubEntry *pending;
> >
> >     entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_SUBSCRIPTION,
> >                                           InvalidOid, subid, NULL);
> >     pending = entry_ref->pending;
> >
> >     switch ((LogicalRepWorkerType) wtype)
> >     {
> >         case WORKERTYPE_APPLY:
> >             pending->apply_error_count++;
> >             break;
> >
> >         case WORKERTYPE_SEQUENCESYNC:
> >             pending->sync_seq_error_count++;
> >             break;
> >
> >         case WORKERTYPE_TABLESYNC:
> >             pending->sync_table_error_count++;
> >             break;
> >
> >         default:
> >             /* Should never happen. */
> >             Assert(0);
> >             break;
> >     }
> > }
> >
> >
> > It doesn't seem like the right thing to have pgstat_subscription.c translate
> > the worker type to the concrete error this way. Afaict each of the callsites
> > of pgstat_report_subscription_error() actually knows what kind of error its
> > reporting, but just uses the worker type to do so.
> >
> > I'd either change the signature to have one argument for each of the error
> > types, i.e.
> >     pgstat_report_subscription_error(int subid,
> >                                      bool apply_error,
> >                                      bool sequencesync_error,
> >                                      bool_tablesync_error);
> >
> > or split the function into three, and have
> >     pgstat_report_subscription_{apply,sequence,tablesync}(int subid);
> >
>
> Good idea. +1 for the second approach to split the function. We can
> name them as pgstat_report_subscription_apply_error(int subid),
> pgstat_report_subscription_sequence_error(int subid),
> pgstat_report_subscription_tablesync_error(int subid).
>
Please find the attached patch implementing the idea. Introduced three
new worker specific functions as suggested and includes a few required
fixups after removing worker_internal.h from pgstat.h, as done earlier
in Amit’s patch [1].

[1] https://www.postgresql.org/message-id/CAA4eK1%2BZOXJotnk%2Bd4mxHFP_i2SEWGTdyJgkQadOCvMgEcPGVg%40mail...
--
Thanks,
Nisha

Attachments:

  [application/octet-stream] v1-0001-Split-pgstat_report_subscription_error-by-worker-.patch (7.7K, ../../CABdArM7LJhPakxsd+sb56HVyLT9Qdk42vUofHVu8gDGLLYPtHQ@mail.gmail.com/2-v1-0001-Split-pgstat_report_subscription_error-by-worker-.patch)
  download | inline diff:
From d331ee8fbc9f8b38c29479cdcf86cf5e3c8590bd Mon Sep 17 00:00:00 2001
From: Nisha Moond <nisha.moond412@gmail.com>
Date: Tue, 17 Feb 2026 12:06:02 +0530
Subject: [PATCH v1] Split pgstat_report_subscription_error by worker type

Refactor the original function into three worker specific functions
instead of passing the worker type to pgstat_report_subscription_*,
which required inclusion of the internal header replication/worker_internal.h.

New functions:
  pgstat_report_subscription_apply_error(int subid)
  pgstat_report_subscription_sequencesync_error(int subid)
  pgstat_report_subscription_tablesync_error(int subid)
---
 src/backend/commands/functioncmds.c           |  1 +
 .../replication/logical/sequencesync.c        |  3 +-
 src/backend/replication/logical/tablesync.c   |  3 +-
 src/backend/replication/logical/worker.c      | 14 +++--
 src/backend/storage/ipc/procsignal.c          |  1 +
 .../utils/activity/pgstat_subscription.c      | 54 +++++++++++--------
 src/include/pgstat.h                          |  7 +--
 .../test_custom_stats/test_custom_var_stats.c |  1 +
 8 files changed, 52 insertions(+), 32 deletions(-)

diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index a516b037dea..242372b1e68 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -34,6 +34,7 @@
 
 #include "access/htup_details.h"
 #include "access/table.h"
+#include "access/xact.h"
 #include "catalog/catalog.h"
 #include "catalog/dependency.h"
 #include "catalog/indexing.h"
diff --git a/src/backend/replication/logical/sequencesync.c b/src/backend/replication/logical/sequencesync.c
index 165f909b3ba..deef43a59ac 100644
--- a/src/backend/replication/logical/sequencesync.c
+++ b/src/backend/replication/logical/sequencesync.c
@@ -750,8 +750,7 @@ start_sequence_sync(void)
 			 * idle state.
 			 */
 			AbortOutOfAnyTransaction();
-			pgstat_report_subscription_error(MySubscription->oid,
-											 WORKERTYPE_SEQUENCESYNC);
+			pgstat_report_subscription_sequencesync_error(MySubscription->oid);
 
 			PG_RE_THROW();
 		}
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index 19a3c21a863..5b92eb0d856 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -1527,8 +1527,7 @@ start_table_sync(XLogRecPtr *origin_startpos, char **slotname)
 			 * idle state.
 			 */
 			AbortOutOfAnyTransaction();
-			pgstat_report_subscription_error(MySubscription->oid,
-											 WORKERTYPE_TABLESYNC);
+			pgstat_report_subscription_tablesync_error(MySubscription->oid);
 
 			PG_RE_THROW();
 		}
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 32725c48623..d718c158a11 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -5606,8 +5606,10 @@ start_apply(XLogRecPtr origin_startpos)
 			 * idle state.
 			 */
 			AbortOutOfAnyTransaction();
-			pgstat_report_subscription_error(MySubscription->oid,
-											 MyLogicalRepWorker->type);
+			if (am_tablesync_worker())
+				pgstat_report_subscription_tablesync_error(MySubscription->oid);
+			else
+				pgstat_report_subscription_apply_error(MySubscription->oid);
 
 			PG_RE_THROW();
 		}
@@ -5960,8 +5962,12 @@ DisableSubscriptionAndExit(void)
 	 * Report the worker failed during sequence synchronization, table
 	 * synchronization, or apply.
 	 */
-	pgstat_report_subscription_error(MyLogicalRepWorker->subid,
-									 MyLogicalRepWorker->type);
+	if (am_tablesync_worker())
+		pgstat_report_subscription_tablesync_error(MySubscription->oid);
+	else if (am_sequencesync_worker())
+		pgstat_report_subscription_sequencesync_error(MySubscription->oid);
+	else
+		pgstat_report_subscription_apply_error(MySubscription->oid);
 
 	/* Disable the subscription */
 	StartTransactionCommand();
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index 5d33559926a..7505c9d3a37 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -22,6 +22,7 @@
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "port/pg_bitutils.h"
+#include "replication/logicalctl.h"
 #include "replication/logicalworker.h"
 #include "replication/walsender.h"
 #include "storage/condition_variable.h"
diff --git a/src/backend/utils/activity/pgstat_subscription.c b/src/backend/utils/activity/pgstat_subscription.c
index 500b1899188..89b5532f7f6 100644
--- a/src/backend/utils/activity/pgstat_subscription.c
+++ b/src/backend/utils/activity/pgstat_subscription.c
@@ -22,10 +22,10 @@
 
 
 /*
- * Report a subscription error.
+ * Report a subscription error for apply worker.
  */
 void
-pgstat_report_subscription_error(Oid subid, LogicalRepWorkerType wtype)
+pgstat_report_subscription_apply_error(Oid subid)
 {
 	PgStat_EntryRef *entry_ref;
 	PgStat_BackendSubEntry *pending;
@@ -34,25 +34,37 @@ pgstat_report_subscription_error(Oid subid, LogicalRepWorkerType wtype)
 										  InvalidOid, subid, NULL);
 	pending = entry_ref->pending;
 
-	switch (wtype)
-	{
-		case WORKERTYPE_APPLY:
-			pending->apply_error_count++;
-			break;
-
-		case WORKERTYPE_SEQUENCESYNC:
-			pending->sync_seq_error_count++;
-			break;
-
-		case WORKERTYPE_TABLESYNC:
-			pending->sync_table_error_count++;
-			break;
-
-		default:
-			/* Should never happen. */
-			Assert(0);
-			break;
-	}
+	pending->apply_error_count++;
+}
+
+/*
+ * Report a subscription error for tablesync worker.
+ */
+void
+pgstat_report_subscription_tablesync_error(Oid subid)
+{
+	PgStat_EntryRef *entry_ref;
+	PgStat_BackendSubEntry *pending;
+
+	entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_SUBSCRIPTION,
+										  InvalidOid, subid, NULL);
+	pending = entry_ref->pending;
+	pending->sync_table_error_count++;
+}
+
+/*
+ * Report a subscription error for sequencesync worker.
+ */
+void
+pgstat_report_subscription_sequencesync_error(Oid subid)
+{
+	PgStat_EntryRef *entry_ref;
+	PgStat_BackendSubEntry *pending;
+
+	entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_SUBSCRIPTION,
+										  InvalidOid, subid, NULL);
+	pending = entry_ref->pending;
+	pending->sync_seq_error_count++;
 }
 
 /*
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index fff7ecc2533..1f9bd6c86c2 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -16,7 +16,6 @@
 #include "portability/instr_time.h"
 #include "postmaster/pgarch.h"	/* for MAX_XFN_CHARS */
 #include "replication/conflict.h"
-#include "replication/worker_internal.h"
 #include "utils/backend_progress.h" /* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/backend_status.h"	/* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/pgstat_kind.h"
@@ -775,8 +774,10 @@ extern PgStat_SLRUStats *pgstat_fetch_slru(void);
  * Functions in pgstat_subscription.c
  */
 
-extern void pgstat_report_subscription_error(Oid subid,
-											 LogicalRepWorkerType wtype);
+extern void pgstat_report_subscription_apply_error(Oid subid);
+extern void pgstat_report_subscription_tablesync_error(Oid subid);
+extern void pgstat_report_subscription_sequencesync_error(Oid subid);
+
 extern void pgstat_report_subscription_conflict(Oid subid, ConflictType type);
 extern void pgstat_create_subscription(Oid subid);
 extern void pgstat_drop_subscription(Oid subid);
diff --git a/src/test/modules/test_custom_stats/test_custom_var_stats.c b/src/test/modules/test_custom_stats/test_custom_var_stats.c
index 64a8fe63cce..da28afbd929 100644
--- a/src/test/modules/test_custom_stats/test_custom_var_stats.c
+++ b/src/test/modules/test_custom_stats/test_custom_var_stats.c
@@ -12,6 +12,7 @@
  */
 #include "postgres.h"
 
+#include "access/htup_details.h"
 #include "common/hashfn.h"
 #include "funcapi.h"
 #include "storage/dsm_registry.h"
-- 
2.50.1 (Apple Git-155)



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-15 23:19 ` Re: pgstat include expansion Chao Li <li.evan.chao@gmail.com>
  2026-02-16 05:35   ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  2026-02-16 16:32     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:50       ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-17 04:45         ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  2026-02-17 07:00           ` Re: pgstat include expansion Nisha Moond <nisha.moond412@gmail.com>
@ 2026-02-17 11:14             ` Amit Kapila <amit.kapila16@gmail.com>
  2026-02-18 04:39               ` Re: pgstat include expansion Nisha Moond <nisha.moond412@gmail.com>
  0 siblings, 1 reply; 33+ messages in thread

From: Amit Kapila @ 2026-02-17 11:14 UTC (permalink / raw)
  To: Nisha Moond <nisha.moond412@gmail.com>; +Cc: Andres Freund <andres@anarazel.de>; Alvaro Herrera <alvherre@kurilemu.de>; Chao Li <li.evan.chao@gmail.com>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>

On Tue, Feb 17, 2026 at 12:30 PM Nisha Moond <nisha.moond412@gmail.com> wrote:
>
> On Tue, Feb 17, 2026 at 10:15 AM Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> > On Mon, Feb 16, 2026 at 11:20 PM Andres Freund <andres@anarazel.de> wrote:
> > >
> > >
> > > It doesn't seem like the right thing to have pgstat_subscription.c translate
> > > the worker type to the concrete error this way. Afaict each of the callsites
> > > of pgstat_report_subscription_error() actually knows what kind of error its
> > > reporting, but just uses the worker type to do so.
> > >
> > > I'd either change the signature to have one argument for each of the error
> > > types, i.e.
> > >     pgstat_report_subscription_error(int subid,
> > >                                      bool apply_error,
> > >                                      bool sequencesync_error,
> > >                                      bool_tablesync_error);
> > >
> > > or split the function into three, and have
> > >     pgstat_report_subscription_{apply,sequence,tablesync}(int subid);
> > >
> >
> > Good idea. +1 for the second approach to split the function. We can
> > name them as pgstat_report_subscription_apply_error(int subid),
> > pgstat_report_subscription_sequence_error(int subid),
> > pgstat_report_subscription_tablesync_error(int subid).
> >
> Please find the attached patch implementing the idea. Introduced three
> new worker specific functions as suggested and includes a few required
> fixups after removing worker_internal.h from pgstat.h, as done earlier
> in Amit’s patch [1].
>

*
@@ -5606,8 +5606,10 @@ start_apply(XLogRecPtr origin_startpos)
  * idle state.
  */
  AbortOutOfAnyTransaction();
- pgstat_report_subscription_error(MySubscription->oid,
- MyLogicalRepWorker->type);
+ if (am_tablesync_worker())
+ pgstat_report_subscription_tablesync_error(MySubscription->oid);
+ else
+ pgstat_report_subscription_apply_error(MySubscription->oid);

  PG_RE_THROW();
  }
@@ -5960,8 +5962,12 @@ DisableSubscriptionAndExit(void)
  * Report the worker failed during sequence synchronization, table
  * synchronization, or apply.
  */
- pgstat_report_subscription_error(MyLogicalRepWorker->subid,
- MyLogicalRepWorker->type);
+ if (am_tablesync_worker())
+ pgstat_report_subscription_tablesync_error(MySubscription->oid);
+ else if (am_sequencesync_worker())
+ pgstat_report_subscription_sequencesync_error(MySubscription->oid);
+ else
+ pgstat_report_subscription_apply_error(MySubscription->oid);

As the worker type is not directly available in all places, the other
possibility is to expose a function like GetLogicalWorkerType from
worker_internal.h and use it directly in
pgstat_report_subscription_error() instead of passing it via
parameter. We can get the worker_type via MyLogicalRepWorker->type
which should be accessible as it will be invoked by one of the logical
replication workers.

-- 
With Regards,
Amit Kapila.





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-15 23:19 ` Re: pgstat include expansion Chao Li <li.evan.chao@gmail.com>
  2026-02-16 05:35   ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  2026-02-16 16:32     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:50       ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-17 04:45         ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  2026-02-17 07:00           ` Re: pgstat include expansion Nisha Moond <nisha.moond412@gmail.com>
  2026-02-17 11:14             ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
@ 2026-02-18 04:39               ` Nisha Moond <nisha.moond412@gmail.com>
  2026-02-19 04:46                 ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  0 siblings, 1 reply; 33+ messages in thread

From: Nisha Moond @ 2026-02-18 04:39 UTC (permalink / raw)
  To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Andres Freund <andres@anarazel.de>; Alvaro Herrera <alvherre@kurilemu.de>; Chao Li <li.evan.chao@gmail.com>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>

On Tue, Feb 17, 2026 at 4:44 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Tue, Feb 17, 2026 at 12:30 PM Nisha Moond <nisha.moond412@gmail.com> wrote:
> >
> > On Tue, Feb 17, 2026 at 10:15 AM Amit Kapila <amit.kapila16@gmail.com> wrote:
> > >
> > > On Mon, Feb 16, 2026 at 11:20 PM Andres Freund <andres@anarazel.de> wrote:
> > > >
> > > >
> > > > It doesn't seem like the right thing to have pgstat_subscription.c translate
> > > > the worker type to the concrete error this way. Afaict each of the callsites
> > > > of pgstat_report_subscription_error() actually knows what kind of error its
> > > > reporting, but just uses the worker type to do so.
> > > >
> > > > I'd either change the signature to have one argument for each of the error
> > > > types, i.e.
> > > >     pgstat_report_subscription_error(int subid,
> > > >                                      bool apply_error,
> > > >                                      bool sequencesync_error,
> > > >                                      bool_tablesync_error);
> > > >
> > > > or split the function into three, and have
> > > >     pgstat_report_subscription_{apply,sequence,tablesync}(int subid);
> > > >
> > >
> > > Good idea. +1 for the second approach to split the function. We can
> > > name them as pgstat_report_subscription_apply_error(int subid),
> > > pgstat_report_subscription_sequence_error(int subid),
> > > pgstat_report_subscription_tablesync_error(int subid).
> > >
> > Please find the attached patch implementing the idea. Introduced three
> > new worker specific functions as suggested and includes a few required
> > fixups after removing worker_internal.h from pgstat.h, as done earlier
> > in Amit’s patch [1].
> >
>
> *
> @@ -5606,8 +5606,10 @@ start_apply(XLogRecPtr origin_startpos)
>   * idle state.
>   */
>   AbortOutOfAnyTransaction();
> - pgstat_report_subscription_error(MySubscription->oid,
> - MyLogicalRepWorker->type);
> + if (am_tablesync_worker())
> + pgstat_report_subscription_tablesync_error(MySubscription->oid);
> + else
> + pgstat_report_subscription_apply_error(MySubscription->oid);
>
>   PG_RE_THROW();
>   }
> @@ -5960,8 +5962,12 @@ DisableSubscriptionAndExit(void)
>   * Report the worker failed during sequence synchronization, table
>   * synchronization, or apply.
>   */
> - pgstat_report_subscription_error(MyLogicalRepWorker->subid,
> - MyLogicalRepWorker->type);
> + if (am_tablesync_worker())
> + pgstat_report_subscription_tablesync_error(MySubscription->oid);
> + else if (am_sequencesync_worker())
> + pgstat_report_subscription_sequencesync_error(MySubscription->oid);
> + else
> + pgstat_report_subscription_apply_error(MySubscription->oid);
>
> As the worker type is not directly available in all places, the other
> possibility is to expose a function like GetLogicalWorkerType from
> worker_internal.h and use it directly in
> pgstat_report_subscription_error() instead of passing it via
> parameter. We can get the worker_type via MyLogicalRepWorker->type
> which should be accessible as it will be invoked by one of the logical
> replication workers.
>
+1
This seems like a cleaner approach than adding multiple worker
specific checks and functions.
Here is a patch that implements this idea.

--
Thanks,
Nisha

Attachments:

  [application/octet-stream] v2-0001-Add-get_logical_worker_type-to-retrieve-the-worke.patch (6.5K, ../../CABdArM6vMq4tRztyYVGdWwnO-ZEfOkFqmDo9nd7rcZpok31MLw@mail.gmail.com/2-v2-0001-Add-get_logical_worker_type-to-retrieve-the-worke.patch)
  download | inline diff:
From 540974fb9683166d37e37ed3852d6bccc43fd99b Mon Sep 17 00:00:00 2001
From: Nisha Moond <nisha.moond412@gmail.com>
Date: Wed, 18 Feb 2026 10:08:00 +0530
Subject: [PATCH v2] Add get_logical_worker_type() to retrieve the worker type

This patch resolves the logical worker type dependency in
pgstat.h by obtaining the current logical replication worker
type through get_logical_worker_type().
---
 src/backend/commands/functioncmds.c                        | 1 +
 src/backend/replication/logical/sequencesync.c             | 3 +--
 src/backend/replication/logical/tablesync.c                | 3 +--
 src/backend/replication/logical/worker.c                   | 6 ++----
 src/backend/storage/ipc/procsignal.c                       | 1 +
 src/backend/utils/activity/pgstat_subscription.c           | 3 ++-
 src/include/pgstat.h                                       | 4 +---
 src/include/replication/worker_internal.h                  | 7 +++++++
 src/test/modules/test_custom_stats/test_custom_var_stats.c | 1 +
 9 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index a516b037dea..242372b1e68 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -34,6 +34,7 @@
 
 #include "access/htup_details.h"
 #include "access/table.h"
+#include "access/xact.h"
 #include "catalog/catalog.h"
 #include "catalog/dependency.h"
 #include "catalog/indexing.h"
diff --git a/src/backend/replication/logical/sequencesync.c b/src/backend/replication/logical/sequencesync.c
index 165f909b3ba..9c92fddd624 100644
--- a/src/backend/replication/logical/sequencesync.c
+++ b/src/backend/replication/logical/sequencesync.c
@@ -750,8 +750,7 @@ start_sequence_sync(void)
 			 * idle state.
 			 */
 			AbortOutOfAnyTransaction();
-			pgstat_report_subscription_error(MySubscription->oid,
-											 WORKERTYPE_SEQUENCESYNC);
+			pgstat_report_subscription_error(MySubscription->oid);
 
 			PG_RE_THROW();
 		}
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index 19a3c21a863..2f2f0121ecf 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -1527,8 +1527,7 @@ start_table_sync(XLogRecPtr *origin_startpos, char **slotname)
 			 * idle state.
 			 */
 			AbortOutOfAnyTransaction();
-			pgstat_report_subscription_error(MySubscription->oid,
-											 WORKERTYPE_TABLESYNC);
+			pgstat_report_subscription_error(MySubscription->oid);
 
 			PG_RE_THROW();
 		}
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 32725c48623..73daa4479e0 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -5606,8 +5606,7 @@ start_apply(XLogRecPtr origin_startpos)
 			 * idle state.
 			 */
 			AbortOutOfAnyTransaction();
-			pgstat_report_subscription_error(MySubscription->oid,
-											 MyLogicalRepWorker->type);
+			pgstat_report_subscription_error(MySubscription->oid);
 
 			PG_RE_THROW();
 		}
@@ -5960,8 +5959,7 @@ DisableSubscriptionAndExit(void)
 	 * Report the worker failed during sequence synchronization, table
 	 * synchronization, or apply.
 	 */
-	pgstat_report_subscription_error(MyLogicalRepWorker->subid,
-									 MyLogicalRepWorker->type);
+	pgstat_report_subscription_error(MyLogicalRepWorker->subid);
 
 	/* Disable the subscription */
 	StartTransactionCommand();
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index 5d33559926a..7505c9d3a37 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -22,6 +22,7 @@
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "port/pg_bitutils.h"
+#include "replication/logicalctl.h"
 #include "replication/logicalworker.h"
 #include "replication/walsender.h"
 #include "storage/condition_variable.h"
diff --git a/src/backend/utils/activity/pgstat_subscription.c b/src/backend/utils/activity/pgstat_subscription.c
index 500b1899188..3277cf88a4e 100644
--- a/src/backend/utils/activity/pgstat_subscription.c
+++ b/src/backend/utils/activity/pgstat_subscription.c
@@ -25,10 +25,11 @@
  * Report a subscription error.
  */
 void
-pgstat_report_subscription_error(Oid subid, LogicalRepWorkerType wtype)
+pgstat_report_subscription_error(Oid subid)
 {
 	PgStat_EntryRef *entry_ref;
 	PgStat_BackendSubEntry *pending;
+	LogicalRepWorkerType wtype = get_logical_worker_type();
 
 	entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_SUBSCRIPTION,
 										  InvalidOid, subid, NULL);
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index fff7ecc2533..9bb777c3d5a 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -16,7 +16,6 @@
 #include "portability/instr_time.h"
 #include "postmaster/pgarch.h"	/* for MAX_XFN_CHARS */
 #include "replication/conflict.h"
-#include "replication/worker_internal.h"
 #include "utils/backend_progress.h" /* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/backend_status.h"	/* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/pgstat_kind.h"
@@ -775,8 +774,7 @@ extern PgStat_SLRUStats *pgstat_fetch_slru(void);
  * Functions in pgstat_subscription.c
  */
 
-extern void pgstat_report_subscription_error(Oid subid,
-											 LogicalRepWorkerType wtype);
+extern void pgstat_report_subscription_error(Oid subid);
 extern void pgstat_report_subscription_conflict(Oid subid, ConflictType type);
 extern void pgstat_create_subscription(Oid subid);
 extern void pgstat_drop_subscription(Oid subid);
diff --git a/src/include/replication/worker_internal.h b/src/include/replication/worker_internal.h
index c1285fdd1bc..da5f938a065 100644
--- a/src/include/replication/worker_internal.h
+++ b/src/include/replication/worker_internal.h
@@ -392,4 +392,11 @@ am_parallel_apply_worker(void)
 	return isParallelApplyWorker(MyLogicalRepWorker);
 }
 
+static inline LogicalRepWorkerType
+get_logical_worker_type(void)
+{
+	Assert(MyLogicalRepWorker->in_use);
+	return MyLogicalRepWorker->type;
+}
+
 #endif							/* WORKER_INTERNAL_H */
diff --git a/src/test/modules/test_custom_stats/test_custom_var_stats.c b/src/test/modules/test_custom_stats/test_custom_var_stats.c
index 64a8fe63cce..da28afbd929 100644
--- a/src/test/modules/test_custom_stats/test_custom_var_stats.c
+++ b/src/test/modules/test_custom_stats/test_custom_var_stats.c
@@ -12,6 +12,7 @@
  */
 #include "postgres.h"
 
+#include "access/htup_details.h"
 #include "common/hashfn.h"
 #include "funcapi.h"
 #include "storage/dsm_registry.h"
-- 
2.50.1 (Apple Git-155)



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-15 23:19 ` Re: pgstat include expansion Chao Li <li.evan.chao@gmail.com>
  2026-02-16 05:35   ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  2026-02-16 16:32     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:50       ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-17 04:45         ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  2026-02-17 07:00           ` Re: pgstat include expansion Nisha Moond <nisha.moond412@gmail.com>
  2026-02-17 11:14             ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  2026-02-18 04:39               ` Re: pgstat include expansion Nisha Moond <nisha.moond412@gmail.com>
@ 2026-02-19 04:46                 ` Amit Kapila <amit.kapila16@gmail.com>
  0 siblings, 0 replies; 33+ messages in thread

From: Amit Kapila @ 2026-02-19 04:46 UTC (permalink / raw)
  To: Nisha Moond <nisha.moond412@gmail.com>; +Cc: Andres Freund <andres@anarazel.de>; Alvaro Herrera <alvherre@kurilemu.de>; Chao Li <li.evan.chao@gmail.com>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>

On Wed, Feb 18, 2026 at 10:09 AM Nisha Moond <nisha.moond412@gmail.com> wrote:
>
> On Tue, Feb 17, 2026 at 4:44 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> > As the worker type is not directly available in all places, the other
> > possibility is to expose a function like GetLogicalWorkerType from
> > worker_internal.h and use it directly in
> > pgstat_report_subscription_error() instead of passing it via
> > parameter. We can get the worker_type via MyLogicalRepWorker->type
> > which should be accessible as it will be invoked by one of the logical
> > replication workers.
> >
> +1
> This seems like a cleaner approach than adding multiple worker
> specific checks and functions.
> Here is a patch that implements this idea.
>

LGTM. I'll push this tomorrow unless there are comments/objections on
this patch.

-- 
With Regards,
Amit Kapila.





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
@ 2026-02-16 04:36 ` Michael Paquier <michael@paquier.xyz>
  2026-02-16 17:18   ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  4 siblings, 1 reply; 33+ messages in thread

From: Michael Paquier @ 2026-02-16 04:36 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Alvaro Herrera <alvherre@kurilemu.de>

On Fri, Feb 13, 2026 at 05:14:01PM -0500, Andres Freund wrote:
> I think now that we rely on C11, we actually could also forward-declare enum
> typedefs. That would allow us to avoid including
> worker_internal.h. Unfortunately I think C++ might throw a wrench in the mix
> for that - IIUC it only allows forward declaring enums when using 'enum
> class', but I don't think we can rely on that.  I think the best solution
> would be to move the typedef to a more suitable header, but baring that, I
> guess just passing an int would do.


> -extern void pgstat_report_subscription_error(Oid subid,
> -                                             LogicalRepWorkerType wtype);
> +extern void pgstat_report_subscription_error(Oid subid, int wtype);

FWIW, I like some type enforcements when it comes to such report
routines.  That avoids some careless assignments.  This is usually a
sign of header refactoring to me, where the "light" declarations ought
to be moved into an independent header that can be fed back to other
places, like this one.  An enum declaration or a set of constants can
be usually worth a split if their knowledge gets a lot across the
tree.  That's just to say that while I agree about reducing the header
footprint, I don't find the result presented here to be the best thing
we can do.
--
Michael

Attachments:

  [application/pgp-signature] signature.asc (832B, ../../aZKesltb6Z35hlbP@paquier.xyz/2-signature.asc)
  download

^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 04:36 ` Re: pgstat include expansion Michael Paquier <michael@paquier.xyz>
@ 2026-02-16 17:18   ` Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 33+ messages in thread

From: Andres Freund @ 2026-02-16 17:18 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Alvaro Herrera <alvherre@kurilemu.de>

Hi,

On 2026-02-16 13:36:02 +0900, Michael Paquier wrote:
> On Fri, Feb 13, 2026 at 05:14:01PM -0500, Andres Freund wrote:
> > I think now that we rely on C11, we actually could also forward-declare enum
> > typedefs. That would allow us to avoid including
> > worker_internal.h. Unfortunately I think C++ might throw a wrench in the mix
> > for that - IIUC it only allows forward declaring enums when using 'enum
> > class', but I don't think we can rely on that.  I think the best solution
> > would be to move the typedef to a more suitable header, but baring that, I
> > guess just passing an int would do.
> 
> 
> > -extern void pgstat_report_subscription_error(Oid subid,
> > -                                             LogicalRepWorkerType wtype);
> > +extern void pgstat_report_subscription_error(Oid subid, int wtype);
> 
> FWIW, I like some type enforcements when it comes to such report
> routines.  That avoids some careless assignments.

In theory I agree (I after all did suggest moving the typedef to a better
header).  However, the type enforcement argument IMO is somewhat bogus, as C
doesn't really have strong enum types, therefore you can just pass pretty
random stuff.  I do wish C enums could be stronger...


> This is usually a sign of header refactoring to me, where the "light"
> declarations ought to be moved into an independent header that can be fed
> back to other places, like this one.  An enum declaration or a set of
> constants can be usually worth a split if their knowledge gets a lot across
> the tree.  That's just to say that while I agree about reducing the header
> footprint, I don't find the result presented here to be the best thing we
> can do.

I literally wrote that it isn't the best solution in the quoted portion above
and suggested moving the typedef to a different header?  I was hoping the
author of the code would do that...

Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
@ 2026-02-16 07:48 ` Nisha Moond <nisha.moond412@gmail.com>
  2026-02-19 06:16   ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  4 siblings, 1 reply; 33+ messages in thread

From: Nisha Moond @ 2026-02-16 07:48 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Alvaro Herrera <alvherre@kurilemu.de>; Michael Paquier <michael@paquier.xyz>

On Sat, Feb 14, 2026 at 3:45 AM Andres Freund <andres@anarazel.de> wrote:
>
> Hi,
>
> A few recent-ish changes have substantially expanded the set of headers
> included in pgstat.h.  As pgstat.h is pretty widely included, that strikes me
> as bad.
>
> commit f6a4c498dcf
> Author: Amit Kapila <akapila@postgresql.org>
> Date:   2025-11-07 08:05:08 +0000
>
>     Add seq_sync_error_count to subscription statistics.
>
> added an include of replication/worker_internal.h, which in turn includes a
> lot of other headers.  It's also seems somewhat obvious that a header named
> _internal.h shouldn't be included in something as widely included as pgstat.h
>
>
> commit 7e638d7f509
> Author: Álvaro Herrera <alvherre@kurilemu.de>
> Date:   2025-09-25 14:45:08 +0200
>
>     Don't include execnodes.h in replication/conflict.h
>
> added an include of access/transam.h, which I don't love being included,
> although it's less bad than some of the other cases. It's not actually to
> blame for that though, as it shrank what was included noticeably.
>
>
> commit 6c2b5edecc0
> Author: Amit Kapila <akapila@postgresql.org>
> Date:   2024-09-04 08:55:21 +0530
>
>     Collect statistics about conflicts in logical replication.
>
> added an include of conflict.h, which in turn includes utils/timestamp.h,
> which includes fmgr.h (and a lot more, before 7e638d7f509).
>
>
> I think now that we rely on C11, we actually could also forward-declare enum
> typedefs. That would allow us to avoid including
> worker_internal.h. Unfortunately I think C++ might throw a wrench in the mix
> for that - IIUC it only allows forward declaring enums when using 'enum
> class', but I don't think we can rely on that.  I think the best solution
> would be to move the typedef to a more suitable header, but baring that, I
> guess just passing an int would do.
>
>
> By forward declaring FullTransactionId, we can avoid including
> access/transam.h
>
>
> conflict.h includes utils/timestamp.h, even though it only needs the
> types. Using datatype/timestamp.h suffices (although it requires some fixups
> elsewhere).
>

It works even without including "utils/timestamp.h" in conflict.h, as
removing this header still allows the build and full tests to pass.
This is likely because the required definitions are included
indirectly, as all files using conflict.h already include either
"access/commit_ts.h" (which includes "datatype/timestamp.h") or
"datatype/timestamp.h" itself.

To avoid possible issues in the future, if conflict.h is used in a
file that does not include timestamp.h, it would be safer to include
"datatype/timestamp.h" directly, which is sufficient and requires no
fixups elsewhere.
The attached patch includes the required change, and make check-world
passes cleanly for it.

>
> conflict.h includes nodes/pg_list.h, which does in turn include nodes/nodes.h,
> which, while not the worst, seems unnecessary.  Another forward declaration
> solves that.
>

I am fine either way here.

--
Thanks,
Nisha

Attachments:

  [application/octet-stream] v1-0001-Fix-header-inclusion-in-conflict.h-file.patch (757B, ../../CABdArM4Ls=HJ02OUL1=cryhHYWrnO=_4vn-EWGcFYQnevDB1Vg@mail.gmail.com/2-v1-0001-Fix-header-inclusion-in-conflict.h-file.patch)
  download | inline diff:
From 9605e918dc211c33fb7cfb35f744b98455b5d7cf Mon Sep 17 00:00:00 2001
From: Nisha Moond <nisha.moond412@gmail.com>
Date: Mon, 16 Feb 2026 13:05:51 +0530
Subject: [PATCH v1] Fix header inclusion in conflict.h file

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

diff --git a/src/include/replication/conflict.h b/src/include/replication/conflict.h
index 1cade336c91..6be3c883185 100644
--- a/src/include/replication/conflict.h
+++ b/src/include/replication/conflict.h
@@ -11,7 +11,7 @@
 
 #include "access/xlogdefs.h"
 #include "nodes/pg_list.h"
-#include "utils/timestamp.h"
+#include "datatype/timestamp.h"
 
 /* Avoid including execnodes.h here */
 typedef struct EState EState;
-- 
2.50.1 (Apple Git-155)



^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 07:48 ` Re: pgstat include expansion Nisha Moond <nisha.moond412@gmail.com>
@ 2026-02-19 06:16   ` Amit Kapila <amit.kapila16@gmail.com>
  2026-02-23 05:49     ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  0 siblings, 1 reply; 33+ messages in thread

From: Amit Kapila @ 2026-02-19 06:16 UTC (permalink / raw)
  To: Nisha Moond <nisha.moond412@gmail.com>; +Cc: Andres Freund <andres@anarazel.de>; pgsql-hackers@postgresql.org, Alvaro Herrera <alvherre@kurilemu.de>; Michael Paquier <michael@paquier.xyz>

On Mon, Feb 16, 2026 at 1:18 PM Nisha Moond <nisha.moond412@gmail.com> wrote:
>
> On Sat, Feb 14, 2026 at 3:45 AM Andres Freund <andres@anarazel.de> wrote:
> >
> >
> > conflict.h includes utils/timestamp.h, even though it only needs the
> > types. Using datatype/timestamp.h suffices (although it requires some fixups
> > elsewhere).
> >
>
> It works even without including "utils/timestamp.h" in conflict.h, as
> removing this header still allows the build and full tests to pass.
> This is likely because the required definitions are included
> indirectly, as all files using conflict.h already include either
> "access/commit_ts.h" (which includes "datatype/timestamp.h") or
> "datatype/timestamp.h" itself.
>
> To avoid possible issues in the future, if conflict.h is used in a
> file that does not include timestamp.h, it would be safer to include
> "datatype/timestamp.h" directly, which is sufficient and requires no
> fixups elsewhere.
>

Yeah, that sounds better.

> The attached patch includes the required change, and make check-world
> passes cleanly for it.
>

Good. I have not tested it myself but if others don't see a problem
with this, I can do the tests and push it.

-- 
With Regards,
Amit Kapila.





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 07:48 ` Re: pgstat include expansion Nisha Moond <nisha.moond412@gmail.com>
  2026-02-19 06:16   ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
@ 2026-02-23 05:49     ` Amit Kapila <amit.kapila16@gmail.com>
  0 siblings, 0 replies; 33+ messages in thread

From: Amit Kapila @ 2026-02-23 05:49 UTC (permalink / raw)
  To: Nisha Moond <nisha.moond412@gmail.com>; +Cc: Andres Freund <andres@anarazel.de>; pgsql-hackers@postgresql.org, Alvaro Herrera <alvherre@kurilemu.de>; Michael Paquier <michael@paquier.xyz>

On Thu, Feb 19, 2026 at 11:46 AM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Mon, Feb 16, 2026 at 1:18 PM Nisha Moond <nisha.moond412@gmail.com> wrote:
> >
>
> > The attached patch includes the required change, and make check-world
> > passes cleanly for it.
> >
>
> Good. I have not tested it myself but if others don't see a problem
> with this, I can do the tests and push it.
>

This change requires explicitly including utils/timestamp.h in
test_custom_fixed_stats.c, which previously relied on the indirect
inclusion. I made that change and pushed the patch.

-- 
With Regards,
Amit Kapila.





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
@ 2026-02-16 16:18 ` Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 16:19   ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:41   ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  4 siblings, 2 replies; 33+ messages in thread

From: Alvaro Herrera @ 2026-02-16 16:18 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

On 2026-Feb-13, Andres Freund wrote:

> commit 7e638d7f509
> Author: Álvaro Herrera <alvherre@kurilemu.de>
> Date:   2025-09-25 14:45:08 +0200
>  
>     Don't include execnodes.h in replication/conflict.h
> 
> added an include of access/transam.h, which I don't love being included,
> although it's less bad than some of the other cases. It's not actually to
> blame for that though, as it shrank what was included noticeably.


> diff --git a/src/include/pgstat.h b/src/include/pgstat.h
> index fff7ecc2533..a2021a0e66f 100644
> --- a/src/include/pgstat.h
> +++ b/src/include/pgstat.h
> @@ -11,18 +11,20 @@
>  #ifndef PGSTAT_H
>  #define PGSTAT_H
>  
> -#include "access/transam.h"		/* for FullTransactionId */
>  #include "datatype/timestamp.h"
>  #include "portability/instr_time.h"
>  #include "postmaster/pgarch.h"	/* for MAX_XFN_CHARS */
> -#include "replication/conflict.h"
> -#include "replication/worker_internal.h"
> +#include "replication/conflict.h"	/* for CONFLICT_NUM_TYPES */
>  #include "utils/backend_progress.h" /* for backward compatibility */	/* IWYU pragma: export */
>  #include "utils/backend_status.h"	/* for backward compatibility */	/* IWYU pragma: export */
>  #include "utils/pgstat_kind.h"
> -#include "utils/relcache.h"
>  #include "utils/wait_event.h"	/* for backward compatibility */	/* IWYU pragma: export */
>  
> +/* to avoid including access/transam.h, for FullTransactionId */
> +typedef struct FullTransactionId FullTransactionId;
> +
> +/* to avoid including utils/relcache.h */
> +typedef struct RelationData *Relation;
>  
>  /* ----------
>   * Paths for the statistics files (relative to installation's $PGDATA).

Yeah, I intended not to add access/transam.h here and instead
forward-declare FullTransactionId, but forgot to actually remove it
before pushing.  So +1 for what you're doing here with that.  Same with
relcache.h and most of the other changes you're doing here.

I don't think the removal of pg_list.h works terribly well though, as
that is something that I would expect to be pretty much everywhere, so
it seems somewhat pointless to try to avoid it in this file.

I'm not very sure what to do about LogicalRepWorkerType ... will
follow-up to Amit's reply.

I think we should in addition remove some includes that were kept during
recent IWYU hacking "for backwards compatibility", and instead include
them explicitly wherever they are needed.  The attached does that.

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"You're _really_ hosed if the person doing the hiring doesn't understand
relational systems: you end up with a whole raft of programmers, none of
whom has had a Date with the clue stick."              (Andrew Sullivan)
https://postgr.es/m/20050809113420.GD2768@phlogiston.dyndns.org





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
@ 2026-02-16 16:19   ` Alvaro Herrera <alvherre@kurilemu.de>
  1 sibling, 0 replies; 33+ messages in thread

From: Alvaro Herrera @ 2026-02-16 16:19 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

On 2026-Feb-16, Alvaro Herrera wrote:

> I think we should in addition remove some includes that were kept during
> recent IWYU hacking "for backwards compatibility", and instead include
> them explicitly wherever they are needed.  The attached does that.

Sigh, I forgot the attachments.

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/

Attachments:

  [text/x-diff] 0002-remove-inclusions-in-pgstat.h.patch (28.3K, ../../202602161618.sq6dcdjoaynx@alvherre.pgsql/2-0002-remove-inclusions-in-pgstat.h.patch)
  download | inline diff:
From c7ef70743df6e9525e275c10ee303573e92aa374 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvherre@kurilemu.de>
Date: Mon, 16 Feb 2026 16:50:51 +0100
Subject: [PATCH 2/2] remove inclusions in pgstat.h

---
 src/backend/access/brin/brin.c                        | 1 +
 src/backend/access/gin/gininsert.c                    | 3 ++-
 src/backend/access/hash/hash.c                        | 1 +
 src/backend/access/hash/hashsort.c                    | 1 +
 src/backend/access/heap/heapam_handler.c              | 1 +
 src/backend/access/heap/vacuumlazy.c                  | 1 +
 src/backend/access/nbtree/nbtree.c                    | 2 ++
 src/backend/access/nbtree/nbtsort.c                   | 2 ++
 src/backend/access/transam/clog.c                     | 1 +
 src/backend/access/transam/parallel.c                 | 1 +
 src/backend/access/transam/slru.c                     | 2 ++
 src/backend/access/transam/timeline.c                 | 1 +
 src/backend/access/transam/twophase.c                 | 1 +
 src/backend/access/transam/xact.c                     | 1 +
 src/backend/access/transam/xlog.c                     | 1 +
 src/backend/access/transam/xlogarchive.c              | 1 +
 src/backend/access/transam/xlogfuncs.c                | 1 +
 src/backend/access/transam/xlogreader.c               | 2 ++
 src/backend/access/transam/xlogwait.c                 | 1 +
 src/backend/archive/shell_archive.c                   | 1 +
 src/backend/backup/basebackup.c                       | 1 +
 src/backend/backup/basebackup_progress.c              | 1 +
 src/backend/backup/basebackup_throttle.c              | 1 +
 src/backend/catalog/index.c                           | 1 +
 src/backend/commands/analyze.c                        | 1 +
 src/backend/commands/cluster.c                        | 1 +
 src/backend/commands/copyfrom.c                       | 1 +
 src/backend/commands/copyfromparse.c                  | 1 +
 src/backend/commands/copyto.c                         | 1 +
 src/backend/commands/indexcmds.c                      | 1 +
 src/backend/commands/vacuum.c                         | 1 +
 src/backend/commands/vacuumparallel.c                 | 1 +
 src/backend/executor/execParallel.c                   | 1 +
 src/backend/postmaster/autovacuum.c                   | 1 +
 src/backend/postmaster/auxprocess.c                   | 1 +
 src/backend/postmaster/postmaster.c                   | 1 +
 src/backend/replication/logical/applyparallelworker.c | 2 ++
 src/backend/replication/logical/worker.c              | 1 +
 src/backend/replication/walreceiver.c                 | 1 +
 src/backend/replication/walsender.c                   | 1 +
 src/backend/statistics/extended_stats.c               | 1 +
 src/backend/storage/file/fd.c                         | 1 +
 src/backend/storage/ipc/ipci.c                        | 1 +
 src/backend/storage/lmgr/deadlock.c                   | 1 +
 src/backend/storage/lmgr/lmgr.c                       | 1 +
 src/backend/tcop/postgres.c                           | 1 +
 src/backend/utils/activity/backend_status.c           | 1 +
 src/backend/utils/activity/pgstat.c                   | 1 +
 src/backend/utils/activity/pgstat_backend.c           | 1 +
 src/backend/utils/activity/pgstat_database.c          | 1 +
 src/backend/utils/adt/pgstatfuncs.c                   | 1 +
 src/backend/utils/error/elog.c                        | 1 +
 src/backend/utils/init/postinit.c                     | 1 +
 src/backend/utils/misc/guc_tables.c                   | 1 +
 src/common/controldata_utils.c                        | 1 +
 src/include/pgstat.h                                  | 3 ---
 src/include/storage/condition_variable.h              | 1 +
 src/test/modules/worker_spi/worker_spi.c              | 1 +
 58 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 6887e421442..d5153839f61 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -35,6 +35,7 @@
 #include "storage/freespace.h"
 #include "tcop/tcopprot.h"
 #include "utils/acl.h"
+#include "utils/backend_status.h"
 #include "utils/datum.h"
 #include "utils/fmgrprotos.h"
 #include "utils/guc.h"
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index 0d63fb4ba27..5f96ba0b17b 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -29,9 +29,10 @@
 #include "storage/bufmgr.h"
 #include "storage/predicate.h"
 #include "tcop/tcopprot.h"
+#include "utils/backend_status.h"
+#include "utils/builtins.h"
 #include "utils/datum.h"
 #include "utils/memutils.h"
-#include "utils/builtins.h"
 #include "utils/rel.h"
 #include "utils/typcache.h"
 
diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c
index e88ddb32a05..5ebd3d50aa1 100644
--- a/src/backend/access/hash/hash.c
+++ b/src/backend/access/hash/hash.c
@@ -30,6 +30,7 @@
 #include "nodes/execnodes.h"
 #include "optimizer/plancat.h"
 #include "pgstat.h"
+#include "utils/backend_progress.h"
 #include "utils/fmgrprotos.h"
 #include "utils/index_selfuncs.h"
 #include "utils/rel.h"
diff --git a/src/backend/access/hash/hashsort.c b/src/backend/access/hash/hashsort.c
index 77bbfaa461b..9dd6adb716f 100644
--- a/src/backend/access/hash/hashsort.c
+++ b/src/backend/access/hash/hashsort.c
@@ -30,6 +30,7 @@
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "port/pg_bitutils.h"
+#include "utils/backend_progress.h"
 #include "utils/tuplesort.h"
 
 
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index cbef73e5d4b..aa4851fd7a1 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -43,6 +43,7 @@
 #include "storage/predicate.h"
 #include "storage/procarray.h"
 #include "storage/smgr.h"
+#include "utils/backend_progress.h"
 #include "utils/builtins.h"
 #include "utils/rel.h"
 
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index 4be267ff657..9f7fd7b370a 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -151,6 +151,7 @@
 #include "storage/freespace.h"
 #include "storage/lmgr.h"
 #include "storage/read_stream.h"
+#include "utils/backend_status.h"
 #include "utils/lsyscache.h"
 #include "utils/pg_rusage.h"
 #include "utils/timestamp.h"
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index 3dec1ee657d..b8e7392f290 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -31,10 +31,12 @@
 #include "storage/ipc.h"
 #include "storage/lmgr.h"
 #include "storage/read_stream.h"
+#include "utils/backend_progress.h"
 #include "utils/datum.h"
 #include "utils/fmgrprotos.h"
 #include "utils/index_selfuncs.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index 3a45508f62e..c77c895718f 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -53,9 +53,11 @@
 #include "pgstat.h"
 #include "storage/bulk_write.h"
 #include "tcop/tcopprot.h"
+#include "utils/backend_status.h"
 #include "utils/rel.h"
 #include "utils/sortsupport.h"
 #include "utils/tuplesort.h"
+#include "utils/wait_event.h"
 
 
 /* Magic numbers for parallel state sharing */
diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c
index b5c38bbb162..3ee1cfdbc24 100644
--- a/src/backend/access/transam/clog.c
+++ b/src/backend/access/transam/clog.c
@@ -45,6 +45,7 @@
 #include "storage/proc.h"
 #include "storage/sync.h"
 #include "utils/guc_hooks.h"
+#include "utils/wait_event.h"
 
 /*
  * Defines for CLOG page sizes.  A page is the same BLCKSZ as is used
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index fe00488487d..ac03cf31bf1 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -38,6 +38,7 @@
 #include "storage/predicate.h"
 #include "storage/spin.h"
 #include "tcop/tcopprot.h"
+#include "utils/backend_progress.h"
 #include "utils/combocid.h"
 #include "utils/guc.h"
 #include "utils/inval.h"
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c
index 549c7e3e64b..9283af67cb7 100644
--- a/src/backend/access/transam/slru.c
+++ b/src/backend/access/transam/slru.c
@@ -70,7 +70,9 @@
 #include "pgstat.h"
 #include "storage/fd.h"
 #include "storage/shmem.h"
+#include "utils/backend_progress.h"
 #include "utils/guc.h"
+#include "utils/wait_event.h"
 
 /*
  * Converts segment number to the filename of the segment.
diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/transam/timeline.c
index 60ee28665b1..68e5f692d26 100644
--- a/src/backend/access/transam/timeline.c
+++ b/src/backend/access/transam/timeline.c
@@ -41,6 +41,7 @@
 #include "access/xlogdefs.h"
 #include "pgstat.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 
 /*
  * Copies all timeline history files with id's between 'begin' and 'end'
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index eabc4d48208..47c0ede807e 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -106,6 +106,7 @@
 #include "utils/injection_point.h"
 #include "utils/memutils.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /*
  * Directory where Two-phase commit files reside within PGDATA
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index eba4f063168..4e15d81fe42 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -62,6 +62,7 @@
 #include "storage/procarray.h"
 #include "storage/sinvaladt.h"
 #include "storage/smgr.h"
+#include "utils/backend_status.h"
 #include "utils/builtins.h"
 #include "utils/combocid.h"
 #include "utils/guc.h"
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 13ec6225b85..2eb7d376427 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -105,6 +105,7 @@
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 #ifdef WAL_DEBUG
 #include "utils/memutils.h"
diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c
index aa0c2fe3afd..9a0c8097cb1 100644
--- a/src/backend/access/transam/xlogarchive.c
+++ b/src/backend/access/transam/xlogarchive.c
@@ -31,6 +31,7 @@
 #include "replication/walsender.h"
 #include "storage/fd.h"
 #include "storage/ipc.h"
+#include "utils/wait_event.h"
 
 /*
  * Attempt to retrieve the specified file from off-line archival storage.
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c
index 2efe4105efb..8965be29703 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -34,6 +34,7 @@
 #include "utils/memutils.h"
 #include "utils/pg_lsn.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /*
  * Backup-related variables.
diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index 03ada8aa0c5..f02f5e515b2 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -32,6 +32,8 @@
 #include "catalog/pg_control.h"
 #include "common/pg_lzcompress.h"
 #include "replication/origin.h"
+#include "utils/backend_progress.h"
+#include "utils/wait_event.h"
 
 #ifndef FRONTEND
 #include "pgstat.h"
diff --git a/src/backend/access/transam/xlogwait.c b/src/backend/access/transam/xlogwait.c
index d286ff63123..bf4630677b4 100644
--- a/src/backend/access/transam/xlogwait.c
+++ b/src/backend/access/transam/xlogwait.c
@@ -60,6 +60,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/pg_lsn.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 
 static int	waitlsn_cmp(const pairingheap_node *a, const pairingheap_node *b,
diff --git a/src/backend/archive/shell_archive.c b/src/backend/archive/shell_archive.c
index 5b565968818..0b427a68809 100644
--- a/src/backend/archive/shell_archive.c
+++ b/src/backend/archive/shell_archive.c
@@ -22,6 +22,7 @@
 #include "archive/shell_archive.h"
 #include "common/percentrepl.h"
 #include "pgstat.h"
+#include "utils/wait_event.h"
 
 static bool shell_archive_configured(ArchiveModuleState *state);
 static bool shell_archive_file(ArchiveModuleState *state,
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 2d74c648335..ab1fbae8001 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -48,6 +48,7 @@
 #include "utils/ps_status.h"
 #include "utils/relcache.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 /*
  * How much data do we want to send in one CopyData message? Note that
diff --git a/src/backend/backup/basebackup_progress.c b/src/backend/backup/basebackup_progress.c
index fb9e57f04df..a195dd6c627 100644
--- a/src/backend/backup/basebackup_progress.c
+++ b/src/backend/backup/basebackup_progress.c
@@ -34,6 +34,7 @@
 #include "backup/basebackup_sink.h"
 #include "commands/progress.h"
 #include "pgstat.h"
+#include "utils/backend_progress.h"
 
 static void bbsink_progress_begin_backup(bbsink *sink);
 static void bbsink_progress_archive_contents(bbsink *sink, size_t len);
diff --git a/src/backend/backup/basebackup_throttle.c b/src/backend/backup/basebackup_throttle.c
index e112eed7485..4d8d90f356b 100644
--- a/src/backend/backup/basebackup_throttle.c
+++ b/src/backend/backup/basebackup_throttle.c
@@ -19,6 +19,7 @@
 #include "pgstat.h"
 #include "storage/latch.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 typedef struct bbsink_throttle
 {
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 43de42ce39e..44c22dc1a91 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -69,6 +69,7 @@
 #include "storage/lmgr.h"
 #include "storage/predicate.h"
 #include "storage/smgr.h"
+#include "utils/backend_progress.h"
 #include "utils/builtins.h"
 #include "utils/fmgroids.h"
 #include "utils/guc.h"
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index a483424152c..82ffd658537 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -45,6 +45,7 @@
 #include "storage/bufmgr.h"
 #include "storage/procarray.h"
 #include "utils/attoptcache.h"
+#include "utils/backend_status.h"
 #include "utils/datum.h"
 #include "utils/guc.h"
 #include "utils/lsyscache.h"
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index 60a4617a585..6b28a204a84 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -46,6 +46,7 @@
 #include "storage/lmgr.h"
 #include "storage/predicate.h"
 #include "utils/acl.h"
+#include "utils/backend_progress.h"
 #include "utils/fmgroids.h"
 #include "utils/guc.h"
 #include "utils/inval.h"
diff --git a/src/backend/commands/copyfrom.c b/src/backend/commands/copyfrom.c
index c0597266a82..f6dbad052a1 100644
--- a/src/backend/commands/copyfrom.c
+++ b/src/backend/commands/copyfrom.c
@@ -45,6 +45,7 @@
 #include "rewrite/rewriteHandler.h"
 #include "storage/fd.h"
 #include "tcop/tcopprot.h"
+#include "utils/backend_progress.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
 #include "utils/portal.h"
diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index 94d6f415a06..0235410c1df 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -72,6 +72,7 @@
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "port/pg_bswap.h"
+#include "utils/backend_progress.h"
 #include "utils/builtins.h"
 #include "utils/rel.h"
 
diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c
index 9ceeff6d99e..0f7c99a4204 100644
--- a/src/backend/commands/copyto.c
+++ b/src/backend/commands/copyto.c
@@ -33,6 +33,7 @@
 #include "pgstat.h"
 #include "storage/fd.h"
 #include "tcop/tcopprot.h"
+#include "utils/backend_progress.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
 #include "utils/rel.h"
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 635679cc1f2..f50f3dc8b9a 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -58,6 +58,7 @@
 #include "storage/proc.h"
 #include "storage/procarray.h"
 #include "utils/acl.h"
+#include "utils/backend_progress.h"
 #include "utils/builtins.h"
 #include "utils/fmgroids.h"
 #include "utils/guc.h"
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 03932f45c8a..104a7574d19 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -53,6 +53,7 @@
 #include "storage/pmsignal.h"
 #include "storage/proc.h"
 #include "storage/procarray.h"
+#include "utils/backend_progress.h"
 #include "utils/acl.h"
 #include "utils/fmgroids.h"
 #include "utils/guc.h"
diff --git a/src/backend/commands/vacuumparallel.c b/src/backend/commands/vacuumparallel.c
index c3b3c9ea21a..de37e7c7d05 100644
--- a/src/backend/commands/vacuumparallel.c
+++ b/src/backend/commands/vacuumparallel.c
@@ -36,6 +36,7 @@
 #include "pgstat.h"
 #include "storage/bufmgr.h"
 #include "tcop/tcopprot.h"
+#include "utils/backend_status.h"
 #include "utils/lsyscache.h"
 #include "utils/rel.h"
 
diff --git a/src/backend/executor/execParallel.c b/src/backend/executor/execParallel.c
index f87978c137e..4f10cc7df7b 100644
--- a/src/backend/executor/execParallel.c
+++ b/src/backend/executor/execParallel.c
@@ -46,6 +46,7 @@
 #include "nodes/nodeFuncs.h"
 #include "pgstat.h"
 #include "tcop/tcopprot.h"
+#include "utils/backend_status.h"
 #include "utils/datum.h"
 #include "utils/dsa.h"
 #include "utils/lsyscache.h"
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 6fde740465f..2bc49153532 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -97,6 +97,7 @@
 #include "storage/procsignal.h"
 #include "storage/smgr.h"
 #include "tcop/tcopprot.h"
+#include "utils/backend_status.h"
 #include "utils/fmgroids.h"
 #include "utils/fmgrprotos.h"
 #include "utils/guc_hooks.h"
diff --git a/src/backend/postmaster/auxprocess.c b/src/backend/postmaster/auxprocess.c
index 8ea800c0bbd..316d227bef8 100644
--- a/src/backend/postmaster/auxprocess.c
+++ b/src/backend/postmaster/auxprocess.c
@@ -22,6 +22,7 @@
 #include "storage/ipc.h"
 #include "storage/proc.h"
 #include "storage/procsignal.h"
+#include "utils/backend_status.h"
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
 
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index d6133bfebc6..acb792dcb21 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -117,6 +117,7 @@
 #include "storage/proc.h"
 #include "tcop/backend_startup.h"
 #include "tcop/tcopprot.h"
+#include "utils/backend_status.h"
 #include "utils/datetime.h"
 #include "utils/memutils.h"
 #include "utils/pidfile.h"
diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c
index 8a01f16a2ca..f38dc4419dc 100644
--- a/src/backend/replication/logical/applyparallelworker.c
+++ b/src/backend/replication/logical/applyparallelworker.c
@@ -159,6 +159,7 @@
 
 #include "libpq/pqformat.h"
 #include "libpq/pqmq.h"
+#include "libpq/protocol.h"
 #include "pgstat.h"
 #include "postmaster/interrupt.h"
 #include "replication/logicallauncher.h"
@@ -168,6 +169,7 @@
 #include "storage/ipc.h"
 #include "storage/lmgr.h"
 #include "tcop/tcopprot.h"
+#include "utils/backend_status.h"
 #include "utils/inval.h"
 #include "utils/memutils.h"
 #include "utils/syscache.h"
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 32725c48623..9eb4a15ca05 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -285,6 +285,7 @@
 #include "storage/procarray.h"
 #include "tcop/tcopprot.h"
 #include "utils/acl.h"
+#include "utils/backend_status.h"
 #include "utils/guc.h"
 #include "utils/inval.h"
 #include "utils/lsyscache.h"
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index 10e64a7d1f4..58d5c5ff994 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -62,6 +62,7 @@
 #include "funcapi.h"
 #include "libpq/pqformat.h"
 #include "libpq/pqsignal.h"
+#include "libpq/protocol.h"
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "postmaster/auxprocess.h"
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 2cde8ebc729..3cbcb18e311 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -89,6 +89,7 @@
 #include "tcop/dest.h"
 #include "tcop/tcopprot.h"
 #include "utils/acl.h"
+#include "utils/backend_status.h"
 #include "utils/builtins.h"
 #include "utils/guc.h"
 #include "utils/lsyscache.h"
diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c
index 3895ed72ef7..d6a37eb7b38 100644
--- a/src/backend/statistics/extended_stats.c
+++ b/src/backend/statistics/extended_stats.c
@@ -37,6 +37,7 @@
 #include "utils/acl.h"
 #include "utils/array.h"
 #include "utils/attoptcache.h"
+#include "utils/backend_progress.h"
 #include "utils/builtins.h"
 #include "utils/datum.h"
 #include "utils/fmgroids.h"
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 5d07b64a1ef..de2a2b64406 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -97,6 +97,7 @@
 #include "storage/aio.h"
 #include "storage/fd.h"
 #include "storage/ipc.h"
+#include "utils/backend_status.h"
 #include "utils/guc.h"
 #include "utils/guc_hooks.h"
 #include "utils/resowner.h"
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c
index 1f7e933d500..22b756d43ee 100644
--- a/src/backend/storage/ipc/ipci.c
+++ b/src/backend/storage/ipc/ipci.c
@@ -50,6 +50,7 @@
 #include "storage/procarray.h"
 #include "storage/procsignal.h"
 #include "storage/sinvaladt.h"
+#include "utils/backend_status.h"
 #include "utils/guc.h"
 #include "utils/injection_point.h"
 
diff --git a/src/backend/storage/lmgr/deadlock.c b/src/backend/storage/lmgr/deadlock.c
index c0c4ed57d9e..4af4ed7baed 100644
--- a/src/backend/storage/lmgr/deadlock.c
+++ b/src/backend/storage/lmgr/deadlock.c
@@ -31,6 +31,7 @@
 #include "storage/lmgr.h"
 #include "storage/proc.h"
 #include "storage/procnumber.h"
+#include "utils/backend_status.h"
 #include "utils/memutils.h"
 
 
diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c
index 2ccf7237fee..5f8ce14b99f 100644
--- a/src/backend/storage/lmgr/lmgr.c
+++ b/src/backend/storage/lmgr/lmgr.c
@@ -24,6 +24,7 @@
 #include "storage/lmgr.h"
 #include "storage/proc.h"
 #include "storage/procarray.h"
+#include "utils/backend_progress.h"
 #include "utils/inval.h"
 
 
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 21de158adbb..356000c8a69 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -73,6 +73,7 @@
 #include "tcop/pquery.h"
 #include "tcop/tcopprot.h"
 #include "tcop/utility.h"
+#include "utils/backend_status.h"
 #include "utils/guc_hooks.h"
 #include "utils/injection_point.h"
 #include "utils/lsyscache.h"
diff --git a/src/backend/utils/activity/backend_status.c b/src/backend/utils/activity/backend_status.c
index cd087129469..5b0f3de4bb3 100644
--- a/src/backend/utils/activity/backend_status.c
+++ b/src/backend/utils/activity/backend_status.c
@@ -20,6 +20,7 @@
 #include "storage/proc.h"		/* for MyProc */
 #include "storage/procarray.h"
 #include "utils/ascii.h"
+#include "utils/backend_status.h"
 #include "utils/guc.h"			/* for application_name */
 #include "utils/memutils.h"
 
diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c
index 11bb71cad5a..e5e7dc7d727 100644
--- a/src/backend/utils/activity/pgstat.c
+++ b/src/backend/utils/activity/pgstat.c
@@ -110,6 +110,7 @@
 #include "storage/ipc.h"
 #include "storage/lwlock.h"
 #include "utils/guc_hooks.h"
+#include "utils/backend_status.h"
 #include "utils/memutils.h"
 #include "utils/pgstat_internal.h"
 #include "utils/timestamp.h"
diff --git a/src/backend/utils/activity/pgstat_backend.c b/src/backend/utils/activity/pgstat_backend.c
index f2f8d3ff75f..c380298defd 100644
--- a/src/backend/utils/activity/pgstat_backend.c
+++ b/src/backend/utils/activity/pgstat_backend.c
@@ -29,6 +29,7 @@
 #include "storage/bufmgr.h"
 #include "storage/proc.h"
 #include "storage/procarray.h"
+#include "utils/backend_status.h"
 #include "utils/memutils.h"
 #include "utils/pgstat_internal.h"
 
diff --git a/src/backend/utils/activity/pgstat_database.c b/src/backend/utils/activity/pgstat_database.c
index 933dcb5cae5..e67ed2821f0 100644
--- a/src/backend/utils/activity/pgstat_database.c
+++ b/src/backend/utils/activity/pgstat_database.c
@@ -18,6 +18,7 @@
 #include "postgres.h"
 
 #include "storage/standby.h"
+#include "utils/backend_status.h"
 #include "utils/pgstat_internal.h"
 #include "utils/timestamp.h"
 
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index b1df96e7b0b..46af5ba2e10 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -29,6 +29,7 @@
 #include "storage/proc.h"
 #include "storage/procarray.h"
 #include "utils/acl.h"
+#include "utils/backend_status.h"
 #include "utils/builtins.h"
 #include "utils/timestamp.h"
 
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 1e5b0531f3a..e80696e0917 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -83,6 +83,7 @@
 #include "storage/ipc.h"
 #include "storage/proc.h"
 #include "tcop/tcopprot.h"
+#include "utils/backend_status.h"
 #include "utils/guc_hooks.h"
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index b59e08605cc..f2b63d3a636 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -58,6 +58,7 @@
 #include "tcop/backend_startup.h"
 #include "tcop/tcopprot.h"
 #include "utils/acl.h"
+#include "utils/backend_status.h"
 #include "utils/builtins.h"
 #include "utils/fmgroids.h"
 #include "utils/guc_hooks.h"
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 741fce8dede..e0af705e95f 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -90,6 +90,7 @@
 #include "tcop/backend_startup.h"
 #include "tcop/tcopprot.h"
 #include "tsearch/ts_cache.h"
+#include "utils/backend_status.h"
 #include "utils/builtins.h"
 #include "utils/bytea.h"
 #include "utils/float.h"
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 14530c6489a..4ab116afcde 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -37,6 +37,7 @@
 #ifndef FRONTEND
 #include "pgstat.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 #endif
 
 /*
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 775ecf37c1a..c897d233c16 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -16,11 +16,8 @@
 #include "postmaster/pgarch.h"	/* for MAX_XFN_CHARS */
 #include "replication/conflict.h"
 #include "replication/worker_internal.h"
-#include "utils/backend_progress.h" /* for backward compatibility */	/* IWYU pragma: export */
-#include "utils/backend_status.h"	/* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/pgstat_kind.h"
 #include "utils/relcache.h"
-#include "utils/wait_event.h"	/* for backward compatibility */	/* IWYU pragma: export */
 
 struct FullTransactionId;
 
diff --git a/src/include/storage/condition_variable.h b/src/include/storage/condition_variable.h
index 14bd6dd55c0..73d02b4f02f 100644
--- a/src/include/storage/condition_variable.h
+++ b/src/include/storage/condition_variable.h
@@ -24,6 +24,7 @@
 
 #include "storage/proclist_types.h"
 #include "storage/spin.h"
+#include "utils/wait_event.h"		/* IWYU pragma: keep */
 
 typedef struct
 {
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index d1e4a2bd952..8908e88fde1 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -37,6 +37,7 @@
 #include "pgstat.h"
 #include "tcop/utility.h"
 #include "utils/acl.h"
+#include "utils/backend_status.h"
 #include "utils/builtins.h"
 #include "utils/snapmgr.h"
 
-- 
2.47.3

^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
@ 2026-02-16 17:41   ` Andres Freund <andres@anarazel.de>
  2026-02-16 18:34     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  1 sibling, 1 reply; 33+ messages in thread

From: Andres Freund @ 2026-02-16 17:41 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@kurilemu.de>; +Cc: pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

Hi,

On 2026-02-16 17:18:36 +0100, Alvaro Herrera wrote:
> Yeah, I intended not to add access/transam.h here and instead
> forward-declare FullTransactionId, but forgot to actually remove it
> before pushing.  So +1 for what you're doing here with that.  Same with
> relcache.h and most of the other changes you're doing here.

Ah, great.


> I don't think the removal of pg_list.h works terribly well though, as
> that is something that I would expect to be pretty much everywhere, so
> it seems somewhat pointless to try to avoid it in this file.

Yea, I was on the fence about that one.

It does seem pretty crappy that pg_list.h is so widely included and in turn
includes nodes/nodes.h, which then depends on the generated nodetags.h.  For
one it forces an unnecessary rebuild of too much if you add a new node type,
but it also just aesthetically feels wrong.

But avoiding it just here does, as you say, not save very much.



> I think we should in addition remove some includes that were kept during
> recent IWYU hacking "for backwards compatibility", and instead include
> them explicitly wherever they are needed.  The attached does that.

FWIW, the "for backwards compatibility" includes are from prep work towards
shared memory stats. Before that all the stuff in backend_status.h,
backend_progress.h and wait_event.h was in pgstat.h, which was quite
unwieldy. The creation of those headers would have broken a lot of extensions
if we had not provided those backward compat includes from pgstat.h.

I suspect it would still break a fair number of extensions if removed those
includes today. Not sure if the improvement is worth it?  But even if we
decide not to remove the backward compat includes, I think we should fix our
own code to include the right headers directly, rather than rely on doing so
via pgstat.h.


FWIW, your patch that you sent subsequently doesn't seem to apply cleanly for
me? I think it's perhaps based on an older tree, it doesn't know about the
conflict.h include yet...  And it fails to build e.g. due to miscadmin.h
defines around BackendType not being indirectly included in pgstat.h anymore,
but there are many other failures...

Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:41   ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
@ 2026-02-16 18:34     ` Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-18 15:10       ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  0 siblings, 1 reply; 33+ messages in thread

From: Alvaro Herrera @ 2026-02-16 18:34 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

Hello,

On 2026-Feb-16, Andres Freund wrote:

> On 2026-02-16 17:18:36 +0100, Alvaro Herrera wrote:

> > I don't think the removal of pg_list.h works terribly well though, as
> > that is something that I would expect to be pretty much everywhere, so
> > it seems somewhat pointless to try to avoid it in this file.
> 
> Yea, I was on the fence about that one.
> 
> It does seem pretty crappy that pg_list.h is so widely included and in turn
> includes nodes/nodes.h, which then depends on the generated nodetags.h.  For
> one it forces an unnecessary rebuild of too much if you add a new node type,
> but it also just aesthetically feels wrong.

Yeah, I was unhappy about pg_list.h too on my recent header hacking, and
perhaps we can improve this somehow, but I think it's a bigger effort.

> > I think we should in addition remove some includes that were kept during
> > recent IWYU hacking "for backwards compatibility", and instead include
> > them explicitly wherever they are needed.  The attached does that.
> 
> FWIW, the "for backwards compatibility" includes are from prep work towards
> shared memory stats. Before that all the stuff in backend_status.h,
> backend_progress.h and wait_event.h was in pgstat.h, which was quite
> unwieldy.

Ah, okay.

> The creation of those headers would have broken a lot of extensions if
> we had not provided those backward compat includes from pgstat.h.

Right ... TBH the real issue for me is that wait_event.h includes the
generated file wait_event_types.h (same complaint you had above), but I
decided that if I was wielding a weapon against pgstat.h, it could as
well be a shotgun.  I guess I would be satisfied if we remove
wait_events.h from pgstat.h, and that probably won't break as many
extensions and won't have as much of a fallout.  Although TB further H,
I don't really see it as terribly bad if we break extensions with this
kind of work, since the fix on their side is fairly easy, noninvasive,
and doesn't have to be done with any urgency.

> FWIW, your patch that you sent subsequently doesn't seem to apply cleanly for
> me? I think it's perhaps based on an older tree, it doesn't know about the
> conflict.h include yet...  And it fails to build e.g. due to miscadmin.h
> defines around BackendType not being indirectly included in pgstat.h anymore,
> but there are many other failures...

Yeah, I just wrote it on (almost) clean master, but feel free to push
your changes whenever, and I'll rebase on top of that.  I suspect the
failures just mean that the implicit header inclusions are worse than
they appear at first.

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:41   ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 18:34     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
@ 2026-02-18 15:10       ` Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-20 04:35         ` Re: pgstat include expansion Amit Kapila <amit.kapila16@gmail.com>
  2026-02-26 13:52         ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  0 siblings, 2 replies; 33+ messages in thread

From: Alvaro Herrera @ 2026-02-18 15:10 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

On 2026-Feb-16, Alvaro Herrera wrote:

> > FWIW, your patch that you sent subsequently doesn't seem to apply
> > cleanly for me? I think it's perhaps based on an older tree, it
> > doesn't know about the conflict.h include yet...  And it fails to
> > build e.g. due to miscadmin.h defines around BackendType not being
> > indirectly included in pgstat.h anymore, but there are many other
> > failures...
> 
> Yeah, I just wrote it on (almost) clean master, but feel free to push
> your changes whenever, and I'll rebase on top of that.

Actually, being more surgical and removing only wait_event.h, the
attached patch applies and compiles cleanly -- after yours this time,
rather than on master.  I think this is the most significant change
because of it including the generated file.  Given that pgstat.h is not
_so_ widely used, I think leaving the other includes there doesn't hurt
all that much anyway.

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
<Schwern> It does it in a really, really complicated way
<crab> why does it need to be complicated?
<Schwern> Because it's MakeMaker.

Attachments:

  [text/x-diff] no_include_wait_event.patch (27.9K, ../../202602181214.gcmhx2vhlxzp@alvherre.pgsql/2-no_include_wait_event.patch)
  download | inline diff:
diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
index 89e187425cc..ba0bc8e6d4a 100644
--- a/contrib/pg_prewarm/autoprewarm.c
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -48,6 +48,7 @@
 #include "utils/rel.h"
 #include "utils/relfilenumbermap.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 #define AUTOPREWARM_FILE "autoprewarm.blocks"
 
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 6887e421442..126ae349452 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -42,6 +42,7 @@
 #include "utils/memutils.h"
 #include "utils/rel.h"
 #include "utils/tuplesort.h"
+#include "utils/wait_event.h"
 
 /* Magic numbers for parallel state sharing */
 #define PARALLEL_KEY_BRIN_SHARED		UINT64CONST(0xB000000000000001)
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index 0d63fb4ba27..e38da2e5b98 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -34,7 +34,7 @@
 #include "utils/builtins.h"
 #include "utils/rel.h"
 #include "utils/typcache.h"
-
+#include "utils/wait_event.h"
 
 /* Magic numbers for parallel state sharing */
 #define PARALLEL_KEY_GIN_SHARED			UINT64CONST(0xB000000000000001)
diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c
index 77fd48eb59e..6b19ac3030d 100644
--- a/src/backend/access/heap/rewriteheap.c
+++ b/src/backend/access/heap/rewriteheap.c
@@ -122,6 +122,7 @@
 #include "storage/procarray.h"
 #include "utils/memutils.h"
 #include "utils/rel.h"
+#include "utils/wait_event.h"
 
 /*
  * State associated with a rewrite operation. This is opaque to the user
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index 4be267ff657..259f0822564 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -154,6 +154,7 @@
 #include "utils/lsyscache.h"
 #include "utils/pg_rusage.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 3dec1ee657d..6d0a6f27f3f 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -35,6 +35,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/index_selfuncs.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index 3a45508f62e..a9b0618f464 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -56,6 +56,7 @@
 #include "utils/rel.h"
 #include "utils/sortsupport.h"
 #include "utils/tuplesort.h"
+#include "utils/wait_event.h"
 
 
 /* Magic numbers for parallel state sharing */
diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c
index b5c38bbb162..3ee1cfdbc24 100644
--- a/src/backend/access/transam/clog.c
+++ b/src/backend/access/transam/clog.c
@@ -45,6 +45,7 @@
 #include "storage/proc.h"
 #include "storage/sync.h"
 #include "utils/guc_hooks.h"
+#include "utils/wait_event.h"
 
 /*
  * Defines for CLOG page sizes.  A page is the same BLCKSZ as is used
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index fe00488487d..96cf8ee9bcc 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -44,6 +44,7 @@
 #include "utils/memutils.h"
 #include "utils/relmapper.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 /*
  * We don't want to waste a lot of memory on an error queue which, most of
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c
index 549c7e3e64b..556edcbf7cb 100644
--- a/src/backend/access/transam/slru.c
+++ b/src/backend/access/transam/slru.c
@@ -71,6 +71,7 @@
 #include "storage/fd.h"
 #include "storage/shmem.h"
 #include "utils/guc.h"
+#include "utils/wait_event.h"
 
 /*
  * Converts segment number to the filename of the segment.
diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/transam/timeline.c
index 60ee28665b1..68e5f692d26 100644
--- a/src/backend/access/transam/timeline.c
+++ b/src/backend/access/transam/timeline.c
@@ -41,6 +41,7 @@
 #include "access/xlogdefs.h"
 #include "pgstat.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 
 /*
  * Copies all timeline history files with id's between 'begin' and 'end'
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index eabc4d48208..47c0ede807e 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -106,6 +106,7 @@
 #include "utils/injection_point.h"
 #include "utils/memutils.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /*
  * Directory where Two-phase commit files reside within PGDATA
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 13ec6225b85..2eb7d376427 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -105,6 +105,7 @@
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 #ifdef WAL_DEBUG
 #include "utils/memutils.h"
diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c
index aa0c2fe3afd..9a0c8097cb1 100644
--- a/src/backend/access/transam/xlogarchive.c
+++ b/src/backend/access/transam/xlogarchive.c
@@ -31,6 +31,7 @@
 #include "replication/walsender.h"
 #include "storage/fd.h"
 #include "storage/ipc.h"
+#include "utils/wait_event.h"
 
 /*
  * Attempt to retrieve the specified file from off-line archival storage.
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c
index 2efe4105efb..8965be29703 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -34,6 +34,7 @@
 #include "utils/memutils.h"
 #include "utils/pg_lsn.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /*
  * Backup-related variables.
diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index 03ada8aa0c5..d26a71e3a89 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -32,6 +32,7 @@
 #include "catalog/pg_control.h"
 #include "common/pg_lzcompress.h"
 #include "replication/origin.h"
+#include "utils/wait_event.h"
 
 #ifndef FRONTEND
 #include "pgstat.h"
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index c0c2744d45b..bc1dd23a822 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -65,6 +65,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/ps_status.h"
 #include "utils/pg_rusage.h"
+#include "utils/wait_event.h"
 
 /* Unsupported old recovery command file names (relative to $PGDATA) */
 #define RECOVERY_COMMAND_FILE	"recovery.conf"
diff --git a/src/backend/access/transam/xlogwait.c b/src/backend/access/transam/xlogwait.c
index d286ff63123..bf4630677b4 100644
--- a/src/backend/access/transam/xlogwait.c
+++ b/src/backend/access/transam/xlogwait.c
@@ -60,6 +60,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/pg_lsn.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 
 static int	waitlsn_cmp(const pairingheap_node *a, const pairingheap_node *b,
diff --git a/src/backend/archive/shell_archive.c b/src/backend/archive/shell_archive.c
index 5b565968818..0b427a68809 100644
--- a/src/backend/archive/shell_archive.c
+++ b/src/backend/archive/shell_archive.c
@@ -22,6 +22,7 @@
 #include "archive/shell_archive.h"
 #include "common/percentrepl.h"
 #include "pgstat.h"
+#include "utils/wait_event.h"
 
 static bool shell_archive_configured(ArchiveModuleState *state);
 static bool shell_archive_file(ArchiveModuleState *state,
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 2d74c648335..ab1fbae8001 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -48,6 +48,7 @@
 #include "utils/ps_status.h"
 #include "utils/relcache.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 /*
  * How much data do we want to send in one CopyData message? Note that
diff --git a/src/backend/backup/basebackup_throttle.c b/src/backend/backup/basebackup_throttle.c
index e112eed7485..4d8d90f356b 100644
--- a/src/backend/backup/basebackup_throttle.c
+++ b/src/backend/backup/basebackup_throttle.c
@@ -19,6 +19,7 @@
 #include "pgstat.h"
 #include "storage/latch.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 typedef struct bbsink_throttle
 {
diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index 94d6f415a06..ef6bb36e9df 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -74,6 +74,7 @@
 #include "port/pg_bswap.h"
 #include "utils/builtins.h"
 #include "utils/rel.h"
+#include "utils/wait_event.h"
 
 #define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
 #define OCTVALUE(c) ((c) - '0')
diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c
index 9ceeff6d99e..d6ef7275a64 100644
--- a/src/backend/commands/copyto.c
+++ b/src/backend/commands/copyto.c
@@ -37,6 +37,7 @@
 #include "utils/memutils.h"
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 /*
  * Represents the different dest cases we need to worry about at
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 33311760df7..ea56cf0056b 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -70,6 +70,7 @@
 #include "utils/relmapper.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /*
  * Create database strategy.
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 03932f45c8a..c61c9eb0a01 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -61,6 +61,7 @@
 #include "utils/memutils.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /*
  * Minimum interval for cost-based vacuum delay reports from a parallel worker.
diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c
index 7138dc692c6..677b9e367c0 100644
--- a/src/backend/executor/nodeAppend.c
+++ b/src/backend/executor/nodeAppend.c
@@ -64,6 +64,7 @@
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "storage/latch.h"
+#include "utils/wait_event.h"
 
 /* Shared state for parallel-aware Append. */
 struct ParallelAppendState
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index c68c26cbf38..e0b6df64767 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -45,6 +45,7 @@
 #include "storage/bufmgr.h"
 #include "utils/rel.h"
 #include "utils/spccache.h"
+#include "utils/wait_event.h"
 
 static void BitmapTableScanSetup(BitmapHeapScanState *node);
 static TupleTableSlot *BitmapHeapNext(BitmapHeapScanState *node);
diff --git a/src/backend/libpq/be-secure-gssapi.c b/src/backend/libpq/be-secure-gssapi.c
index df7dc79b827..ff355201afa 100644
--- a/src/backend/libpq/be-secure-gssapi.c
+++ b/src/backend/libpq/be-secure-gssapi.c
@@ -23,6 +23,7 @@
 #include "port/pg_bswap.h"
 #include "utils/injection_point.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.c
index 4da6ac22ff9..14c6532bb16 100644
--- a/src/backend/libpq/be-secure-openssl.c
+++ b/src/backend/libpq/be-secure-openssl.c
@@ -35,6 +35,7 @@
 #include "storage/latch.h"
 #include "utils/guc.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * These SSL-related #includes must come after all system-provided headers.
diff --git a/src/backend/libpq/pqmq.c b/src/backend/libpq/pqmq.c
index 6e4bbfb5aa1..8270bcc8007 100644
--- a/src/backend/libpq/pqmq.c
+++ b/src/backend/libpq/pqmq.c
@@ -22,6 +22,7 @@
 #include "replication/logicalworker.h"
 #include "tcop/tcopprot.h"
 #include "utils/builtins.h"
+#include "utils/wait_event.h"
 
 static shm_mq_handle *pq_mq_handle = NULL;
 static bool pq_mq_busy = false;
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 6fde740465f..695e187ba11 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -109,6 +109,7 @@
 #include "utils/syscache.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c
index 261ccd3f59c..9a4ee4f6746 100644
--- a/src/backend/postmaster/bgworker.c
+++ b/src/backend/postmaster/bgworker.c
@@ -34,6 +34,7 @@
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
+#include "utils/wait_event.h"
 
 /*
  * The postmaster's list of registered background workers, in private memory.
diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c
index 0956bd39a85..1d8947774a9 100644
--- a/src/backend/postmaster/bgwriter.c
+++ b/src/backend/postmaster/bgwriter.c
@@ -51,6 +51,7 @@
 #include "utils/memutils.h"
 #include "utils/resowner.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /*
  * GUC parameters
diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c
index e03c19123bc..3c982c6ffac 100644
--- a/src/backend/postmaster/checkpointer.c
+++ b/src/backend/postmaster/checkpointer.c
@@ -67,6 +67,7 @@
 #include "utils/guc.h"
 #include "utils/memutils.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 
 /*----------
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 82731e452fc..fa4bdfe9ab9 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -53,6 +53,7 @@
 #include "utils/ps_status.h"
 #include "utils/resowner.h"
 #include "utils/timeout.h"
+#include "utils/wait_event.h"
 
 
 /* ----------
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index 86c5e376b40..9792f638718 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -51,6 +51,7 @@
 #include "utils/guc.h"
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
+#include "utils/wait_event.h"
 
 /*
  * We read() into a temp buffer twice as big as a chunk, so that any fragment
diff --git a/src/backend/postmaster/walwriter.c b/src/backend/postmaster/walwriter.c
index 7c0e2809c17..9cd86ad7022 100644
--- a/src/backend/postmaster/walwriter.c
+++ b/src/backend/postmaster/walwriter.c
@@ -62,6 +62,7 @@
 #include "utils/hsearch.h"
 #include "utils/memutils.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c
index 8a01f16a2ca..05d83c606a5 100644
--- a/src/backend/replication/logical/applyparallelworker.c
+++ b/src/backend/replication/logical/applyparallelworker.c
@@ -171,6 +171,7 @@
 #include "utils/inval.h"
 #include "utils/memutils.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 #define PG_LOGICAL_APPLY_SHM_MAGIC 0x787ca067
 
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index 3ed86480be2..fe1cc792fc2 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -44,6 +44,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /* max sleep time between cycles (3min) */
 #define DEFAULT_NAPTIME_PER_CYCLE 180000L
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index c3271a6fd0e..26afd8f0af9 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -95,6 +95,7 @@
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /* paths for replication origin checkpoint files */
 #define PG_REPLORIGIN_CHECKPOINT_FILENAME PG_LOGICAL_DIR "/replorigin_checkpoint"
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 94b2b29945c..758e0ae5677 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -113,6 +113,7 @@
 #include "utils/memutils.h"
 #include "utils/rel.h"
 #include "utils/relfilenumbermap.h"
+#include "utils/wait_event.h"
 
 /*
  * Each transaction has an 8MB limit for invalidation messages distributed from
diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c
index 062a08ccb88..19976efe4f2 100644
--- a/src/backend/replication/logical/slotsync.c
+++ b/src/backend/replication/logical/slotsync.c
@@ -75,6 +75,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
+#include "utils/wait_event.h"
 
 /*
  * Struct for sharing information to control slot synchronization.
diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c
index 7f79621b57e..eddb3d9105c 100644
--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -144,6 +144,9 @@
 #include "utils/memutils.h"
 #include "utils/snapmgr.h"
 #include "utils/snapshot.h"
+#include "utils/wait_event.h"
+
+
 /*
  * Starting a transaction -- which we need to do while exporting a snapshot --
  * removes knowledge about the previously used resowner, so we save it here.
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index 19a3c21a863..4306e682728 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -121,6 +121,7 @@
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
 #include "utils/usercontext.h"
+#include "utils/wait_event.h"
 
 List	   *table_states_not_ready = NIL;
 
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 32725c48623..688182c3e3d 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -295,6 +295,7 @@
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
 #include "utils/usercontext.h"
+#include "utils/wait_event.h"
 
 #define NAPTIME_PER_CYCLE 1000	/* max sleep time between cycles (1s) */
 
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index 28c7019402b..a9092fc2382 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -59,6 +59,7 @@
 #include "utils/guc_hooks.h"
 #include "utils/injection_point.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 /*
  * Replication slot on-disk data structure.
diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c
index 7ea6001e9ad..87202e491ed 100644
--- a/src/backend/replication/syncrep.c
+++ b/src/backend/replication/syncrep.c
@@ -85,6 +85,7 @@
 #include "tcop/tcopprot.h"
 #include "utils/guc_hooks.h"
 #include "utils/ps_status.h"
+#include "utils/wait_event.h"
 
 /* User-settable parameters for sync rep */
 char	   *SyncRepStandbyNames;
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index 10e64a7d1f4..34a38678ec1 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -79,6 +79,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/ps_status.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c
index 42e3e170bc0..f0413dedf71 100644
--- a/src/backend/replication/walreceiverfuncs.c
+++ b/src/backend/replication/walreceiverfuncs.c
@@ -30,6 +30,7 @@
 #include "storage/proc.h"
 #include "storage/shmem.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 WalRcvData *WalRcv = NULL;
 
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 2cde8ebc729..829ec538ea5 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -98,6 +98,7 @@
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /* Minimum interval used by walsender for stats flushes, in ms */
 #define WALSENDER_STATS_FLUSH_INTERVAL         1000
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index d1babaff023..5f3d083e938 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -68,6 +68,7 @@
 #include "utils/rel.h"
 #include "utils/resowner.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /* Note: these two macros only work on shared buffers, not local ones! */
diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c
index ddf3a410d6f..c4afe4d368a 100644
--- a/src/backend/storage/file/buffile.c
+++ b/src/backend/storage/file/buffile.c
@@ -53,6 +53,7 @@
 #include "storage/bufmgr.h"
 #include "storage/fd.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 /*
  * We break BufFiles into gigabyte-sized segments, regardless of RELSEG_SIZE.
diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c
index 596d9070fd8..5ee141f13a5 100644
--- a/src/backend/storage/file/copydir.c
+++ b/src/backend/storage/file/copydir.c
@@ -29,6 +29,7 @@
 #include "pgstat.h"
 #include "storage/copydir.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 
 /* GUCs */
 int			file_copy_method = FILE_COPY_METHOD_COPY;
diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c
index e208457df27..e8c07805f59 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -68,6 +68,7 @@
 #include "storage/fd.h"
 #include "utils/guc.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 #ifdef USE_DSM_POSIX
 static bool dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index 40312df2cac..406b8253f8b 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -67,6 +67,7 @@
 #include "utils/lsyscache.h"
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 #define UINT32_ACCESS_ONCE(var)		 ((uint32)(*((volatile uint32 *)&(var))))
 
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index 4e32a29766c..82fc9a6b1d0 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -33,6 +33,7 @@
 #include "storage/smgr.h"
 #include "tcop/tcopprot.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * The SIGUSR1 signal is multiplexed to support signaling multiple event
diff --git a/src/backend/storage/ipc/shm_mq.c b/src/backend/storage/ipc/shm_mq.c
index 3ce6068ac54..ab0d4cdf063 100644
--- a/src/backend/storage/ipc/shm_mq.c
+++ b/src/backend/storage/ipc/shm_mq.c
@@ -25,6 +25,7 @@
 #include "storage/shm_mq.h"
 #include "storage/spin.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * This structure represents the actual queue, stored in shared memory.
diff --git a/src/backend/storage/ipc/signalfuncs.c b/src/backend/storage/ipc/signalfuncs.c
index d48b4fe3799..800b699de21 100644
--- a/src/backend/storage/ipc/signalfuncs.c
+++ b/src/backend/storage/ipc/signalfuncs.c
@@ -25,6 +25,7 @@
 #include "storage/procarray.h"
 #include "utils/acl.h"
 #include "utils/fmgrprotos.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c
index d83afbfb9d6..f3ad90c7c7a 100644
--- a/src/backend/storage/ipc/standby.c
+++ b/src/backend/storage/ipc/standby.c
@@ -35,6 +35,7 @@
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /* User-settable GUC parameters */
 int			max_standby_archive_delay = 30 * 1000;
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 517c55375b4..49382de88fc 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -85,6 +85,7 @@
 #include "storage/procnumber.h"
 #include "storage/spin.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 #ifdef LWLOCK_STATS
 #include "utils/hsearch.h"
diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c
index fe75ead3501..548b4f66470 100644
--- a/src/backend/storage/lmgr/predicate.c
+++ b/src/backend/storage/lmgr/predicate.c
@@ -214,6 +214,7 @@
 #include "utils/guc_hooks.h"
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 /* Uncomment the next line to test the graceful degradation code. */
 /* #define TEST_SUMMARIZE_SERIAL */
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index fd8318bdf3d..d8fbf50db93 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -53,6 +53,7 @@
 #include "storage/standby.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /* GUC variables */
 int			DeadlockTimeout = 1000;
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 443434e4ea8..dee29037b16 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -40,6 +40,7 @@
 #include "storage/smgr.h"
 #include "storage/sync.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * The magnetic disk storage manager keeps track of open file
diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c
index b1accc68b95..2c964b6f3d9 100644
--- a/src/backend/storage/sync/sync.c
+++ b/src/backend/storage/sync/sync.c
@@ -31,6 +31,7 @@
 #include "storage/md.h"
 #include "utils/hsearch.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * In some contexts (currently, standalone backends and the checkpointer)
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index 32a787d7df7..864032c32bf 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -46,6 +46,7 @@
 #include "utils/ruleutils.h"
 #include "utils/syscache.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/utils/cache/relmapper.c b/src/backend/utils/cache/relmapper.c
index 778b14a2318..3aaf466868d 100644
--- a/src/backend/utils/cache/relmapper.c
+++ b/src/backend/utils/cache/relmapper.c
@@ -54,6 +54,7 @@
 #include "storage/lwlock.h"
 #include "utils/inval.h"
 #include "utils/relmapper.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index 03f6c8479f2..ba191977697 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -55,6 +55,7 @@
 #include "utils/pidfile.h"
 #include "utils/syscache.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 
 #define DIRECTORY_LOCK_FILE		"postmaster.pid"
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 14530c6489a..4ab116afcde 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -37,6 +37,7 @@
 #ifndef FRONTEND
 #include "pgstat.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 #endif
 
 /*
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index a2021a0e66f..d0fefb133e4 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -18,7 +18,6 @@
 #include "utils/backend_progress.h" /* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/backend_status.h"	/* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/pgstat_kind.h"
-#include "utils/wait_event.h"	/* for backward compatibility */	/* IWYU pragma: export */
 
 /* to avoid including access/transam.h, for FullTransactionId */
 typedef struct FullTransactionId FullTransactionId;

^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:41   ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 18:34     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-18 15:10       ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
@ 2026-02-20 04:35         ` Amit Kapila <amit.kapila16@gmail.com>
  1 sibling, 0 replies; 33+ messages in thread

From: Amit Kapila @ 2026-02-20 04:35 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@kurilemu.de>; +Cc: Andres Freund <andres@anarazel.de>; pgsql-hackers@postgresql.org, Michael Paquier <michael@paquier.xyz>

On Wed, Feb 18, 2026 at 8:40 PM Alvaro Herrera <alvherre@kurilemu.de> wrote:
>
> On 2026-Feb-16, Alvaro Herrera wrote:
>
> > > FWIW, your patch that you sent subsequently doesn't seem to apply
> > > cleanly for me? I think it's perhaps based on an older tree, it
> > > doesn't know about the conflict.h include yet...  And it fails to
> > > build e.g. due to miscadmin.h defines around BackendType not being
> > > indirectly included in pgstat.h anymore, but there are many other
> > > failures...
> >
> > Yeah, I just wrote it on (almost) clean master, but feel free to push
> > your changes whenever, and I'll rebase on top of that.
>
> Actually, being more surgical and removing only wait_event.h, the
> attached patch applies and compiles cleanly -- after yours this time,
> rather than on master.  I think this is the most significant change
> because of it including the generated file.  Given that pgstat.h is not
> _so_ widely used, I think leaving the other includes there doesn't hurt
> all that much anyway.
>

After pushing the patch for removing worker_internal.h from pgstat.h,
I tried this patch, but it failed to apply for pgstat.h. I fixed that
manually and tried to build on mac and windows. I see the following
problems.

On Windows (using meson build):
==========================
[951/2089] Compiling C object
src/backend/postgres_lib.a.p/utils_adt_pgstatfuncs.c.obj
../src/backend/utils/adt/pgstatfuncs.c(473): warning C4047: '=':
'const char *' differs in levels of indirection from 'int'
../src/backend/utils/adt/pgstatfuncs.c(474): warning C4047: '=':
'const char *' differs in levels of indirection from 'int'
../src/backend/utils/adt/pgstatfuncs.c(833): warning C4047: '=':
'const char *' differs in levels of indirection from 'int'
../src/backend/utils/adt/pgstatfuncs.c(860): warning C4047: '=':
'const char *' differs in levels of indirection from 'int'
...
...
[1472/2089] Linking target src/backend/postgres.exe
FAILED: [code=1120] src/backend/postgres.exe src/backend/postgres.pdb
"link" @src/backend/postgres.exe.rsp
   Creating library src\backend\postgres.lib
access_transam_xact.c.obj : error LNK2019: unresolved external symbol
pgstat_report_wait_end referenced in function AbortTransaction
postmaster_auxprocess.c.obj : error LNK2001: unresolved external
symbol pgstat_report_wait_end
storage_file_fd.c.obj : error LNK2001: unresolved external symbol
pgstat_report_wait_end
storage_ipc_waiteventset.c.obj : error LNK2001: unresolved external
symbol pgstat_report_wait_end
storage_file_fd.c.obj : error LNK2019: unresolved external symbol
pgstat_report_wait_start referenced in function FileReadV
storage_ipc_waiteventset.c.obj : error LNK2001: unresolved external
symbol pgstat_report_wait_start
src\backend\postgres.exe : fatal error LNK1120: 2 unresolved externals

On Mac:
=======
xact.c:2855:2: error: call to undeclared function
'pgstat_report_wait_end'; ISO C99 and later do not support implicit
function declarations [-Wimplicit-function-declaration]
 2855 |         pgstat_report_wait_end();
      |         ^
xact.c:5263:2: error: call to undeclared function
'pgstat_report_wait_end'; ISO C99 and later do not support implicit
function declarations [-Wimplicit-function-declaration]
 5263 |         pgstat_report_wait_end();
      |         ^
2 errors generated.

Do let me know if everything is good at your end, I can retry to see
if there are any dev-environment issues at my end.

-- 
With Regards,
Amit Kapila.





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:41   ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 18:34     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-18 15:10       ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
@ 2026-02-26 13:52         ` Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 15:14           ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  1 sibling, 1 reply; 33+ messages in thread

From: Alvaro Herrera @ 2026-02-26 13:52 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

Hello

This one removes wait_event.h from pgstat.h.  The only difference from
the previous one, aside from the fact that I had to add pgstat.h to a
few more .c files, is that xlogreader.c needs to include it inside the
#ifndef FRONTEND; otherwise, "ninja -t missingdeps" complain about the
file being used in pg_rewind and pg_waldump (seen in CI).

I think this would conclude the current exercise.

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/

Attachments:

  [text/x-diff] v2-0001-Don-t-include-wait_event.h-in-pgstat.h.patch (36.3K, ../../202602261349.kkwgdwllewwl@alvherre.pgsql/2-v2-0001-Don-t-include-wait_event.h-in-pgstat.h.patch)
  download | inline diff:
From b9bb8fa3753f2c865613bcc2adf695ecb4c8b01e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvherre@kurilemu.de>
Date: Thu, 26 Feb 2026 14:01:02 +0100
Subject: [PATCH v2] Don't include wait_event.h in pgstat.h

Some files now need to include wait_event.h explicitly.

Discussion: https://postgr.es/m/202602181214.gcmhx2vhlxzp@alvherre.pgsql
---
 contrib/pg_prewarm/autoprewarm.c                      | 1 +
 src/backend/access/brin/brin.c                        | 1 +
 src/backend/access/gin/gininsert.c                    | 1 +
 src/backend/access/heap/rewriteheap.c                 | 1 +
 src/backend/access/heap/vacuumlazy.c                  | 1 +
 src/backend/access/nbtree/nbtree.c                    | 1 +
 src/backend/access/nbtree/nbtsort.c                   | 1 +
 src/backend/access/transam/clog.c                     | 1 +
 src/backend/access/transam/parallel.c                 | 1 +
 src/backend/access/transam/slru.c                     | 1 +
 src/backend/access/transam/timeline.c                 | 1 +
 src/backend/access/transam/twophase.c                 | 1 +
 src/backend/access/transam/xact.c                     | 1 +
 src/backend/access/transam/xlog.c                     | 1 +
 src/backend/access/transam/xlogarchive.c              | 1 +
 src/backend/access/transam/xlogfuncs.c                | 1 +
 src/backend/access/transam/xlogreader.c               | 1 +
 src/backend/access/transam/xlogrecovery.c             | 1 +
 src/backend/access/transam/xlogwait.c                 | 1 +
 src/backend/archive/shell_archive.c                   | 1 +
 src/backend/backup/basebackup.c                       | 1 +
 src/backend/backup/basebackup_throttle.c              | 1 +
 src/backend/commands/copyfromparse.c                  | 1 +
 src/backend/commands/copyto.c                         | 1 +
 src/backend/commands/dbcommands.c                     | 1 +
 src/backend/commands/vacuum.c                         | 1 +
 src/backend/executor/nodeAppend.c                     | 1 +
 src/backend/executor/nodeBitmapHeapscan.c             | 1 +
 src/backend/libpq/be-secure-gssapi.c                  | 1 +
 src/backend/libpq/be-secure-openssl.c                 | 1 +
 src/backend/libpq/pqmq.c                              | 1 +
 src/backend/postmaster/autovacuum.c                   | 1 +
 src/backend/postmaster/auxprocess.c                   | 1 +
 src/backend/postmaster/bgworker.c                     | 1 +
 src/backend/postmaster/bgwriter.c                     | 1 +
 src/backend/postmaster/checkpointer.c                 | 1 +
 src/backend/postmaster/pgarch.c                       | 1 +
 src/backend/postmaster/syslogger.c                    | 1 +
 src/backend/postmaster/walwriter.c                    | 1 +
 src/backend/replication/logical/applyparallelworker.c | 1 +
 src/backend/replication/logical/launcher.c            | 1 +
 src/backend/replication/logical/origin.c              | 1 +
 src/backend/replication/logical/reorderbuffer.c       | 1 +
 src/backend/replication/logical/slotsync.c            | 1 +
 src/backend/replication/logical/snapbuild.c           | 3 +++
 src/backend/replication/logical/tablesync.c           | 1 +
 src/backend/replication/logical/worker.c              | 1 +
 src/backend/replication/slot.c                        | 1 +
 src/backend/replication/syncrep.c                     | 1 +
 src/backend/replication/walreceiver.c                 | 1 +
 src/backend/replication/walreceiverfuncs.c            | 1 +
 src/backend/replication/walsender.c                   | 1 +
 src/backend/storage/buffer/bufmgr.c                   | 1 +
 src/backend/storage/file/buffile.c                    | 1 +
 src/backend/storage/file/copydir.c                    | 1 +
 src/backend/storage/file/fd.c                         | 1 +
 src/backend/storage/ipc/dsm_impl.c                    | 1 +
 src/backend/storage/ipc/ipci.c                        | 1 +
 src/backend/storage/ipc/procarray.c                   | 1 +
 src/backend/storage/ipc/procsignal.c                  | 1 +
 src/backend/storage/ipc/shm_mq.c                      | 1 +
 src/backend/storage/ipc/signalfuncs.c                 | 1 +
 src/backend/storage/ipc/standby.c                     | 1 +
 src/backend/storage/ipc/waiteventset.c                | 1 +
 src/backend/storage/lmgr/lwlock.c                     | 1 +
 src/backend/storage/lmgr/predicate.c                  | 1 +
 src/backend/storage/lmgr/proc.c                       | 1 +
 src/backend/storage/smgr/md.c                         | 1 +
 src/backend/storage/sync/sync.c                       | 1 +
 src/backend/utils/adt/misc.c                          | 1 +
 src/backend/utils/adt/pgstatfuncs.c                   | 1 +
 src/backend/utils/cache/relmapper.c                   | 1 +
 src/backend/utils/init/miscinit.c                     | 1 +
 src/common/controldata_utils.c                        | 1 +
 src/include/pgstat.h                                  | 1 -
 src/test/modules/test_shm_mq/setup.c                  | 1 +
 src/test/modules/test_shm_mq/test.c                   | 1 +
 src/test/modules/worker_spi/worker_spi.c              | 1 +
 78 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
index 89e187425cc..ba0bc8e6d4a 100644
--- a/contrib/pg_prewarm/autoprewarm.c
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -48,6 +48,7 @@
 #include "utils/rel.h"
 #include "utils/relfilenumbermap.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 #define AUTOPREWARM_FILE "autoprewarm.blocks"
 
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 6887e421442..126ae349452 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -42,6 +42,7 @@
 #include "utils/memutils.h"
 #include "utils/rel.h"
 #include "utils/tuplesort.h"
+#include "utils/wait_event.h"
 
 /* Magic numbers for parallel state sharing */
 #define PARALLEL_KEY_BRIN_SHARED		UINT64CONST(0xB000000000000001)
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index 0d63fb4ba27..bb07ecccb46 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -34,6 +34,7 @@
 #include "utils/builtins.h"
 #include "utils/rel.h"
 #include "utils/typcache.h"
+#include "utils/wait_event.h"
 
 
 /* Magic numbers for parallel state sharing */
diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c
index 77fd48eb59e..6b19ac3030d 100644
--- a/src/backend/access/heap/rewriteheap.c
+++ b/src/backend/access/heap/rewriteheap.c
@@ -122,6 +122,7 @@
 #include "storage/procarray.h"
 #include "utils/memutils.h"
 #include "utils/rel.h"
+#include "utils/wait_event.h"
 
 /*
  * State associated with a rewrite operation. This is opaque to the user
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index 4be267ff657..259f0822564 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -154,6 +154,7 @@
 #include "utils/lsyscache.h"
 #include "utils/pg_rusage.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 3dec1ee657d..6d0a6f27f3f 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -35,6 +35,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/index_selfuncs.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index 3a45508f62e..a9b0618f464 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -56,6 +56,7 @@
 #include "utils/rel.h"
 #include "utils/sortsupport.h"
 #include "utils/tuplesort.h"
+#include "utils/wait_event.h"
 
 
 /* Magic numbers for parallel state sharing */
diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c
index b5c38bbb162..3ee1cfdbc24 100644
--- a/src/backend/access/transam/clog.c
+++ b/src/backend/access/transam/clog.c
@@ -45,6 +45,7 @@
 #include "storage/proc.h"
 #include "storage/sync.h"
 #include "utils/guc_hooks.h"
+#include "utils/wait_event.h"
 
 /*
  * Defines for CLOG page sizes.  A page is the same BLCKSZ as is used
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index 44786dc131f..6b350cfe005 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -44,6 +44,7 @@
 #include "utils/memutils.h"
 #include "utils/relmapper.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 /*
  * We don't want to waste a lot of memory on an error queue which, most of
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c
index 549c7e3e64b..556edcbf7cb 100644
--- a/src/backend/access/transam/slru.c
+++ b/src/backend/access/transam/slru.c
@@ -71,6 +71,7 @@
 #include "storage/fd.h"
 #include "storage/shmem.h"
 #include "utils/guc.h"
+#include "utils/wait_event.h"
 
 /*
  * Converts segment number to the filename of the segment.
diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/transam/timeline.c
index 60ee28665b1..68e5f692d26 100644
--- a/src/backend/access/transam/timeline.c
+++ b/src/backend/access/transam/timeline.c
@@ -41,6 +41,7 @@
 #include "access/xlogdefs.h"
 #include "pgstat.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 
 /*
  * Copies all timeline history files with id's between 'begin' and 'end'
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index e4340b59640..5cce76752a2 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -106,6 +106,7 @@
 #include "utils/injection_point.h"
 #include "utils/memutils.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /*
  * Directory where Two-phase commit files reside within PGDATA
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index eba4f063168..aafc53e0164 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -72,6 +72,7 @@
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
 #include "utils/typcache.h"
+#include "utils/wait_event.h"
 
 /*
  *	User-tweakable parameters
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 13cce9b49f1..fb5085e4b38 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -105,6 +105,7 @@
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 #ifdef WAL_DEBUG
 #include "utils/memutils.h"
diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c
index aa0c2fe3afd..9a0c8097cb1 100644
--- a/src/backend/access/transam/xlogarchive.c
+++ b/src/backend/access/transam/xlogarchive.c
@@ -31,6 +31,7 @@
 #include "replication/walsender.h"
 #include "storage/fd.h"
 #include "storage/ipc.h"
+#include "utils/wait_event.h"
 
 /*
  * Attempt to retrieve the specified file from off-line archival storage.
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c
index 2efe4105efb..8965be29703 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -34,6 +34,7 @@
 #include "utils/memutils.h"
 #include "utils/pg_lsn.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /*
  * Backup-related variables.
diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index 03ada8aa0c5..8cb2110cb99 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -36,6 +36,7 @@
 #ifndef FRONTEND
 #include "pgstat.h"
 #include "storage/bufmgr.h"
+#include "utils/wait_event.h"
 #else
 #include "common/logging.h"
 #endif
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index ecd66fd86a4..1e3e11be0ae 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -65,6 +65,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/ps_status.h"
 #include "utils/pg_rusage.h"
+#include "utils/wait_event.h"
 
 /* Unsupported old recovery command file names (relative to $PGDATA) */
 #define RECOVERY_COMMAND_FILE	"recovery.conf"
diff --git a/src/backend/access/transam/xlogwait.c b/src/backend/access/transam/xlogwait.c
index d286ff63123..bf4630677b4 100644
--- a/src/backend/access/transam/xlogwait.c
+++ b/src/backend/access/transam/xlogwait.c
@@ -60,6 +60,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/pg_lsn.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 
 static int	waitlsn_cmp(const pairingheap_node *a, const pairingheap_node *b,
diff --git a/src/backend/archive/shell_archive.c b/src/backend/archive/shell_archive.c
index 5b565968818..0b427a68809 100644
--- a/src/backend/archive/shell_archive.c
+++ b/src/backend/archive/shell_archive.c
@@ -22,6 +22,7 @@
 #include "archive/shell_archive.h"
 #include "common/percentrepl.h"
 #include "pgstat.h"
+#include "utils/wait_event.h"
 
 static bool shell_archive_configured(ArchiveModuleState *state);
 static bool shell_archive_file(ArchiveModuleState *state,
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 2d74c648335..ab1fbae8001 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -48,6 +48,7 @@
 #include "utils/ps_status.h"
 #include "utils/relcache.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 /*
  * How much data do we want to send in one CopyData message? Note that
diff --git a/src/backend/backup/basebackup_throttle.c b/src/backend/backup/basebackup_throttle.c
index e112eed7485..4d8d90f356b 100644
--- a/src/backend/backup/basebackup_throttle.c
+++ b/src/backend/backup/basebackup_throttle.c
@@ -19,6 +19,7 @@
 #include "pgstat.h"
 #include "storage/latch.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 typedef struct bbsink_throttle
 {
diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index 6b00d49c50f..8a93a892ba0 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -74,6 +74,7 @@
 #include "port/pg_bswap.h"
 #include "utils/builtins.h"
 #include "utils/rel.h"
+#include "utils/wait_event.h"
 
 #define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
 #define OCTVALUE(c) ((c) - '0')
diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c
index 9ceeff6d99e..d6ef7275a64 100644
--- a/src/backend/commands/copyto.c
+++ b/src/backend/commands/copyto.c
@@ -37,6 +37,7 @@
 #include "utils/memutils.h"
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 /*
  * Represents the different dest cases we need to worry about at
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 740c526e92d..9b18bb4a17e 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -70,6 +70,7 @@
 #include "utils/relmapper.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /*
  * Create database strategy.
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 03932f45c8a..c61c9eb0a01 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -61,6 +61,7 @@
 #include "utils/memutils.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /*
  * Minimum interval for cost-based vacuum delay reports from a parallel worker.
diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c
index 7138dc692c6..677b9e367c0 100644
--- a/src/backend/executor/nodeAppend.c
+++ b/src/backend/executor/nodeAppend.c
@@ -64,6 +64,7 @@
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "storage/latch.h"
+#include "utils/wait_event.h"
 
 /* Shared state for parallel-aware Append. */
 struct ParallelAppendState
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index c68c26cbf38..e0b6df64767 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -45,6 +45,7 @@
 #include "storage/bufmgr.h"
 #include "utils/rel.h"
 #include "utils/spccache.h"
+#include "utils/wait_event.h"
 
 static void BitmapTableScanSetup(BitmapHeapScanState *node);
 static TupleTableSlot *BitmapHeapNext(BitmapHeapScanState *node);
diff --git a/src/backend/libpq/be-secure-gssapi.c b/src/backend/libpq/be-secure-gssapi.c
index df7dc79b827..ff355201afa 100644
--- a/src/backend/libpq/be-secure-gssapi.c
+++ b/src/backend/libpq/be-secure-gssapi.c
@@ -23,6 +23,7 @@
 #include "port/pg_bswap.h"
 #include "utils/injection_point.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.c
index 4da6ac22ff9..14c6532bb16 100644
--- a/src/backend/libpq/be-secure-openssl.c
+++ b/src/backend/libpq/be-secure-openssl.c
@@ -35,6 +35,7 @@
 #include "storage/latch.h"
 #include "utils/guc.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * These SSL-related #includes must come after all system-provided headers.
diff --git a/src/backend/libpq/pqmq.c b/src/backend/libpq/pqmq.c
index 6e4bbfb5aa1..8270bcc8007 100644
--- a/src/backend/libpq/pqmq.c
+++ b/src/backend/libpq/pqmq.c
@@ -22,6 +22,7 @@
 #include "replication/logicalworker.h"
 #include "tcop/tcopprot.h"
 #include "utils/builtins.h"
+#include "utils/wait_event.h"
 
 static shm_mq_handle *pq_mq_handle = NULL;
 static bool pq_mq_busy = false;
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 6fde740465f..695e187ba11 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -109,6 +109,7 @@
 #include "utils/syscache.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/postmaster/auxprocess.c b/src/backend/postmaster/auxprocess.c
index 8ea800c0bbd..cf24f662d27 100644
--- a/src/backend/postmaster/auxprocess.c
+++ b/src/backend/postmaster/auxprocess.c
@@ -24,6 +24,7 @@
 #include "storage/procsignal.h"
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
+#include "utils/wait_event.h"
 
 
 static void ShutdownAuxiliaryProcess(int code, Datum arg);
diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c
index 8678ea4e139..0104a86b9ec 100644
--- a/src/backend/postmaster/bgworker.c
+++ b/src/backend/postmaster/bgworker.c
@@ -34,6 +34,7 @@
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
+#include "utils/wait_event.h"
 
 /*
  * The postmaster's list of registered background workers, in private memory.
diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c
index 0956bd39a85..1d8947774a9 100644
--- a/src/backend/postmaster/bgwriter.c
+++ b/src/backend/postmaster/bgwriter.c
@@ -51,6 +51,7 @@
 #include "utils/memutils.h"
 #include "utils/resowner.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /*
  * GUC parameters
diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c
index e03c19123bc..3c982c6ffac 100644
--- a/src/backend/postmaster/checkpointer.c
+++ b/src/backend/postmaster/checkpointer.c
@@ -67,6 +67,7 @@
 #include "utils/guc.h"
 #include "utils/memutils.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 
 /*----------
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 82731e452fc..fa4bdfe9ab9 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -53,6 +53,7 @@
 #include "utils/ps_status.h"
 #include "utils/resowner.h"
 #include "utils/timeout.h"
+#include "utils/wait_event.h"
 
 
 /* ----------
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index 86c5e376b40..9792f638718 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -51,6 +51,7 @@
 #include "utils/guc.h"
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
+#include "utils/wait_event.h"
 
 /*
  * We read() into a temp buffer twice as big as a chunk, so that any fragment
diff --git a/src/backend/postmaster/walwriter.c b/src/backend/postmaster/walwriter.c
index 7c0e2809c17..9cd86ad7022 100644
--- a/src/backend/postmaster/walwriter.c
+++ b/src/backend/postmaster/walwriter.c
@@ -62,6 +62,7 @@
 #include "utils/hsearch.h"
 #include "utils/memutils.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c
index 1730ace5490..3630f8497d6 100644
--- a/src/backend/replication/logical/applyparallelworker.c
+++ b/src/backend/replication/logical/applyparallelworker.c
@@ -171,6 +171,7 @@
 #include "utils/inval.h"
 #include "utils/memutils.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 #define PG_LOGICAL_APPLY_SHM_MAGIC 0x787ca067
 
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index e6112e11ec2..09964198550 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -44,6 +44,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /* max sleep time between cycles (3min) */
 #define DEFAULT_NAPTIME_PER_CYCLE 180000L
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index c3271a6fd0e..26afd8f0af9 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -95,6 +95,7 @@
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /* paths for replication origin checkpoint files */
 #define PG_REPLORIGIN_CHECKPOINT_FILENAME PG_LOGICAL_DIR "/replorigin_checkpoint"
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index e832fa0d8ea..b7664b90006 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -113,6 +113,7 @@
 #include "utils/memutils.h"
 #include "utils/rel.h"
 #include "utils/relfilenumbermap.h"
+#include "utils/wait_event.h"
 
 /*
  * Each transaction has an 8MB limit for invalidation messages distributed from
diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c
index 062a08ccb88..19976efe4f2 100644
--- a/src/backend/replication/logical/slotsync.c
+++ b/src/backend/replication/logical/slotsync.c
@@ -75,6 +75,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
+#include "utils/wait_event.h"
 
 /*
  * Struct for sharing information to control slot synchronization.
diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c
index 7f79621b57e..eddb3d9105c 100644
--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -144,6 +144,9 @@
 #include "utils/memutils.h"
 #include "utils/snapmgr.h"
 #include "utils/snapshot.h"
+#include "utils/wait_event.h"
+
+
 /*
  * Starting a transaction -- which we need to do while exporting a snapshot --
  * removes knowledge about the previously used resowner, so we save it here.
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index 2f2f0121ecf..121cd058856 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -121,6 +121,7 @@
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
 #include "utils/usercontext.h"
+#include "utils/wait_event.h"
 
 List	   *table_states_not_ready = NIL;
 
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index bae8c011390..260bf70280b 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -295,6 +295,7 @@
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
 #include "utils/usercontext.h"
+#include "utils/wait_event.h"
 
 #define NAPTIME_PER_CYCLE 1000	/* max sleep time between cycles (1s) */
 
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index 28c7019402b..a9092fc2382 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -59,6 +59,7 @@
 #include "utils/guc_hooks.h"
 #include "utils/injection_point.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 /*
  * Replication slot on-disk data structure.
diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c
index d1582a5d711..9cecc83ed68 100644
--- a/src/backend/replication/syncrep.c
+++ b/src/backend/replication/syncrep.c
@@ -85,6 +85,7 @@
 #include "tcop/tcopprot.h"
 #include "utils/guc_hooks.h"
 #include "utils/ps_status.h"
+#include "utils/wait_event.h"
 
 /* User-settable parameters for sync rep */
 char	   *SyncRepStandbyNames;
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index 7c1b8757d7d..fabe3c73034 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -79,6 +79,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/ps_status.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c
index e62e8a20420..45b9d4f09f2 100644
--- a/src/backend/replication/walreceiverfuncs.c
+++ b/src/backend/replication/walreceiverfuncs.c
@@ -30,6 +30,7 @@
 #include "storage/proc.h"
 #include "storage/shmem.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 WalRcvData *WalRcv = NULL;
 
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 2cde8ebc729..829ec538ea5 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -98,6 +98,7 @@
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /* Minimum interval used by walsender for stats flushes, in ms */
 #define WALSENDER_STATS_FLUSH_INTERVAL         1000
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index d1babaff023..5f3d083e938 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -68,6 +68,7 @@
 #include "utils/rel.h"
 #include "utils/resowner.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /* Note: these two macros only work on shared buffers, not local ones! */
diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c
index ddf3a410d6f..c4afe4d368a 100644
--- a/src/backend/storage/file/buffile.c
+++ b/src/backend/storage/file/buffile.c
@@ -53,6 +53,7 @@
 #include "storage/bufmgr.h"
 #include "storage/fd.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 /*
  * We break BufFiles into gigabyte-sized segments, regardless of RELSEG_SIZE.
diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c
index 596d9070fd8..5ee141f13a5 100644
--- a/src/backend/storage/file/copydir.c
+++ b/src/backend/storage/file/copydir.c
@@ -29,6 +29,7 @@
 #include "pgstat.h"
 #include "storage/copydir.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 
 /* GUCs */
 int			file_copy_method = FILE_COPY_METHOD_COPY;
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 5d07b64a1ef..01f1bd6e687 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -101,6 +101,7 @@
 #include "utils/guc_hooks.h"
 #include "utils/resowner.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 /* Define PG_FLUSH_DATA_WORKS if we have an implementation for pg_flush_data */
 #if defined(HAVE_SYNC_FILE_RANGE)
diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c
index e208457df27..e8c07805f59 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -68,6 +68,7 @@
 #include "storage/fd.h"
 #include "utils/guc.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 #ifdef USE_DSM_POSIX
 static bool dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c
index 1f7e933d500..a4785daf1e5 100644
--- a/src/backend/storage/ipc/ipci.c
+++ b/src/backend/storage/ipc/ipci.c
@@ -52,6 +52,7 @@
 #include "storage/sinvaladt.h"
 #include "utils/guc.h"
 #include "utils/injection_point.h"
+#include "utils/wait_event.h"
 
 /* GUCs */
 int			shared_memory_type = DEFAULT_SHARED_MEMORY_TYPE;
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index 40312df2cac..406b8253f8b 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -67,6 +67,7 @@
 #include "utils/lsyscache.h"
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 #define UINT32_ACCESS_ONCE(var)		 ((uint32)(*((volatile uint32 *)&(var))))
 
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index 7505c9d3a37..f0575aca949 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -33,6 +33,7 @@
 #include "storage/smgr.h"
 #include "tcop/tcopprot.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * The SIGUSR1 signal is multiplexed to support signaling multiple event
diff --git a/src/backend/storage/ipc/shm_mq.c b/src/backend/storage/ipc/shm_mq.c
index 3ce6068ac54..ab0d4cdf063 100644
--- a/src/backend/storage/ipc/shm_mq.c
+++ b/src/backend/storage/ipc/shm_mq.c
@@ -25,6 +25,7 @@
 #include "storage/shm_mq.h"
 #include "storage/spin.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * This structure represents the actual queue, stored in shared memory.
diff --git a/src/backend/storage/ipc/signalfuncs.c b/src/backend/storage/ipc/signalfuncs.c
index d48b4fe3799..800b699de21 100644
--- a/src/backend/storage/ipc/signalfuncs.c
+++ b/src/backend/storage/ipc/signalfuncs.c
@@ -25,6 +25,7 @@
 #include "storage/procarray.h"
 #include "utils/acl.h"
 #include "utils/fmgrprotos.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c
index d83afbfb9d6..f3ad90c7c7a 100644
--- a/src/backend/storage/ipc/standby.c
+++ b/src/backend/storage/ipc/standby.c
@@ -35,6 +35,7 @@
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /* User-settable GUC parameters */
 int			max_standby_archive_delay = 30 * 1000;
diff --git a/src/backend/storage/ipc/waiteventset.c b/src/backend/storage/ipc/waiteventset.c
index 772e350a0c0..0f228e1e7b8 100644
--- a/src/backend/storage/ipc/waiteventset.c
+++ b/src/backend/storage/ipc/waiteventset.c
@@ -77,6 +77,7 @@
 #include "storage/waiteventset.h"
 #include "utils/memutils.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 /*
  * Select the fd readiness primitive to use. Normally the "most modern"
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 517c55375b4..49382de88fc 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -85,6 +85,7 @@
 #include "storage/procnumber.h"
 #include "storage/spin.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 #ifdef LWLOCK_STATS
 #include "utils/hsearch.h"
diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c
index fe75ead3501..548b4f66470 100644
--- a/src/backend/storage/lmgr/predicate.c
+++ b/src/backend/storage/lmgr/predicate.c
@@ -214,6 +214,7 @@
 #include "utils/guc_hooks.h"
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 /* Uncomment the next line to test the graceful degradation code. */
 /* #define TEST_SUMMARIZE_SERIAL */
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index 771b006b522..0568f3cf9b1 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -53,6 +53,7 @@
 #include "storage/standby.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /* GUC variables */
 int			DeadlockTimeout = 1000;
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 443434e4ea8..dee29037b16 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -40,6 +40,7 @@
 #include "storage/smgr.h"
 #include "storage/sync.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * The magnetic disk storage manager keeps track of open file
diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c
index b1accc68b95..2c964b6f3d9 100644
--- a/src/backend/storage/sync/sync.c
+++ b/src/backend/storage/sync/sync.c
@@ -31,6 +31,7 @@
 #include "storage/md.h"
 #include "utils/hsearch.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * In some contexts (currently, standalone backends and the checkpointer)
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index 32a787d7df7..864032c32bf 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -46,6 +46,7 @@
 #include "utils/ruleutils.h"
 #include "utils/syscache.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index b1df96e7b0b..50ea9e8fb83 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -31,6 +31,7 @@
 #include "utils/acl.h"
 #include "utils/builtins.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 #define UINT32_ACCESS_ONCE(var)		 ((uint32)(*((volatile uint32 *)&(var))))
 
diff --git a/src/backend/utils/cache/relmapper.c b/src/backend/utils/cache/relmapper.c
index 778b14a2318..3aaf466868d 100644
--- a/src/backend/utils/cache/relmapper.c
+++ b/src/backend/utils/cache/relmapper.c
@@ -54,6 +54,7 @@
 #include "storage/lwlock.h"
 #include "utils/inval.h"
 #include "utils/relmapper.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index 03f6c8479f2..ba191977697 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -55,6 +55,7 @@
 #include "utils/pidfile.h"
 #include "utils/syscache.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 
 #define DIRECTORY_LOCK_FILE		"postmaster.pid"
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 14530c6489a..4ab116afcde 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -37,6 +37,7 @@
 #ifndef FRONTEND
 #include "pgstat.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 #endif
 
 /*
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 0e9d2b4c623..216b93492ba 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -18,7 +18,6 @@
 #include "utils/backend_progress.h" /* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/backend_status.h"	/* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/pgstat_kind.h"
-#include "utils/wait_event.h"	/* for backward compatibility */	/* IWYU pragma: export */
 
 
 /* avoid including access/transam.h */
diff --git a/src/test/modules/test_shm_mq/setup.c b/src/test/modules/test_shm_mq/setup.c
index 579e5933d28..d9a277a1cf6 100644
--- a/src/test/modules/test_shm_mq/setup.c
+++ b/src/test/modules/test_shm_mq/setup.c
@@ -21,6 +21,7 @@
 #include "storage/shm_toc.h"
 #include "test_shm_mq.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 typedef struct
 {
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index fe1794c6077..2af88d7674e 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -17,6 +17,7 @@
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "varatt.h"
+#include "utils/wait_event.h"
 
 #include "test_shm_mq.h"
 
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index d1e4a2bd952..b89954279c0 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -39,6 +39,7 @@
 #include "utils/acl.h"
 #include "utils/builtins.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 PG_MODULE_MAGIC;
 
-- 
2.47.3

^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:41   ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 18:34     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-18 15:10       ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 13:52         ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
@ 2026-02-26 15:14           ` Andres Freund <andres@anarazel.de>
  2026-02-26 15:59             ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  0 siblings, 1 reply; 33+ messages in thread

From: Andres Freund @ 2026-02-26 15:14 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@kurilemu.de>; Heikki Linnakangas <hlinnaka@iki.fi>; +Cc: pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

Hi,

Thanks for pushing the pgstat.h slimdown patch - I should have gotten to that
... but didn't.

On 2026-02-26 14:52:10 +0100, Alvaro Herrera wrote:
> This one removes wait_event.h from pgstat.h.  The only difference from
> the previous one, aside from the fact that I had to add pgstat.h to a
> few more .c files, is that xlogreader.c needs to include it inside the
> #ifndef FRONTEND; otherwise, "ninja -t missingdeps" complain about the
> file being used in pg_rewind and pg_waldump (seen in CI).

I'm somewhat worried about the amount of breakage this will cause in
extensions.  Many extensions use something like
   WaitLatch(wait_event_info = WAIT_EVENT_EXTENSION)
and many of them won't have included wait_event.h.

OTOH, Heikki's interrupt patch will already cause widespread breakage in just
such code, so maybe this is the time to do it.

Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:41   ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 18:34     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-18 15:10       ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 13:52         ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 15:14           ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
@ 2026-02-26 15:59             ` Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 16:19               ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 16:27               ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  0 siblings, 2 replies; 33+ messages in thread

From: Alvaro Herrera @ 2026-02-26 15:59 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: Heikki Linnakangas <hlinnaka@iki.fi>; pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

On 2026-Feb-26, Andres Freund wrote:

> On 2026-02-26 14:52:10 +0100, Alvaro Herrera wrote:
> > This one removes wait_event.h from pgstat.h.  The only difference from
> > the previous one, aside from the fact that I had to add pgstat.h to a
> > few more .c files, is that xlogreader.c needs to include it inside the
> > #ifndef FRONTEND; otherwise, "ninja -t missingdeps" complain about the
> > file being used in pg_rewind and pg_waldump (seen in CI).
> 
> I'm somewhat worried about the amount of breakage this will cause in
> extensions.  Many extensions use something like
>    WaitLatch(wait_event_info = WAIT_EVENT_EXTENSION)
> and many of them won't have included wait_event.h.

Yeah, I considered that, and instead of breaking these, to include
wait_event.h in latch.h.  This sounds a very reasonable thing to do.
But then I searched for other headers that have a wait_event_info
parameter in one of their functions, and if we force those to also
acquire wait_event.h, then the pollution is much worse than if we just
leave it in pgstat.h.  (condition_variable.h, fd.h, proc.h, barrier.h). 

The problem is that some of those headers are in turn being included by
others; most notably condition_variable.h is used in execnodes.h and
others, and that makes a huge mess.  (And it can't be removed.)

However, maybe we can just not be so principled about it, add it to
latch.h, and then we don't break the whole world.  I'll try that.

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/
"Finally, the phrase, 'No one was ever fired for buying an IBM' I don't believe
has ever been translated into German."                       (Leonard Tramiel)





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:41   ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 18:34     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-18 15:10       ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 13:52         ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 15:14           ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-26 15:59             ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
@ 2026-02-26 16:19               ` Alvaro Herrera <alvherre@kurilemu.de>
  1 sibling, 0 replies; 33+ messages in thread

From: Alvaro Herrera @ 2026-02-26 16:19 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: Heikki Linnakangas <hlinnaka@iki.fi>; pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

On 2026-Feb-26, Alvaro Herrera wrote:

> However, maybe we can just not be so principled about it, add it to
> latch.h, and then we don't break the whole world.  I'll try that.

This one does it that way.

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"Cuando mañana llegue pelearemos segun lo que mañana exija" (Mowgli)

Attachments:

  [text/x-diff] v3-0001-Don-t-include-wait_event.h-in-pgstat.h.patch (7.8K, ../../202602261618.manjpfqcmp66@alvherre.pgsql/2-v3-0001-Don-t-include-wait_event.h-in-pgstat.h.patch)
  download | inline diff:
From 716ff1063aa274c1bfcff83515da8d706c03e657 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvherre@kurilemu.de>
Date: Thu, 26 Feb 2026 17:15:22 +0100
Subject: [PATCH v3] Don't include wait_event.h in pgstat.h

Avoid breaking too much third-party code by including wait_events.h in
latch.h; this makes sense anyway, because many extension do WaitLatch()
using a wait event value.

Discussion: https://postgr.es/m/202602181214.gcmhx2vhlxzp@alvherre.pgsql
---
 src/backend/access/transam/slru.c        | 1 +
 src/backend/access/transam/timeline.c    | 1 +
 src/backend/access/transam/xlogarchive.c | 1 +
 src/backend/access/transam/xlogreader.c  | 1 +
 src/backend/archive/shell_archive.c      | 1 +
 src/backend/backup/basebackup.c          | 1 +
 src/backend/replication/logical/origin.c | 1 +
 src/backend/storage/file/buffile.c       | 1 +
 src/backend/storage/file/copydir.c       | 1 +
 src/backend/storage/file/fd.c            | 1 +
 src/backend/storage/ipc/dsm_impl.c       | 1 +
 src/backend/storage/smgr/md.c            | 1 +
 src/backend/utils/cache/relmapper.c      | 1 +
 src/common/controldata_utils.c           | 1 +
 src/include/pgstat.h                     | 1 -
 src/include/storage/latch.h              | 1 +
 16 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c
index 549c7e3e64b..556edcbf7cb 100644
--- a/src/backend/access/transam/slru.c
+++ b/src/backend/access/transam/slru.c
@@ -71,6 +71,7 @@
 #include "storage/fd.h"
 #include "storage/shmem.h"
 #include "utils/guc.h"
+#include "utils/wait_event.h"
 
 /*
  * Converts segment number to the filename of the segment.
diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/transam/timeline.c
index 60ee28665b1..68e5f692d26 100644
--- a/src/backend/access/transam/timeline.c
+++ b/src/backend/access/transam/timeline.c
@@ -41,6 +41,7 @@
 #include "access/xlogdefs.h"
 #include "pgstat.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 
 /*
  * Copies all timeline history files with id's between 'begin' and 'end'
diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c
index aa0c2fe3afd..9a0c8097cb1 100644
--- a/src/backend/access/transam/xlogarchive.c
+++ b/src/backend/access/transam/xlogarchive.c
@@ -31,6 +31,7 @@
 #include "replication/walsender.h"
 #include "storage/fd.h"
 #include "storage/ipc.h"
+#include "utils/wait_event.h"
 
 /*
  * Attempt to retrieve the specified file from off-line archival storage.
diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index 03ada8aa0c5..8cb2110cb99 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -36,6 +36,7 @@
 #ifndef FRONTEND
 #include "pgstat.h"
 #include "storage/bufmgr.h"
+#include "utils/wait_event.h"
 #else
 #include "common/logging.h"
 #endif
diff --git a/src/backend/archive/shell_archive.c b/src/backend/archive/shell_archive.c
index 5b565968818..0b427a68809 100644
--- a/src/backend/archive/shell_archive.c
+++ b/src/backend/archive/shell_archive.c
@@ -22,6 +22,7 @@
 #include "archive/shell_archive.h"
 #include "common/percentrepl.h"
 #include "pgstat.h"
+#include "utils/wait_event.h"
 
 static bool shell_archive_configured(ArchiveModuleState *state);
 static bool shell_archive_file(ArchiveModuleState *state,
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 2d74c648335..ab1fbae8001 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -48,6 +48,7 @@
 #include "utils/ps_status.h"
 #include "utils/relcache.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 /*
  * How much data do we want to send in one CopyData message? Note that
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index c3271a6fd0e..26afd8f0af9 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -95,6 +95,7 @@
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /* paths for replication origin checkpoint files */
 #define PG_REPLORIGIN_CHECKPOINT_FILENAME PG_LOGICAL_DIR "/replorigin_checkpoint"
diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c
index ddf3a410d6f..c4afe4d368a 100644
--- a/src/backend/storage/file/buffile.c
+++ b/src/backend/storage/file/buffile.c
@@ -53,6 +53,7 @@
 #include "storage/bufmgr.h"
 #include "storage/fd.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 /*
  * We break BufFiles into gigabyte-sized segments, regardless of RELSEG_SIZE.
diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c
index 596d9070fd8..5ee141f13a5 100644
--- a/src/backend/storage/file/copydir.c
+++ b/src/backend/storage/file/copydir.c
@@ -29,6 +29,7 @@
 #include "pgstat.h"
 #include "storage/copydir.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 
 /* GUCs */
 int			file_copy_method = FILE_COPY_METHOD_COPY;
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 5d07b64a1ef..01f1bd6e687 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -101,6 +101,7 @@
 #include "utils/guc_hooks.h"
 #include "utils/resowner.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 /* Define PG_FLUSH_DATA_WORKS if we have an implementation for pg_flush_data */
 #if defined(HAVE_SYNC_FILE_RANGE)
diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c
index e208457df27..e8c07805f59 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -68,6 +68,7 @@
 #include "storage/fd.h"
 #include "utils/guc.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 #ifdef USE_DSM_POSIX
 static bool dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 443434e4ea8..dee29037b16 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -40,6 +40,7 @@
 #include "storage/smgr.h"
 #include "storage/sync.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * The magnetic disk storage manager keeps track of open file
diff --git a/src/backend/utils/cache/relmapper.c b/src/backend/utils/cache/relmapper.c
index 778b14a2318..3aaf466868d 100644
--- a/src/backend/utils/cache/relmapper.c
+++ b/src/backend/utils/cache/relmapper.c
@@ -54,6 +54,7 @@
 #include "storage/lwlock.h"
 #include "utils/inval.h"
 #include "utils/relmapper.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 14530c6489a..4ab116afcde 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -37,6 +37,7 @@
 #ifndef FRONTEND
 #include "pgstat.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 #endif
 
 /*
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 0e9d2b4c623..216b93492ba 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -18,7 +18,6 @@
 #include "utils/backend_progress.h" /* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/backend_status.h"	/* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/pgstat_kind.h"
-#include "utils/wait_event.h"	/* for backward compatibility */	/* IWYU pragma: export */
 
 
 /* avoid including access/transam.h */
diff --git a/src/include/storage/latch.h b/src/include/storage/latch.h
index fbdadc86959..cbefc7ed154 100644
--- a/src/include/storage/latch.h
+++ b/src/include/storage/latch.h
@@ -104,6 +104,7 @@
 #include <signal.h>
 
 #include "storage/waiteventset.h"	/* for WL_* arguments to WaitLatch */
+#include "utils/wait_event.h"	/* IWYU pragma: export */
 
 /*
  * Latch structure should be treated as opaque and only accessed through
-- 
2.47.3

^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:41   ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 18:34     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-18 15:10       ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 13:52         ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 15:14           ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-26 15:59             ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
@ 2026-02-26 16:27               ` Andres Freund <andres@anarazel.de>
  2026-02-26 17:07                 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 17:40                 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-27 10:37                 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  1 sibling, 3 replies; 33+ messages in thread

From: Andres Freund @ 2026-02-26 16:27 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@kurilemu.de>; +Cc: Heikki Linnakangas <hlinnaka@iki.fi>; pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

Hi,

On 2026-02-26 16:59:12 +0100, Alvaro Herrera wrote:
> On 2026-Feb-26, Andres Freund wrote:
> > On 2026-02-26 14:52:10 +0100, Alvaro Herrera wrote:
> > > This one removes wait_event.h from pgstat.h.  The only difference from
> > > the previous one, aside from the fact that I had to add pgstat.h to a
> > > few more .c files, is that xlogreader.c needs to include it inside the
> > > #ifndef FRONTEND; otherwise, "ninja -t missingdeps" complain about the
> > > file being used in pg_rewind and pg_waldump (seen in CI).
> >
> > I'm somewhat worried about the amount of breakage this will cause in
> > extensions.  Many extensions use something like
> >    WaitLatch(wait_event_info = WAIT_EVENT_EXTENSION)
> > and many of them won't have included wait_event.h.
>
> Yeah, I considered that, and instead of breaking these, to include
> wait_event.h in latch.h.  This sounds a very reasonable thing to do.
> But then I searched for other headers that have a wait_event_info
> parameter in one of their functions, and if we force those to also
> acquire wait_event.h, then the pollution is much worse than if we just
> leave it in pgstat.h.  (condition_variable.h, fd.h, proc.h, barrier.h).
>
> The problem is that some of those headers are in turn being included by
> others; most notably condition_variable.h is used in execnodes.h and
> others, and that makes a huge mess.  (And it can't be removed.)
>
> However, maybe we can just not be so principled about it, add it to
> latch.h, and then we don't break the whole world.  I'll try that.

FWIW, regardless of what we choose here (i.e. whether and where to
"unnecessarily" include wait_event.h), I'd be in favor of fixing all the
fallout in our source tree, just for cleanliness' sake. It's also presumably
the part of the patch that would be the most pain to keep updated.


I'm not sure that including in latch.h really would an improvement though -
that's included in proc.h and libpq.h, which both are fairly widely included
[1].


FWIW, I'm a lot less concerned with extension users of condition_variable.h,
fd.h, proc.h, barrier.h breaking due to removal of an implicit include, I
don't think they are remotely as widely used.


Greetings,

Andres Freund

[1] Although at least the include in libpq.h seems like it could trivially be
replaced by a forward declaration. There's only three .c files that need to be
fixed for that...





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:41   ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 18:34     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-18 15:10       ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 13:52         ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 15:14           ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-26 15:59             ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 16:27               ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
@ 2026-02-26 17:07                 ` Alvaro Herrera <alvherre@kurilemu.de>
  2 siblings, 0 replies; 33+ messages in thread

From: Alvaro Herrera @ 2026-02-26 17:07 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: Heikki Linnakangas <hlinnaka@iki.fi>; pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

Hi,

On 2026-Feb-26, Andres Freund wrote:

> I'm not sure that including in latch.h really would an improvement though -
> that's included in proc.h and libpq.h, which both are fairly widely included
> [1].

> [1] Although at least the include in libpq.h seems like it could trivially be
> replaced by a forward declaration. There's only three .c files that need to be
> fixed for that...

Okay, let's start there -- pushed that for now.

Pity, that we can't remove latch.h from proc.h.  That's really where
most of the mess is, here ...

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/
Essentially, you're proposing Kevlar shoes as a solution for the problem
that you want to walk around carrying a loaded gun aimed at your foot.
(Tom Lane)





^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:41   ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 18:34     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-18 15:10       ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 13:52         ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 15:14           ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-26 15:59             ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 16:27               ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
@ 2026-02-26 17:40                 ` Alvaro Herrera <alvherre@kurilemu.de>
  2 siblings, 0 replies; 33+ messages in thread

From: Alvaro Herrera @ 2026-02-26 17:40 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: Heikki Linnakangas <hlinnaka@iki.fi>; pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

On 2026-Feb-26, Andres Freund wrote:

> I'm not sure that including in latch.h really would an improvement though -
> that's included in proc.h and libpq.h, which both are fairly widely included
> [1].

Although we cannot remove latch.h, what we can do is remove proc.h from
shm_mq.h, which is actually very good because the proliferation of stuff
from there is enormous.  See the attached.  Practically all the network
of dependents of proc.h comes from there.  The fallout is even somewhat
insane.  I think this is a good cleanup.

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/
"Industry suffers from the managerial dogma that for the sake of stability
and continuity, the company should be independent of the competence of
individual employees."                                      (E. Dijkstra)

Attachments:

  [text/x-diff] 0001-Avoid-including-proc.h-in-shm_mq.h.patch (13.0K, ../../202602261733.s2rkxezwuif6@alvherre.pgsql/2-0001-Avoid-including-proc.h-in-shm_mq.h.patch)
  download | inline diff:
From ba3dec8480aae835e458fdc35fff67e13dfb611e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvherre@kurilemu.de>
Date: Thu, 26 Feb 2026 18:29:49 +0100
Subject: [PATCH] Avoid including proc.h in shm_mq.h

This prevents proliferation of proc.h to tons of other places.
---
 src/backend/access/brin/brin.c                        | 1 +
 src/backend/access/gin/gininsert.c                    | 1 +
 src/backend/access/heap/heapam.c                      | 1 +
 src/backend/access/heap/vacuumlazy.c                  | 1 +
 src/backend/access/nbtree/nbtsort.c                   | 1 +
 src/backend/access/transam/parallel.c                 | 1 +
 src/backend/catalog/namespace.c                       | 1 +
 src/backend/commands/async.c                          | 1 +
 src/backend/commands/vacuumparallel.c                 | 1 +
 src/backend/executor/execParallel.c                   | 1 +
 src/backend/executor/nodeAppend.c                     | 1 +
 src/backend/executor/nodeGather.c                     | 1 +
 src/backend/libpq/pqmq.c                              | 1 +
 src/backend/optimizer/plan/createplan.c               | 1 +
 src/backend/replication/logical/applyparallelworker.c | 2 ++
 src/backend/replication/logical/tablesync.c           | 1 +
 src/backend/replication/logical/worker.c              | 1 +
 src/backend/storage/ipc/procsignal.c                  | 1 +
 src/backend/storage/ipc/shm_mq.c                      | 1 +
 src/backend/utils/activity/backend_progress.c         | 1 +
 src/backend/utils/misc/guc_tables.c                   | 1 +
 src/include/access/parallel.h                         | 2 ++
 src/include/libpq/pqmq.h                              | 1 +
 src/include/storage/shm_mq.h                          | 4 +++-
 src/test/modules/test_shm_mq/setup.c                  | 1 +
 src/test/modules/test_shm_mq/test.c                   | 1 +
 src/test/modules/test_shm_mq/worker.c                 | 2 ++
 27 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 6887e421442..9cd563fd0c3 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -33,6 +33,7 @@
 #include "postmaster/autovacuum.h"
 #include "storage/bufmgr.h"
 #include "storage/freespace.h"
+#include "storage/proc.h"
 #include "tcop/tcopprot.h"
 #include "utils/acl.h"
 #include "utils/datum.h"
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index 0d63fb4ba27..ee9b6106922 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -27,6 +27,7 @@
 #include "nodes/execnodes.h"
 #include "pgstat.h"
 #include "storage/bufmgr.h"
+#include "storage/proc.h"
 #include "storage/predicate.h"
 #include "tcop/tcopprot.h"
 #include "utils/datum.h"
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 98d53caeea8..d534258e547 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -47,6 +47,7 @@
 #include "port/pg_bitutils.h"
 #include "storage/lmgr.h"
 #include "storage/predicate.h"
+#include "storage/proc.h"
 #include "storage/procarray.h"
 #include "utils/datum.h"
 #include "utils/injection_point.h"
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index 4be267ff657..1f11d8c1567 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -149,6 +149,7 @@
 #include "postmaster/autovacuum.h"
 #include "storage/bufmgr.h"
 #include "storage/freespace.h"
+#include "storage/latch.h"
 #include "storage/lmgr.h"
 #include "storage/read_stream.h"
 #include "utils/lsyscache.h"
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index 3a45508f62e..fd9d4087b5a 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -52,6 +52,7 @@
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "storage/bulk_write.h"
+#include "storage/proc.h"
 #include "tcop/tcopprot.h"
 #include "utils/rel.h"
 #include "utils/sortsupport.h"
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index 44786dc131f..e69c4b74248 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -36,6 +36,7 @@
 #include "pgstat.h"
 #include "storage/ipc.h"
 #include "storage/predicate.h"
+#include "storage/proc.h"
 #include "storage/spin.h"
 #include "tcop/tcopprot.h"
 #include "utils/combocid.h"
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c
index 4b0f4ba115d..56b87d878e8 100644
--- a/src/backend/catalog/namespace.c
+++ b/src/backend/catalog/namespace.c
@@ -48,6 +48,7 @@
 #include "nodes/makefuncs.h"
 #include "storage/ipc.h"
 #include "storage/lmgr.h"
+#include "storage/proc.h"
 #include "storage/procarray.h"
 #include "utils/acl.h"
 #include "utils/builtins.h"
diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c
index 657c591618d..0b6d119dad0 100644
--- a/src/backend/commands/async.c
+++ b/src/backend/commands/async.c
@@ -176,6 +176,7 @@
 #include "miscadmin.h"
 #include "storage/dsm_registry.h"
 #include "storage/ipc.h"
+#include "storage/latch.h"
 #include "storage/lmgr.h"
 #include "storage/procsignal.h"
 #include "tcop/tcopprot.h"
diff --git a/src/backend/commands/vacuumparallel.c b/src/backend/commands/vacuumparallel.c
index c3b3c9ea21a..279108ca89f 100644
--- a/src/backend/commands/vacuumparallel.c
+++ b/src/backend/commands/vacuumparallel.c
@@ -35,6 +35,7 @@
 #include "optimizer/paths.h"
 #include "pgstat.h"
 #include "storage/bufmgr.h"
+#include "storage/proc.h"
 #include "tcop/tcopprot.h"
 #include "utils/lsyscache.h"
 #include "utils/rel.h"
diff --git a/src/backend/executor/execParallel.c b/src/backend/executor/execParallel.c
index f87978c137e..ac84af294c9 100644
--- a/src/backend/executor/execParallel.c
+++ b/src/backend/executor/execParallel.c
@@ -45,6 +45,7 @@
 #include "jit/jit.h"
 #include "nodes/nodeFuncs.h"
 #include "pgstat.h"
+#include "storage/proc.h"
 #include "tcop/tcopprot.h"
 #include "utils/datum.h"
 #include "utils/dsa.h"
diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c
index 7138dc692c6..39d9442c121 100644
--- a/src/backend/executor/nodeAppend.c
+++ b/src/backend/executor/nodeAppend.c
@@ -64,6 +64,7 @@
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "storage/latch.h"
+#include "storage/lwlock.h"
 
 /* Shared state for parallel-aware Append. */
 struct ParallelAppendState
diff --git a/src/backend/executor/nodeGather.c b/src/backend/executor/nodeGather.c
index 4105f1d1968..114693abb32 100644
--- a/src/backend/executor/nodeGather.c
+++ b/src/backend/executor/nodeGather.c
@@ -36,6 +36,7 @@
 #include "executor/tqueue.h"
 #include "miscadmin.h"
 #include "optimizer/optimizer.h"
+#include "storage/latch.h"
 #include "utils/wait_event.h"
 
 
diff --git a/src/backend/libpq/pqmq.c b/src/backend/libpq/pqmq.c
index 6e4bbfb5aa1..7e4a725b796 100644
--- a/src/backend/libpq/pqmq.c
+++ b/src/backend/libpq/pqmq.c
@@ -20,6 +20,7 @@
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "replication/logicalworker.h"
+#include "storage/latch.h"
 #include "tcop/tcopprot.h"
 #include "utils/builtins.h"
 
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 21f1988cf22..50b0e10308b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -17,6 +17,7 @@
 #include "postgres.h"
 
 #include "access/sysattr.h"
+#include "access/transam.h"
 #include "catalog/pg_class.h"
 #include "foreign/fdwapi.h"
 #include "miscadmin.h"
diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c
index 1730ace5490..7cd6e912a9c 100644
--- a/src/backend/replication/logical/applyparallelworker.c
+++ b/src/backend/replication/logical/applyparallelworker.c
@@ -166,7 +166,9 @@
 #include "replication/origin.h"
 #include "replication/worker_internal.h"
 #include "storage/ipc.h"
+#include "storage/latch.h"
 #include "storage/lmgr.h"
+#include "storage/proc.h"
 #include "tcop/tcopprot.h"
 #include "utils/inval.h"
 #include "utils/memutils.h"
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index 2f2f0121ecf..bccbf61bf39 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -112,6 +112,7 @@
 #include "replication/walreceiver.h"
 #include "replication/worker_internal.h"
 #include "storage/ipc.h"
+#include "storage/latch.h"
 #include "storage/lmgr.h"
 #include "utils/acl.h"
 #include "utils/array.h"
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index bae8c011390..f9c4b484754 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -281,6 +281,7 @@
 #include "rewrite/rewriteHandler.h"
 #include "storage/buffile.h"
 #include "storage/ipc.h"
+#include "storage/latch.h"
 #include "storage/lmgr.h"
 #include "storage/procarray.h"
 #include "tcop/tcopprot.h"
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index 7505c9d3a37..d47d180a32f 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -28,6 +28,7 @@
 #include "storage/condition_variable.h"
 #include "storage/ipc.h"
 #include "storage/latch.h"
+#include "storage/proc.h"
 #include "storage/shmem.h"
 #include "storage/sinval.h"
 #include "storage/smgr.h"
diff --git a/src/backend/storage/ipc/shm_mq.c b/src/backend/storage/ipc/shm_mq.c
index 3ce6068ac54..7e9fbc00705 100644
--- a/src/backend/storage/ipc/shm_mq.c
+++ b/src/backend/storage/ipc/shm_mq.c
@@ -22,6 +22,7 @@
 #include "pgstat.h"
 #include "port/pg_bitutils.h"
 #include "postmaster/bgworker.h"
+#include "storage/proc.h"
 #include "storage/shm_mq.h"
 #include "storage/spin.h"
 #include "utils/memutils.h"
diff --git a/src/backend/utils/activity/backend_progress.c b/src/backend/utils/activity/backend_progress.c
index 5addb2d004f..b0359771de5 100644
--- a/src/backend/utils/activity/backend_progress.c
+++ b/src/backend/utils/activity/backend_progress.c
@@ -12,6 +12,7 @@
 
 #include "access/parallel.h"
 #include "libpq/pqformat.h"
+#include "storage/proc.h"
 #include "utils/backend_progress.h"
 #include "utils/backend_status.h"
 
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 741fce8dede..38aaf82f120 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -85,6 +85,7 @@
 #include "storage/large_object.h"
 #include "storage/pg_shmem.h"
 #include "storage/predicate.h"
+#include "storage/proc.h"
 #include "storage/procnumber.h"
 #include "storage/standby.h"
 #include "tcop/backend_startup.h"
diff --git a/src/include/access/parallel.h b/src/include/access/parallel.h
index 01bdf2bec1f..60f857675e0 100644
--- a/src/include/access/parallel.h
+++ b/src/include/access/parallel.h
@@ -14,6 +14,8 @@
 #ifndef PARALLEL_H
 #define PARALLEL_H
 
+#include <signal.h>
+
 #include "access/xlogdefs.h"
 #include "lib/ilist.h"
 #include "postmaster/bgworker.h"
diff --git a/src/include/libpq/pqmq.h b/src/include/libpq/pqmq.h
index c62fffb5998..36780c0816e 100644
--- a/src/include/libpq/pqmq.h
+++ b/src/include/libpq/pqmq.h
@@ -14,6 +14,7 @@
 #define PQMQ_H
 
 #include "lib/stringinfo.h"
+#include "storage/procnumber.h"
 #include "storage/shm_mq.h"
 
 extern void pq_redirect_to_shm_mq(dsm_segment *seg, shm_mq_handle *mqh);
diff --git a/src/include/storage/shm_mq.h b/src/include/storage/shm_mq.h
index aa5676f6a12..6f78f4a3acb 100644
--- a/src/include/storage/shm_mq.h
+++ b/src/include/storage/shm_mq.h
@@ -15,7 +15,9 @@
 
 #include "postmaster/bgworker.h"
 #include "storage/dsm.h"
-#include "storage/proc.h"
+
+/* avoid including storage/proc.h */
+typedef struct PGPROC PGPROC;
 
 /* The queue itself, in shared memory. */
 struct shm_mq;
diff --git a/src/test/modules/test_shm_mq/setup.c b/src/test/modules/test_shm_mq/setup.c
index 579e5933d28..36bb255922c 100644
--- a/src/test/modules/test_shm_mq/setup.c
+++ b/src/test/modules/test_shm_mq/setup.c
@@ -18,6 +18,7 @@
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "postmaster/bgworker.h"
+#include "storage/proc.h"
 #include "storage/shm_toc.h"
 #include "test_shm_mq.h"
 #include "utils/memutils.h"
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index fe1794c6077..ce97e6e1aa4 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -16,6 +16,7 @@
 #include "fmgr.h"
 #include "miscadmin.h"
 #include "pgstat.h"
+#include "storage/proc.h"
 #include "varatt.h"
 
 #include "test_shm_mq.h"
diff --git a/src/test/modules/test_shm_mq/worker.c b/src/test/modules/test_shm_mq/worker.c
index 6a4147554bb..e13c05ae5c7 100644
--- a/src/test/modules/test_shm_mq/worker.c
+++ b/src/test/modules/test_shm_mq/worker.c
@@ -21,6 +21,8 @@
 
 #include "miscadmin.h"
 #include "storage/ipc.h"
+#include "storage/latch.h"
+#include "storage/proc.h"
 #include "storage/procarray.h"
 #include "storage/shm_mq.h"
 #include "storage/shm_toc.h"
-- 
2.47.3

^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:41   ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 18:34     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-18 15:10       ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 13:52         ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 15:14           ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-26 15:59             ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 16:27               ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
@ 2026-02-27 10:37                 ` Alvaro Herrera <alvherre@kurilemu.de>
  2026-03-05 15:08                   ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2 siblings, 1 reply; 33+ messages in thread

From: Alvaro Herrera @ 2026-02-27 10:37 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: Heikki Linnakangas <hlinnaka@iki.fi>; pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

Hi,

On 2026-Feb-26, Andres Freund wrote:

> FWIW, regardless of what we choose here (i.e. whether and where to
> "unnecessarily" include wait_event.h), I'd be in favor of fixing all the
> fallout in our source tree, just for cleanliness' sake. It's also presumably
> the part of the patch that would be the most pain to keep updated.

Oh, that makes sense.

> I'm not sure that including in latch.h really would an improvement though -
> that's included in proc.h and libpq.h, which both are fairly widely included
> [1].

I have committed fixes for both of those, so that including an extra
file in latch.h is not as bad.

Here's one more patch.  I noticed that the call actually uses
PG_WAIT_EXTENSION, which is in storage/wait_classes.h.  Including that
seems a bit narrow-minded even if it's just for backwards compatibility,
so I decided to do wait_event_types.h instead.  This is still a bit
better than the whole wait_event.h IMO.  And also now it's IWYU: export
rather than IWYU: keep, which seems sensible.

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"El miedo atento y previsor es la madre de la seguridad" (E. Burke)

Attachments:

  [text/x-diff] 0001-Don-t-include-wait_event.h-in-pgstat.h.patch (37.1K, ../../202602271034.lgsu7hqnmc5p@alvherre.pgsql/2-0001-Don-t-include-wait_event.h-in-pgstat.h.patch)
  download | inline diff:
From b04c18d81f0c7da8606f4d6276694caf28056d35 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvherre@kurilemu.de>
Date: Thu, 26 Feb 2026 16:22:49 +0100
Subject: [PATCH] Don't include wait_event.h in pgstat.h

To avoid breaking too many third-party modules, we now #include
utils/wait_event_types.h in storage/latch.h.  Then, the very common case
of doing
	WaitLatch(..., PG_WAIT_EXTENSION)
continues to work by including just storage/latch.h.

(It would actually be sufficient to include storage/wait_classes.h, but
that seems rather unprincipled.)

Discussion: https://postgr.es/m/202602181214.gcmhx2vhlxzp@alvherre.pgsql
---
 contrib/pg_prewarm/autoprewarm.c                      | 1 +
 src/backend/access/brin/brin.c                        | 1 +
 src/backend/access/gin/gininsert.c                    | 1 +
 src/backend/access/heap/rewriteheap.c                 | 1 +
 src/backend/access/heap/vacuumlazy.c                  | 1 +
 src/backend/access/nbtree/nbtree.c                    | 1 +
 src/backend/access/nbtree/nbtsort.c                   | 1 +
 src/backend/access/transam/clog.c                     | 1 +
 src/backend/access/transam/parallel.c                 | 1 +
 src/backend/access/transam/slru.c                     | 1 +
 src/backend/access/transam/timeline.c                 | 1 +
 src/backend/access/transam/twophase.c                 | 1 +
 src/backend/access/transam/xact.c                     | 1 +
 src/backend/access/transam/xlog.c                     | 1 +
 src/backend/access/transam/xlogarchive.c              | 1 +
 src/backend/access/transam/xlogfuncs.c                | 1 +
 src/backend/access/transam/xlogreader.c               | 1 +
 src/backend/access/transam/xlogrecovery.c             | 1 +
 src/backend/access/transam/xlogwait.c                 | 1 +
 src/backend/archive/shell_archive.c                   | 1 +
 src/backend/backup/basebackup.c                       | 1 +
 src/backend/backup/basebackup_throttle.c              | 1 +
 src/backend/commands/copyfromparse.c                  | 1 +
 src/backend/commands/copyto.c                         | 1 +
 src/backend/commands/dbcommands.c                     | 1 +
 src/backend/commands/vacuum.c                         | 1 +
 src/backend/executor/nodeAppend.c                     | 1 +
 src/backend/executor/nodeBitmapHeapscan.c             | 1 +
 src/backend/libpq/be-secure-gssapi.c                  | 1 +
 src/backend/libpq/be-secure-openssl.c                 | 1 +
 src/backend/libpq/pqmq.c                              | 1 +
 src/backend/postmaster/autovacuum.c                   | 1 +
 src/backend/postmaster/auxprocess.c                   | 1 +
 src/backend/postmaster/bgworker.c                     | 1 +
 src/backend/postmaster/bgwriter.c                     | 1 +
 src/backend/postmaster/checkpointer.c                 | 1 +
 src/backend/postmaster/pgarch.c                       | 1 +
 src/backend/postmaster/syslogger.c                    | 1 +
 src/backend/postmaster/walwriter.c                    | 1 +
 src/backend/replication/logical/applyparallelworker.c | 1 +
 src/backend/replication/logical/launcher.c            | 1 +
 src/backend/replication/logical/origin.c              | 1 +
 src/backend/replication/logical/reorderbuffer.c       | 1 +
 src/backend/replication/logical/slotsync.c            | 1 +
 src/backend/replication/logical/snapbuild.c           | 3 +++
 src/backend/replication/logical/tablesync.c           | 1 +
 src/backend/replication/logical/worker.c              | 1 +
 src/backend/replication/slot.c                        | 1 +
 src/backend/replication/syncrep.c                     | 1 +
 src/backend/replication/walreceiver.c                 | 1 +
 src/backend/replication/walreceiverfuncs.c            | 1 +
 src/backend/replication/walsender.c                   | 1 +
 src/backend/storage/buffer/bufmgr.c                   | 1 +
 src/backend/storage/file/buffile.c                    | 1 +
 src/backend/storage/file/copydir.c                    | 1 +
 src/backend/storage/file/fd.c                         | 1 +
 src/backend/storage/ipc/dsm_impl.c                    | 1 +
 src/backend/storage/ipc/ipci.c                        | 1 +
 src/backend/storage/ipc/procarray.c                   | 1 +
 src/backend/storage/ipc/procsignal.c                  | 1 +
 src/backend/storage/ipc/shm_mq.c                      | 1 +
 src/backend/storage/ipc/signalfuncs.c                 | 1 +
 src/backend/storage/ipc/standby.c                     | 1 +
 src/backend/storage/ipc/waiteventset.c                | 1 +
 src/backend/storage/lmgr/lwlock.c                     | 1 +
 src/backend/storage/lmgr/predicate.c                  | 1 +
 src/backend/storage/lmgr/proc.c                       | 1 +
 src/backend/storage/smgr/md.c                         | 1 +
 src/backend/storage/sync/sync.c                       | 1 +
 src/backend/utils/adt/misc.c                          | 1 +
 src/backend/utils/adt/pgstatfuncs.c                   | 1 +
 src/backend/utils/cache/relmapper.c                   | 1 +
 src/backend/utils/init/miscinit.c                     | 1 +
 src/common/controldata_utils.c                        | 1 +
 src/include/pgstat.h                                  | 1 -
 src/include/storage/latch.h                           | 1 +
 src/test/modules/test_shm_mq/setup.c                  | 1 +
 src/test/modules/test_shm_mq/test.c                   | 1 +
 src/test/modules/worker_spi/worker_spi.c              | 1 +
 79 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
index 89e187425cc..ba0bc8e6d4a 100644
--- a/contrib/pg_prewarm/autoprewarm.c
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -48,6 +48,7 @@
 #include "utils/rel.h"
 #include "utils/relfilenumbermap.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 #define AUTOPREWARM_FILE "autoprewarm.blocks"
 
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 9cd563fd0c3..146ee97a47d 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -43,6 +43,7 @@
 #include "utils/memutils.h"
 #include "utils/rel.h"
 #include "utils/tuplesort.h"
+#include "utils/wait_event.h"
 
 /* Magic numbers for parallel state sharing */
 #define PARALLEL_KEY_BRIN_SHARED		UINT64CONST(0xB000000000000001)
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index ee9b6106922..c7e38dbe193 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -35,6 +35,7 @@
 #include "utils/builtins.h"
 #include "utils/rel.h"
 #include "utils/typcache.h"
+#include "utils/wait_event.h"
 
 
 /* Magic numbers for parallel state sharing */
diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c
index 77fd48eb59e..6b19ac3030d 100644
--- a/src/backend/access/heap/rewriteheap.c
+++ b/src/backend/access/heap/rewriteheap.c
@@ -122,6 +122,7 @@
 #include "storage/procarray.h"
 #include "utils/memutils.h"
 #include "utils/rel.h"
+#include "utils/wait_event.h"
 
 /*
  * State associated with a rewrite operation. This is opaque to the user
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index 5d271d80967..429d16059f0 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -155,6 +155,7 @@
 #include "utils/lsyscache.h"
 #include "utils/pg_rusage.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 3dec1ee657d..6d0a6f27f3f 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -35,6 +35,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/index_selfuncs.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index fd9d4087b5a..69ef1527e06 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -57,6 +57,7 @@
 #include "utils/rel.h"
 #include "utils/sortsupport.h"
 #include "utils/tuplesort.h"
+#include "utils/wait_event.h"
 
 
 /* Magic numbers for parallel state sharing */
diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c
index b5c38bbb162..3ee1cfdbc24 100644
--- a/src/backend/access/transam/clog.c
+++ b/src/backend/access/transam/clog.c
@@ -45,6 +45,7 @@
 #include "storage/proc.h"
 #include "storage/sync.h"
 #include "utils/guc_hooks.h"
+#include "utils/wait_event.h"
 
 /*
  * Defines for CLOG page sizes.  A page is the same BLCKSZ as is used
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index e69c4b74248..ab1dfb30e73 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -45,6 +45,7 @@
 #include "utils/memutils.h"
 #include "utils/relmapper.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 /*
  * We don't want to waste a lot of memory on an error queue which, most of
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c
index 549c7e3e64b..556edcbf7cb 100644
--- a/src/backend/access/transam/slru.c
+++ b/src/backend/access/transam/slru.c
@@ -71,6 +71,7 @@
 #include "storage/fd.h"
 #include "storage/shmem.h"
 #include "utils/guc.h"
+#include "utils/wait_event.h"
 
 /*
  * Converts segment number to the filename of the segment.
diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/transam/timeline.c
index 60ee28665b1..68e5f692d26 100644
--- a/src/backend/access/transam/timeline.c
+++ b/src/backend/access/transam/timeline.c
@@ -41,6 +41,7 @@
 #include "access/xlogdefs.h"
 #include "pgstat.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 
 /*
  * Copies all timeline history files with id's between 'begin' and 'end'
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index e4340b59640..5cce76752a2 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -106,6 +106,7 @@
 #include "utils/injection_point.h"
 #include "utils/memutils.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /*
  * Directory where Two-phase commit files reside within PGDATA
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index eba4f063168..aafc53e0164 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -72,6 +72,7 @@
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
 #include "utils/typcache.h"
+#include "utils/wait_event.h"
 
 /*
  *	User-tweakable parameters
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 13cce9b49f1..fb5085e4b38 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -105,6 +105,7 @@
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 #ifdef WAL_DEBUG
 #include "utils/memutils.h"
diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c
index aa0c2fe3afd..9a0c8097cb1 100644
--- a/src/backend/access/transam/xlogarchive.c
+++ b/src/backend/access/transam/xlogarchive.c
@@ -31,6 +31,7 @@
 #include "replication/walsender.h"
 #include "storage/fd.h"
 #include "storage/ipc.h"
+#include "utils/wait_event.h"
 
 /*
  * Attempt to retrieve the specified file from off-line archival storage.
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c
index 2efe4105efb..8965be29703 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -34,6 +34,7 @@
 #include "utils/memutils.h"
 #include "utils/pg_lsn.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /*
  * Backup-related variables.
diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index 03ada8aa0c5..8cb2110cb99 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -36,6 +36,7 @@
 #ifndef FRONTEND
 #include "pgstat.h"
 #include "storage/bufmgr.h"
+#include "utils/wait_event.h"
 #else
 #include "common/logging.h"
 #endif
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index ecd66fd86a4..1e3e11be0ae 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -65,6 +65,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/ps_status.h"
 #include "utils/pg_rusage.h"
+#include "utils/wait_event.h"
 
 /* Unsupported old recovery command file names (relative to $PGDATA) */
 #define RECOVERY_COMMAND_FILE	"recovery.conf"
diff --git a/src/backend/access/transam/xlogwait.c b/src/backend/access/transam/xlogwait.c
index d286ff63123..bf4630677b4 100644
--- a/src/backend/access/transam/xlogwait.c
+++ b/src/backend/access/transam/xlogwait.c
@@ -60,6 +60,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/pg_lsn.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 
 static int	waitlsn_cmp(const pairingheap_node *a, const pairingheap_node *b,
diff --git a/src/backend/archive/shell_archive.c b/src/backend/archive/shell_archive.c
index 5b565968818..0b427a68809 100644
--- a/src/backend/archive/shell_archive.c
+++ b/src/backend/archive/shell_archive.c
@@ -22,6 +22,7 @@
 #include "archive/shell_archive.h"
 #include "common/percentrepl.h"
 #include "pgstat.h"
+#include "utils/wait_event.h"
 
 static bool shell_archive_configured(ArchiveModuleState *state);
 static bool shell_archive_file(ArchiveModuleState *state,
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 2d74c648335..ab1fbae8001 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -48,6 +48,7 @@
 #include "utils/ps_status.h"
 #include "utils/relcache.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 /*
  * How much data do we want to send in one CopyData message? Note that
diff --git a/src/backend/backup/basebackup_throttle.c b/src/backend/backup/basebackup_throttle.c
index e112eed7485..4d8d90f356b 100644
--- a/src/backend/backup/basebackup_throttle.c
+++ b/src/backend/backup/basebackup_throttle.c
@@ -19,6 +19,7 @@
 #include "pgstat.h"
 #include "storage/latch.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 typedef struct bbsink_throttle
 {
diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index 6b00d49c50f..8a93a892ba0 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -74,6 +74,7 @@
 #include "port/pg_bswap.h"
 #include "utils/builtins.h"
 #include "utils/rel.h"
+#include "utils/wait_event.h"
 
 #define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
 #define OCTVALUE(c) ((c) - '0')
diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c
index 9ceeff6d99e..d6ef7275a64 100644
--- a/src/backend/commands/copyto.c
+++ b/src/backend/commands/copyto.c
@@ -37,6 +37,7 @@
 #include "utils/memutils.h"
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 /*
  * Represents the different dest cases we need to worry about at
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 740c526e92d..9b18bb4a17e 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -70,6 +70,7 @@
 #include "utils/relmapper.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /*
  * Create database strategy.
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 03932f45c8a..c61c9eb0a01 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -61,6 +61,7 @@
 #include "utils/memutils.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /*
  * Minimum interval for cost-based vacuum delay reports from a parallel worker.
diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c
index 39d9442c121..85c85569b5e 100644
--- a/src/backend/executor/nodeAppend.c
+++ b/src/backend/executor/nodeAppend.c
@@ -65,6 +65,7 @@
 #include "pgstat.h"
 #include "storage/latch.h"
 #include "storage/lwlock.h"
+#include "utils/wait_event.h"
 
 /* Shared state for parallel-aware Append. */
 struct ParallelAppendState
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index c68c26cbf38..e0b6df64767 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -45,6 +45,7 @@
 #include "storage/bufmgr.h"
 #include "utils/rel.h"
 #include "utils/spccache.h"
+#include "utils/wait_event.h"
 
 static void BitmapTableScanSetup(BitmapHeapScanState *node);
 static TupleTableSlot *BitmapHeapNext(BitmapHeapScanState *node);
diff --git a/src/backend/libpq/be-secure-gssapi.c b/src/backend/libpq/be-secure-gssapi.c
index 5fb043b8608..540ed62a5cc 100644
--- a/src/backend/libpq/be-secure-gssapi.c
+++ b/src/backend/libpq/be-secure-gssapi.c
@@ -24,6 +24,7 @@
 #include "storage/latch.h"
 #include "utils/injection_point.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.c
index 4da6ac22ff9..14c6532bb16 100644
--- a/src/backend/libpq/be-secure-openssl.c
+++ b/src/backend/libpq/be-secure-openssl.c
@@ -35,6 +35,7 @@
 #include "storage/latch.h"
 #include "utils/guc.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * These SSL-related #includes must come after all system-provided headers.
diff --git a/src/backend/libpq/pqmq.c b/src/backend/libpq/pqmq.c
index 7e4a725b796..22e5164adbf 100644
--- a/src/backend/libpq/pqmq.c
+++ b/src/backend/libpq/pqmq.c
@@ -23,6 +23,7 @@
 #include "storage/latch.h"
 #include "tcop/tcopprot.h"
 #include "utils/builtins.h"
+#include "utils/wait_event.h"
 
 static shm_mq_handle *pq_mq_handle = NULL;
 static bool pq_mq_busy = false;
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 6fde740465f..695e187ba11 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -109,6 +109,7 @@
 #include "utils/syscache.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/postmaster/auxprocess.c b/src/backend/postmaster/auxprocess.c
index 8ea800c0bbd..cf24f662d27 100644
--- a/src/backend/postmaster/auxprocess.c
+++ b/src/backend/postmaster/auxprocess.c
@@ -24,6 +24,7 @@
 #include "storage/procsignal.h"
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
+#include "utils/wait_event.h"
 
 
 static void ShutdownAuxiliaryProcess(int code, Datum arg);
diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c
index 8678ea4e139..0104a86b9ec 100644
--- a/src/backend/postmaster/bgworker.c
+++ b/src/backend/postmaster/bgworker.c
@@ -34,6 +34,7 @@
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
+#include "utils/wait_event.h"
 
 /*
  * The postmaster's list of registered background workers, in private memory.
diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c
index 0956bd39a85..1d8947774a9 100644
--- a/src/backend/postmaster/bgwriter.c
+++ b/src/backend/postmaster/bgwriter.c
@@ -51,6 +51,7 @@
 #include "utils/memutils.h"
 #include "utils/resowner.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /*
  * GUC parameters
diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c
index e03c19123bc..3c982c6ffac 100644
--- a/src/backend/postmaster/checkpointer.c
+++ b/src/backend/postmaster/checkpointer.c
@@ -67,6 +67,7 @@
 #include "utils/guc.h"
 #include "utils/memutils.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 
 /*----------
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 82731e452fc..fa4bdfe9ab9 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -53,6 +53,7 @@
 #include "utils/ps_status.h"
 #include "utils/resowner.h"
 #include "utils/timeout.h"
+#include "utils/wait_event.h"
 
 
 /* ----------
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index 86c5e376b40..9792f638718 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -51,6 +51,7 @@
 #include "utils/guc.h"
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
+#include "utils/wait_event.h"
 
 /*
  * We read() into a temp buffer twice as big as a chunk, so that any fragment
diff --git a/src/backend/postmaster/walwriter.c b/src/backend/postmaster/walwriter.c
index 7c0e2809c17..9cd86ad7022 100644
--- a/src/backend/postmaster/walwriter.c
+++ b/src/backend/postmaster/walwriter.c
@@ -62,6 +62,7 @@
 #include "utils/hsearch.h"
 #include "utils/memutils.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c
index 7cd6e912a9c..d78693ffa8e 100644
--- a/src/backend/replication/logical/applyparallelworker.c
+++ b/src/backend/replication/logical/applyparallelworker.c
@@ -173,6 +173,7 @@
 #include "utils/inval.h"
 #include "utils/memutils.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 #define PG_LOGICAL_APPLY_SHM_MAGIC 0x787ca067
 
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index e6112e11ec2..09964198550 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -44,6 +44,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /* max sleep time between cycles (3min) */
 #define DEFAULT_NAPTIME_PER_CYCLE 180000L
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index c3271a6fd0e..26afd8f0af9 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -95,6 +95,7 @@
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /* paths for replication origin checkpoint files */
 #define PG_REPLORIGIN_CHECKPOINT_FILENAME PG_LOGICAL_DIR "/replorigin_checkpoint"
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index e832fa0d8ea..b7664b90006 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -113,6 +113,7 @@
 #include "utils/memutils.h"
 #include "utils/rel.h"
 #include "utils/relfilenumbermap.h"
+#include "utils/wait_event.h"
 
 /*
  * Each transaction has an 8MB limit for invalidation messages distributed from
diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c
index 062a08ccb88..19976efe4f2 100644
--- a/src/backend/replication/logical/slotsync.c
+++ b/src/backend/replication/logical/slotsync.c
@@ -75,6 +75,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
+#include "utils/wait_event.h"
 
 /*
  * Struct for sharing information to control slot synchronization.
diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c
index 7f79621b57e..eddb3d9105c 100644
--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -144,6 +144,9 @@
 #include "utils/memutils.h"
 #include "utils/snapmgr.h"
 #include "utils/snapshot.h"
+#include "utils/wait_event.h"
+
+
 /*
  * Starting a transaction -- which we need to do while exporting a snapshot --
  * removes knowledge about the previously used resowner, so we save it here.
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index bccbf61bf39..a0de2efded8 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -122,6 +122,7 @@
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
 #include "utils/usercontext.h"
+#include "utils/wait_event.h"
 
 List	   *table_states_not_ready = NIL;
 
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index f9c4b484754..274dc71c6a1 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -296,6 +296,7 @@
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
 #include "utils/usercontext.h"
+#include "utils/wait_event.h"
 
 #define NAPTIME_PER_CYCLE 1000	/* max sleep time between cycles (1s) */
 
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index 28c7019402b..a9092fc2382 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -59,6 +59,7 @@
 #include "utils/guc_hooks.h"
 #include "utils/injection_point.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 /*
  * Replication slot on-disk data structure.
diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c
index d1582a5d711..9cecc83ed68 100644
--- a/src/backend/replication/syncrep.c
+++ b/src/backend/replication/syncrep.c
@@ -85,6 +85,7 @@
 #include "tcop/tcopprot.h"
 #include "utils/guc_hooks.h"
 #include "utils/ps_status.h"
+#include "utils/wait_event.h"
 
 /* User-settable parameters for sync rep */
 char	   *SyncRepStandbyNames;
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index 7c1b8757d7d..fabe3c73034 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -79,6 +79,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/ps_status.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c
index e62e8a20420..45b9d4f09f2 100644
--- a/src/backend/replication/walreceiverfuncs.c
+++ b/src/backend/replication/walreceiverfuncs.c
@@ -30,6 +30,7 @@
 #include "storage/proc.h"
 #include "storage/shmem.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 WalRcvData *WalRcv = NULL;
 
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 2cde8ebc729..829ec538ea5 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -98,6 +98,7 @@
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /* Minimum interval used by walsender for stats flushes, in ms */
 #define WALSENDER_STATS_FLUSH_INTERVAL         1000
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index d1babaff023..5f3d083e938 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -68,6 +68,7 @@
 #include "utils/rel.h"
 #include "utils/resowner.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /* Note: these two macros only work on shared buffers, not local ones! */
diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c
index ddf3a410d6f..c4afe4d368a 100644
--- a/src/backend/storage/file/buffile.c
+++ b/src/backend/storage/file/buffile.c
@@ -53,6 +53,7 @@
 #include "storage/bufmgr.h"
 #include "storage/fd.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 /*
  * We break BufFiles into gigabyte-sized segments, regardless of RELSEG_SIZE.
diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c
index 596d9070fd8..5ee141f13a5 100644
--- a/src/backend/storage/file/copydir.c
+++ b/src/backend/storage/file/copydir.c
@@ -29,6 +29,7 @@
 #include "pgstat.h"
 #include "storage/copydir.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 
 /* GUCs */
 int			file_copy_method = FILE_COPY_METHOD_COPY;
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 5d07b64a1ef..01f1bd6e687 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -101,6 +101,7 @@
 #include "utils/guc_hooks.h"
 #include "utils/resowner.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 /* Define PG_FLUSH_DATA_WORKS if we have an implementation for pg_flush_data */
 #if defined(HAVE_SYNC_FILE_RANGE)
diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c
index e208457df27..e8c07805f59 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -68,6 +68,7 @@
 #include "storage/fd.h"
 #include "utils/guc.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 #ifdef USE_DSM_POSIX
 static bool dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c
index 1f7e933d500..a4785daf1e5 100644
--- a/src/backend/storage/ipc/ipci.c
+++ b/src/backend/storage/ipc/ipci.c
@@ -52,6 +52,7 @@
 #include "storage/sinvaladt.h"
 #include "utils/guc.h"
 #include "utils/injection_point.h"
+#include "utils/wait_event.h"
 
 /* GUCs */
 int			shared_memory_type = DEFAULT_SHARED_MEMORY_TYPE;
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index 40312df2cac..406b8253f8b 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -67,6 +67,7 @@
 #include "utils/lsyscache.h"
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 #define UINT32_ACCESS_ONCE(var)		 ((uint32)(*((volatile uint32 *)&(var))))
 
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index d47d180a32f..7e017c8d53b 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -34,6 +34,7 @@
 #include "storage/smgr.h"
 #include "tcop/tcopprot.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * The SIGUSR1 signal is multiplexed to support signaling multiple event
diff --git a/src/backend/storage/ipc/shm_mq.c b/src/backend/storage/ipc/shm_mq.c
index 7e9fbc00705..26b24158ed9 100644
--- a/src/backend/storage/ipc/shm_mq.c
+++ b/src/backend/storage/ipc/shm_mq.c
@@ -26,6 +26,7 @@
 #include "storage/shm_mq.h"
 #include "storage/spin.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * This structure represents the actual queue, stored in shared memory.
diff --git a/src/backend/storage/ipc/signalfuncs.c b/src/backend/storage/ipc/signalfuncs.c
index d48b4fe3799..800b699de21 100644
--- a/src/backend/storage/ipc/signalfuncs.c
+++ b/src/backend/storage/ipc/signalfuncs.c
@@ -25,6 +25,7 @@
 #include "storage/procarray.h"
 #include "utils/acl.h"
 #include "utils/fmgrprotos.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c
index d83afbfb9d6..f3ad90c7c7a 100644
--- a/src/backend/storage/ipc/standby.c
+++ b/src/backend/storage/ipc/standby.c
@@ -35,6 +35,7 @@
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /* User-settable GUC parameters */
 int			max_standby_archive_delay = 30 * 1000;
diff --git a/src/backend/storage/ipc/waiteventset.c b/src/backend/storage/ipc/waiteventset.c
index 772e350a0c0..0f228e1e7b8 100644
--- a/src/backend/storage/ipc/waiteventset.c
+++ b/src/backend/storage/ipc/waiteventset.c
@@ -77,6 +77,7 @@
 #include "storage/waiteventset.h"
 #include "utils/memutils.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 /*
  * Select the fd readiness primitive to use. Normally the "most modern"
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 517c55375b4..49382de88fc 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -85,6 +85,7 @@
 #include "storage/procnumber.h"
 #include "storage/spin.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 #ifdef LWLOCK_STATS
 #include "utils/hsearch.h"
diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c
index fe75ead3501..548b4f66470 100644
--- a/src/backend/storage/lmgr/predicate.c
+++ b/src/backend/storage/lmgr/predicate.c
@@ -214,6 +214,7 @@
 #include "utils/guc_hooks.h"
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 /* Uncomment the next line to test the graceful degradation code. */
 /* #define TEST_SUMMARIZE_SERIAL */
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index 771b006b522..0568f3cf9b1 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -53,6 +53,7 @@
 #include "storage/standby.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /* GUC variables */
 int			DeadlockTimeout = 1000;
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 443434e4ea8..dee29037b16 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -40,6 +40,7 @@
 #include "storage/smgr.h"
 #include "storage/sync.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * The magnetic disk storage manager keeps track of open file
diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c
index b1accc68b95..2c964b6f3d9 100644
--- a/src/backend/storage/sync/sync.c
+++ b/src/backend/storage/sync/sync.c
@@ -31,6 +31,7 @@
 #include "storage/md.h"
 #include "utils/hsearch.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * In some contexts (currently, standalone backends and the checkpointer)
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index 32a787d7df7..864032c32bf 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -46,6 +46,7 @@
 #include "utils/ruleutils.h"
 #include "utils/syscache.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index b1df96e7b0b..50ea9e8fb83 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -31,6 +31,7 @@
 #include "utils/acl.h"
 #include "utils/builtins.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 #define UINT32_ACCESS_ONCE(var)		 ((uint32)(*((volatile uint32 *)&(var))))
 
diff --git a/src/backend/utils/cache/relmapper.c b/src/backend/utils/cache/relmapper.c
index 778b14a2318..3aaf466868d 100644
--- a/src/backend/utils/cache/relmapper.c
+++ b/src/backend/utils/cache/relmapper.c
@@ -54,6 +54,7 @@
 #include "storage/lwlock.h"
 #include "utils/inval.h"
 #include "utils/relmapper.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index 03f6c8479f2..ba191977697 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -55,6 +55,7 @@
 #include "utils/pidfile.h"
 #include "utils/syscache.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 
 #define DIRECTORY_LOCK_FILE		"postmaster.pid"
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 14530c6489a..4ab116afcde 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -37,6 +37,7 @@
 #ifndef FRONTEND
 #include "pgstat.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 #endif
 
 /*
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 0e9d2b4c623..216b93492ba 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -18,7 +18,6 @@
 #include "utils/backend_progress.h" /* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/backend_status.h"	/* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/pgstat_kind.h"
-#include "utils/wait_event.h"	/* for backward compatibility */	/* IWYU pragma: export */
 
 
 /* avoid including access/transam.h */
diff --git a/src/include/storage/latch.h b/src/include/storage/latch.h
index fbdadc86959..8fba94a471b 100644
--- a/src/include/storage/latch.h
+++ b/src/include/storage/latch.h
@@ -104,6 +104,7 @@
 #include <signal.h>
 
 #include "storage/waiteventset.h"	/* for WL_* arguments to WaitLatch */
+#include "utils/wait_event_types.h"		/* IWYU: export */
 
 /*
  * Latch structure should be treated as opaque and only accessed through
diff --git a/src/test/modules/test_shm_mq/setup.c b/src/test/modules/test_shm_mq/setup.c
index 36bb255922c..4f40a61e3d9 100644
--- a/src/test/modules/test_shm_mq/setup.c
+++ b/src/test/modules/test_shm_mq/setup.c
@@ -22,6 +22,7 @@
 #include "storage/shm_toc.h"
 #include "test_shm_mq.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 typedef struct
 {
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index ce97e6e1aa4..ccf5485cc55 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -18,6 +18,7 @@
 #include "pgstat.h"
 #include "storage/proc.h"
 #include "varatt.h"
+#include "utils/wait_event.h"
 
 #include "test_shm_mq.h"
 
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index d1e4a2bd952..b89954279c0 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -39,6 +39,7 @@
 #include "utils/acl.h"
 #include "utils/builtins.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 PG_MODULE_MAGIC;
 
-- 
2.47.3

^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 16:18 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-16 17:41   ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-16 18:34     ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-18 15:10       ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 13:52         ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 15:14           ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-26 15:59             ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
  2026-02-26 16:27               ` Re: pgstat include expansion Andres Freund <andres@anarazel.de>
  2026-02-27 10:37                 ` Re: pgstat include expansion Alvaro Herrera <alvherre@kurilemu.de>
@ 2026-03-05 15:08                   ` Alvaro Herrera <alvherre@kurilemu.de>
  0 siblings, 0 replies; 33+ messages in thread

From: Alvaro Herrera @ 2026-03-05 15:08 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: Heikki Linnakangas <hlinnaka@iki.fi>; pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

On 2026-Feb-27, Alvaro Herrera wrote:

> Here's one more patch.  I noticed that the call actually uses
> PG_WAIT_EXTENSION, which is in storage/wait_classes.h.  Including that
> seems a bit narrow-minded even if it's just for backwards compatibility,
> so I decided to do wait_event_types.h instead.  This is still a bit
> better than the whole wait_event.h IMO.  And also now it's IWYU: export
> rather than IWYU: keep, which seems sensible.

Actually, I think this is not a great idea, because if we do that, then
wait_event_types.h (the generated header) is, overall, included in more
files than before, so it'd be a net loss.  But if we include
wait_classes.h in latch.h instead, then that aspect is definitely much
better, and I can't find anything that gets worse.  (Any code that wants
to use other wait events can include wait_event_types.h or wait_event.h
themselves).  So I propose to close this with the attached patch.

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
"The important things in the world are problems with society that we don't
understand at all. The machines will become more complicated but they won't
be more complicated than the societies that run them."    (Freeman Dyson)

Attachments:

  [text/x-diff] v2-0001-Don-t-include-wait_event.h-in-pgstat.h.patch (37.0K, ../../202602280858.ypc5z67ajlf4@alvherre.pgsql/2-v2-0001-Don-t-include-wait_event.h-in-pgstat.h.patch)
  download | inline diff:
From b3c6f60b429192d186d062982c0deb81afd25c9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvherre@kurilemu.de>
Date: Thu, 26 Feb 2026 16:22:49 +0100
Subject: [PATCH v2] Don't include wait_event.h in pgstat.h

To avoid breaking too many third-party modules, we now #include
utils/wait_classes.h in storage/latch.h.  Then, the very common case
of doing
	WaitLatch(..., PG_WAIT_EXTENSION)
continues to work by including just storage/latch.h.

Discussion: https://postgr.es/m/202602181214.gcmhx2vhlxzp@alvherre.pgsql
---
 contrib/pg_prewarm/autoprewarm.c                      | 1 +
 src/backend/access/brin/brin.c                        | 1 +
 src/backend/access/gin/gininsert.c                    | 1 +
 src/backend/access/heap/rewriteheap.c                 | 1 +
 src/backend/access/heap/vacuumlazy.c                  | 1 +
 src/backend/access/nbtree/nbtree.c                    | 1 +
 src/backend/access/nbtree/nbtsort.c                   | 1 +
 src/backend/access/transam/clog.c                     | 1 +
 src/backend/access/transam/parallel.c                 | 1 +
 src/backend/access/transam/slru.c                     | 1 +
 src/backend/access/transam/timeline.c                 | 1 +
 src/backend/access/transam/twophase.c                 | 1 +
 src/backend/access/transam/xact.c                     | 1 +
 src/backend/access/transam/xlog.c                     | 1 +
 src/backend/access/transam/xlogarchive.c              | 1 +
 src/backend/access/transam/xlogfuncs.c                | 1 +
 src/backend/access/transam/xlogreader.c               | 1 +
 src/backend/access/transam/xlogrecovery.c             | 1 +
 src/backend/access/transam/xlogwait.c                 | 1 +
 src/backend/archive/shell_archive.c                   | 1 +
 src/backend/backup/basebackup.c                       | 1 +
 src/backend/backup/basebackup_throttle.c              | 1 +
 src/backend/commands/copyfromparse.c                  | 1 +
 src/backend/commands/copyto.c                         | 1 +
 src/backend/commands/dbcommands.c                     | 1 +
 src/backend/commands/vacuum.c                         | 1 +
 src/backend/executor/nodeAppend.c                     | 1 +
 src/backend/executor/nodeBitmapHeapscan.c             | 1 +
 src/backend/libpq/be-secure-gssapi.c                  | 1 +
 src/backend/libpq/be-secure-openssl.c                 | 1 +
 src/backend/libpq/pqmq.c                              | 1 +
 src/backend/postmaster/autovacuum.c                   | 1 +
 src/backend/postmaster/auxprocess.c                   | 1 +
 src/backend/postmaster/bgworker.c                     | 1 +
 src/backend/postmaster/bgwriter.c                     | 1 +
 src/backend/postmaster/checkpointer.c                 | 1 +
 src/backend/postmaster/pgarch.c                       | 1 +
 src/backend/postmaster/syslogger.c                    | 1 +
 src/backend/postmaster/walwriter.c                    | 1 +
 src/backend/replication/logical/applyparallelworker.c | 1 +
 src/backend/replication/logical/launcher.c            | 1 +
 src/backend/replication/logical/origin.c              | 1 +
 src/backend/replication/logical/reorderbuffer.c       | 1 +
 src/backend/replication/logical/slotsync.c            | 1 +
 src/backend/replication/logical/snapbuild.c           | 3 +++
 src/backend/replication/logical/tablesync.c           | 1 +
 src/backend/replication/logical/worker.c              | 1 +
 src/backend/replication/slot.c                        | 1 +
 src/backend/replication/syncrep.c                     | 1 +
 src/backend/replication/walreceiver.c                 | 1 +
 src/backend/replication/walreceiverfuncs.c            | 1 +
 src/backend/replication/walsender.c                   | 1 +
 src/backend/storage/buffer/bufmgr.c                   | 1 +
 src/backend/storage/file/buffile.c                    | 1 +
 src/backend/storage/file/copydir.c                    | 1 +
 src/backend/storage/file/fd.c                         | 1 +
 src/backend/storage/ipc/dsm_impl.c                    | 1 +
 src/backend/storage/ipc/ipci.c                        | 1 +
 src/backend/storage/ipc/procarray.c                   | 1 +
 src/backend/storage/ipc/procsignal.c                  | 1 +
 src/backend/storage/ipc/shm_mq.c                      | 1 +
 src/backend/storage/ipc/signalfuncs.c                 | 1 +
 src/backend/storage/ipc/standby.c                     | 1 +
 src/backend/storage/ipc/waiteventset.c                | 1 +
 src/backend/storage/lmgr/lwlock.c                     | 1 +
 src/backend/storage/lmgr/predicate.c                  | 1 +
 src/backend/storage/lmgr/proc.c                       | 1 +
 src/backend/storage/smgr/md.c                         | 1 +
 src/backend/storage/sync/sync.c                       | 1 +
 src/backend/utils/adt/misc.c                          | 1 +
 src/backend/utils/adt/pgstatfuncs.c                   | 1 +
 src/backend/utils/cache/relmapper.c                   | 1 +
 src/backend/utils/init/miscinit.c                     | 1 +
 src/common/controldata_utils.c                        | 1 +
 src/include/pgstat.h                                  | 1 -
 src/include/storage/latch.h                           | 2 ++
 src/test/modules/test_shm_mq/setup.c                  | 1 +
 src/test/modules/test_shm_mq/test.c                   | 1 +
 src/test/modules/worker_spi/worker_spi.c              | 1 +
 79 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
index 89e187425cc..ba0bc8e6d4a 100644
--- a/contrib/pg_prewarm/autoprewarm.c
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -48,6 +48,7 @@
 #include "utils/rel.h"
 #include "utils/relfilenumbermap.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 #define AUTOPREWARM_FILE "autoprewarm.blocks"
 
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 9cd563fd0c3..146ee97a47d 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -43,6 +43,7 @@
 #include "utils/memutils.h"
 #include "utils/rel.h"
 #include "utils/tuplesort.h"
+#include "utils/wait_event.h"
 
 /* Magic numbers for parallel state sharing */
 #define PARALLEL_KEY_BRIN_SHARED		UINT64CONST(0xB000000000000001)
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index ee9b6106922..c7e38dbe193 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -35,6 +35,7 @@
 #include "utils/builtins.h"
 #include "utils/rel.h"
 #include "utils/typcache.h"
+#include "utils/wait_event.h"
 
 
 /* Magic numbers for parallel state sharing */
diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c
index 77fd48eb59e..6b19ac3030d 100644
--- a/src/backend/access/heap/rewriteheap.c
+++ b/src/backend/access/heap/rewriteheap.c
@@ -122,6 +122,7 @@
 #include "storage/procarray.h"
 #include "utils/memutils.h"
 #include "utils/rel.h"
+#include "utils/wait_event.h"
 
 /*
  * State associated with a rewrite operation. This is opaque to the user
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index 5b6f2441f6b..f15b2f3fd1e 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -155,6 +155,7 @@
 #include "utils/lsyscache.h"
 #include "utils/pg_rusage.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 3dec1ee657d..6d0a6f27f3f 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -35,6 +35,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/index_selfuncs.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index fd9d4087b5a..69ef1527e06 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -57,6 +57,7 @@
 #include "utils/rel.h"
 #include "utils/sortsupport.h"
 #include "utils/tuplesort.h"
+#include "utils/wait_event.h"
 
 
 /* Magic numbers for parallel state sharing */
diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c
index b5c38bbb162..3ee1cfdbc24 100644
--- a/src/backend/access/transam/clog.c
+++ b/src/backend/access/transam/clog.c
@@ -45,6 +45,7 @@
 #include "storage/proc.h"
 #include "storage/sync.h"
 #include "utils/guc_hooks.h"
+#include "utils/wait_event.h"
 
 /*
  * Defines for CLOG page sizes.  A page is the same BLCKSZ as is used
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index e69c4b74248..ab1dfb30e73 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -45,6 +45,7 @@
 #include "utils/memutils.h"
 #include "utils/relmapper.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 /*
  * We don't want to waste a lot of memory on an error queue which, most of
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c
index 549c7e3e64b..556edcbf7cb 100644
--- a/src/backend/access/transam/slru.c
+++ b/src/backend/access/transam/slru.c
@@ -71,6 +71,7 @@
 #include "storage/fd.h"
 #include "storage/shmem.h"
 #include "utils/guc.h"
+#include "utils/wait_event.h"
 
 /*
  * Converts segment number to the filename of the segment.
diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/transam/timeline.c
index 60ee28665b1..68e5f692d26 100644
--- a/src/backend/access/transam/timeline.c
+++ b/src/backend/access/transam/timeline.c
@@ -41,6 +41,7 @@
 #include "access/xlogdefs.h"
 #include "pgstat.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 
 /*
  * Copies all timeline history files with id's between 'begin' and 'end'
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 5f65fa7b80f..55b9f38927d 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -106,6 +106,7 @@
 #include "utils/injection_point.h"
 #include "utils/memutils.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /*
  * Directory where Two-phase commit files reside within PGDATA
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index eba4f063168..aafc53e0164 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -72,6 +72,7 @@
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
 #include "utils/typcache.h"
+#include "utils/wait_event.h"
 
 /*
  *	User-tweakable parameters
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 354ac645bdc..b9b678f3722 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -105,6 +105,7 @@
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 #ifdef WAL_DEBUG
 #include "utils/memutils.h"
diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c
index aa0c2fe3afd..9a0c8097cb1 100644
--- a/src/backend/access/transam/xlogarchive.c
+++ b/src/backend/access/transam/xlogarchive.c
@@ -31,6 +31,7 @@
 #include "replication/walsender.h"
 #include "storage/fd.h"
 #include "storage/ipc.h"
+#include "utils/wait_event.h"
 
 /*
  * Attempt to retrieve the specified file from off-line archival storage.
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c
index 2efe4105efb..8965be29703 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -34,6 +34,7 @@
 #include "utils/memutils.h"
 #include "utils/pg_lsn.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /*
  * Backup-related variables.
diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index 03ada8aa0c5..8cb2110cb99 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -36,6 +36,7 @@
 #ifndef FRONTEND
 #include "pgstat.h"
 #include "storage/bufmgr.h"
+#include "utils/wait_event.h"
 #else
 #include "common/logging.h"
 #endif
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index fbddd7e522c..d55a534b138 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -65,6 +65,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/ps_status.h"
 #include "utils/pg_rusage.h"
+#include "utils/wait_event.h"
 
 /* Unsupported old recovery command file names (relative to $PGDATA) */
 #define RECOVERY_COMMAND_FILE	"recovery.conf"
diff --git a/src/backend/access/transam/xlogwait.c b/src/backend/access/transam/xlogwait.c
index d286ff63123..bf4630677b4 100644
--- a/src/backend/access/transam/xlogwait.c
+++ b/src/backend/access/transam/xlogwait.c
@@ -60,6 +60,7 @@
 #include "utils/fmgrprotos.h"
 #include "utils/pg_lsn.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 
 static int	waitlsn_cmp(const pairingheap_node *a, const pairingheap_node *b,
diff --git a/src/backend/archive/shell_archive.c b/src/backend/archive/shell_archive.c
index 5b565968818..0b427a68809 100644
--- a/src/backend/archive/shell_archive.c
+++ b/src/backend/archive/shell_archive.c
@@ -22,6 +22,7 @@
 #include "archive/shell_archive.h"
 #include "common/percentrepl.h"
 #include "pgstat.h"
+#include "utils/wait_event.h"
 
 static bool shell_archive_configured(ArchiveModuleState *state);
 static bool shell_archive_file(ArchiveModuleState *state,
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 2d74c648335..ab1fbae8001 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -48,6 +48,7 @@
 #include "utils/ps_status.h"
 #include "utils/relcache.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 /*
  * How much data do we want to send in one CopyData message? Note that
diff --git a/src/backend/backup/basebackup_throttle.c b/src/backend/backup/basebackup_throttle.c
index e112eed7485..4d8d90f356b 100644
--- a/src/backend/backup/basebackup_throttle.c
+++ b/src/backend/backup/basebackup_throttle.c
@@ -19,6 +19,7 @@
 #include "pgstat.h"
 #include "storage/latch.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 typedef struct bbsink_throttle
 {
diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index fbd13353efc..84c8809a889 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -74,6 +74,7 @@
 #include "port/pg_bswap.h"
 #include "utils/builtins.h"
 #include "utils/rel.h"
+#include "utils/wait_event.h"
 
 #define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
 #define OCTVALUE(c) ((c) - '0')
diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c
index 9ceeff6d99e..d6ef7275a64 100644
--- a/src/backend/commands/copyto.c
+++ b/src/backend/commands/copyto.c
@@ -37,6 +37,7 @@
 #include "utils/memutils.h"
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 /*
  * Represents the different dest cases we need to worry about at
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 740c526e92d..9b18bb4a17e 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -70,6 +70,7 @@
 #include "utils/relmapper.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /*
  * Create database strategy.
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index b9840637783..62c1ebdfd9b 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -61,6 +61,7 @@
 #include "utils/memutils.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /*
  * Minimum interval for cost-based vacuum delay reports from a parallel worker.
diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c
index 39d9442c121..85c85569b5e 100644
--- a/src/backend/executor/nodeAppend.c
+++ b/src/backend/executor/nodeAppend.c
@@ -65,6 +65,7 @@
 #include "pgstat.h"
 #include "storage/latch.h"
 #include "storage/lwlock.h"
+#include "utils/wait_event.h"
 
 /* Shared state for parallel-aware Append. */
 struct ParallelAppendState
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index c68c26cbf38..e0b6df64767 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -45,6 +45,7 @@
 #include "storage/bufmgr.h"
 #include "utils/rel.h"
 #include "utils/spccache.h"
+#include "utils/wait_event.h"
 
 static void BitmapTableScanSetup(BitmapHeapScanState *node);
 static TupleTableSlot *BitmapHeapNext(BitmapHeapScanState *node);
diff --git a/src/backend/libpq/be-secure-gssapi.c b/src/backend/libpq/be-secure-gssapi.c
index 5fb043b8608..540ed62a5cc 100644
--- a/src/backend/libpq/be-secure-gssapi.c
+++ b/src/backend/libpq/be-secure-gssapi.c
@@ -24,6 +24,7 @@
 #include "storage/latch.h"
 #include "utils/injection_point.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.c
index 4da6ac22ff9..14c6532bb16 100644
--- a/src/backend/libpq/be-secure-openssl.c
+++ b/src/backend/libpq/be-secure-openssl.c
@@ -35,6 +35,7 @@
 #include "storage/latch.h"
 #include "utils/guc.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * These SSL-related #includes must come after all system-provided headers.
diff --git a/src/backend/libpq/pqmq.c b/src/backend/libpq/pqmq.c
index 7e4a725b796..22e5164adbf 100644
--- a/src/backend/libpq/pqmq.c
+++ b/src/backend/libpq/pqmq.c
@@ -23,6 +23,7 @@
 #include "storage/latch.h"
 #include "tcop/tcopprot.h"
 #include "utils/builtins.h"
+#include "utils/wait_event.h"
 
 static shm_mq_handle *pq_mq_handle = NULL;
 static bool pq_mq_busy = false;
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 6fde740465f..695e187ba11 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -109,6 +109,7 @@
 #include "utils/syscache.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/postmaster/auxprocess.c b/src/backend/postmaster/auxprocess.c
index 8ea800c0bbd..cf24f662d27 100644
--- a/src/backend/postmaster/auxprocess.c
+++ b/src/backend/postmaster/auxprocess.c
@@ -24,6 +24,7 @@
 #include "storage/procsignal.h"
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
+#include "utils/wait_event.h"
 
 
 static void ShutdownAuxiliaryProcess(int code, Datum arg);
diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c
index 8678ea4e139..0104a86b9ec 100644
--- a/src/backend/postmaster/bgworker.c
+++ b/src/backend/postmaster/bgworker.c
@@ -34,6 +34,7 @@
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
+#include "utils/wait_event.h"
 
 /*
  * The postmaster's list of registered background workers, in private memory.
diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c
index 0956bd39a85..1d8947774a9 100644
--- a/src/backend/postmaster/bgwriter.c
+++ b/src/backend/postmaster/bgwriter.c
@@ -51,6 +51,7 @@
 #include "utils/memutils.h"
 #include "utils/resowner.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /*
  * GUC parameters
diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c
index e03c19123bc..3c982c6ffac 100644
--- a/src/backend/postmaster/checkpointer.c
+++ b/src/backend/postmaster/checkpointer.c
@@ -67,6 +67,7 @@
 #include "utils/guc.h"
 #include "utils/memutils.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 
 /*----------
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 82731e452fc..fa4bdfe9ab9 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -53,6 +53,7 @@
 #include "utils/ps_status.h"
 #include "utils/resowner.h"
 #include "utils/timeout.h"
+#include "utils/wait_event.h"
 
 
 /* ----------
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index 86c5e376b40..9792f638718 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -51,6 +51,7 @@
 #include "utils/guc.h"
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
+#include "utils/wait_event.h"
 
 /*
  * We read() into a temp buffer twice as big as a chunk, so that any fragment
diff --git a/src/backend/postmaster/walwriter.c b/src/backend/postmaster/walwriter.c
index 7c0e2809c17..9cd86ad7022 100644
--- a/src/backend/postmaster/walwriter.c
+++ b/src/backend/postmaster/walwriter.c
@@ -62,6 +62,7 @@
 #include "utils/hsearch.h"
 #include "utils/memutils.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c
index 7cd6e912a9c..d78693ffa8e 100644
--- a/src/backend/replication/logical/applyparallelworker.c
+++ b/src/backend/replication/logical/applyparallelworker.c
@@ -173,6 +173,7 @@
 #include "utils/inval.h"
 #include "utils/memutils.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 #define PG_LOGICAL_APPLY_SHM_MAGIC 0x787ca067
 
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index e6112e11ec2..09964198550 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -44,6 +44,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /* max sleep time between cycles (3min) */
 #define DEFAULT_NAPTIME_PER_CYCLE 180000L
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index c3271a6fd0e..26afd8f0af9 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -95,6 +95,7 @@
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
+#include "utils/wait_event.h"
 
 /* paths for replication origin checkpoint files */
 #define PG_REPLORIGIN_CHECKPOINT_FILENAME PG_LOGICAL_DIR "/replorigin_checkpoint"
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index e832fa0d8ea..b7664b90006 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -113,6 +113,7 @@
 #include "utils/memutils.h"
 #include "utils/rel.h"
 #include "utils/relfilenumbermap.h"
+#include "utils/wait_event.h"
 
 /*
  * Each transaction has an 8MB limit for invalidation messages distributed from
diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c
index 062a08ccb88..19976efe4f2 100644
--- a/src/backend/replication/logical/slotsync.c
+++ b/src/backend/replication/logical/slotsync.c
@@ -75,6 +75,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
+#include "utils/wait_event.h"
 
 /*
  * Struct for sharing information to control slot synchronization.
diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c
index 7f79621b57e..eddb3d9105c 100644
--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -144,6 +144,9 @@
 #include "utils/memutils.h"
 #include "utils/snapmgr.h"
 #include "utils/snapshot.h"
+#include "utils/wait_event.h"
+
+
 /*
  * Starting a transaction -- which we need to do while exporting a snapshot --
  * removes knowledge about the previously used resowner, so we save it here.
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index bccbf61bf39..a0de2efded8 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -122,6 +122,7 @@
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
 #include "utils/usercontext.h"
+#include "utils/wait_event.h"
 
 List	   *table_states_not_ready = NIL;
 
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index f9c4b484754..274dc71c6a1 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -296,6 +296,7 @@
 #include "utils/snapmgr.h"
 #include "utils/syscache.h"
 #include "utils/usercontext.h"
+#include "utils/wait_event.h"
 
 #define NAPTIME_PER_CYCLE 1000	/* max sleep time between cycles (1s) */
 
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index 28c7019402b..a9092fc2382 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -59,6 +59,7 @@
 #include "utils/guc_hooks.h"
 #include "utils/injection_point.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 /*
  * Replication slot on-disk data structure.
diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c
index d1582a5d711..9cecc83ed68 100644
--- a/src/backend/replication/syncrep.c
+++ b/src/backend/replication/syncrep.c
@@ -85,6 +85,7 @@
 #include "tcop/tcopprot.h"
 #include "utils/guc_hooks.h"
 #include "utils/ps_status.h"
+#include "utils/wait_event.h"
 
 /* User-settable parameters for sync rep */
 char	   *SyncRepStandbyNames;
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index 7c1b8757d7d..fabe3c73034 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -79,6 +79,7 @@
 #include "utils/pg_lsn.h"
 #include "utils/ps_status.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c
index e62e8a20420..45b9d4f09f2 100644
--- a/src/backend/replication/walreceiverfuncs.c
+++ b/src/backend/replication/walreceiverfuncs.c
@@ -30,6 +30,7 @@
 #include "storage/proc.h"
 #include "storage/shmem.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 WalRcvData *WalRcv = NULL;
 
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 2cde8ebc729..829ec538ea5 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -98,6 +98,7 @@
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /* Minimum interval used by walsender for stats flushes, in ms */
 #define WALSENDER_STATS_FLUSH_INTERVAL         1000
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index d1babaff023..5f3d083e938 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -68,6 +68,7 @@
 #include "utils/rel.h"
 #include "utils/resowner.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /* Note: these two macros only work on shared buffers, not local ones! */
diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c
index ddf3a410d6f..c4afe4d368a 100644
--- a/src/backend/storage/file/buffile.c
+++ b/src/backend/storage/file/buffile.c
@@ -53,6 +53,7 @@
 #include "storage/bufmgr.h"
 #include "storage/fd.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 /*
  * We break BufFiles into gigabyte-sized segments, regardless of RELSEG_SIZE.
diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c
index 596d9070fd8..5ee141f13a5 100644
--- a/src/backend/storage/file/copydir.c
+++ b/src/backend/storage/file/copydir.c
@@ -29,6 +29,7 @@
 #include "pgstat.h"
 #include "storage/copydir.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 
 /* GUCs */
 int			file_copy_method = FILE_COPY_METHOD_COPY;
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 5d07b64a1ef..01f1bd6e687 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -101,6 +101,7 @@
 #include "utils/guc_hooks.h"
 #include "utils/resowner.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 /* Define PG_FLUSH_DATA_WORKS if we have an implementation for pg_flush_data */
 #if defined(HAVE_SYNC_FILE_RANGE)
diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c
index e208457df27..e8c07805f59 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -68,6 +68,7 @@
 #include "storage/fd.h"
 #include "utils/guc.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 #ifdef USE_DSM_POSIX
 static bool dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c
index 1f7e933d500..a4785daf1e5 100644
--- a/src/backend/storage/ipc/ipci.c
+++ b/src/backend/storage/ipc/ipci.c
@@ -52,6 +52,7 @@
 #include "storage/sinvaladt.h"
 #include "utils/guc.h"
 #include "utils/injection_point.h"
+#include "utils/wait_event.h"
 
 /* GUCs */
 int			shared_memory_type = DEFAULT_SHARED_MEMORY_TYPE;
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index 40312df2cac..406b8253f8b 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -67,6 +67,7 @@
 #include "utils/lsyscache.h"
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 #define UINT32_ACCESS_ONCE(var)		 ((uint32)(*((volatile uint32 *)&(var))))
 
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index d47d180a32f..7e017c8d53b 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -34,6 +34,7 @@
 #include "storage/smgr.h"
 #include "tcop/tcopprot.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * The SIGUSR1 signal is multiplexed to support signaling multiple event
diff --git a/src/backend/storage/ipc/shm_mq.c b/src/backend/storage/ipc/shm_mq.c
index 7e9fbc00705..26b24158ed9 100644
--- a/src/backend/storage/ipc/shm_mq.c
+++ b/src/backend/storage/ipc/shm_mq.c
@@ -26,6 +26,7 @@
 #include "storage/shm_mq.h"
 #include "storage/spin.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * This structure represents the actual queue, stored in shared memory.
diff --git a/src/backend/storage/ipc/signalfuncs.c b/src/backend/storage/ipc/signalfuncs.c
index d48b4fe3799..800b699de21 100644
--- a/src/backend/storage/ipc/signalfuncs.c
+++ b/src/backend/storage/ipc/signalfuncs.c
@@ -25,6 +25,7 @@
 #include "storage/procarray.h"
 #include "utils/acl.h"
 #include "utils/fmgrprotos.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c
index d83afbfb9d6..f3ad90c7c7a 100644
--- a/src/backend/storage/ipc/standby.c
+++ b/src/backend/storage/ipc/standby.c
@@ -35,6 +35,7 @@
 #include "utils/ps_status.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /* User-settable GUC parameters */
 int			max_standby_archive_delay = 30 * 1000;
diff --git a/src/backend/storage/ipc/waiteventset.c b/src/backend/storage/ipc/waiteventset.c
index 772e350a0c0..0f228e1e7b8 100644
--- a/src/backend/storage/ipc/waiteventset.c
+++ b/src/backend/storage/ipc/waiteventset.c
@@ -77,6 +77,7 @@
 #include "storage/waiteventset.h"
 #include "utils/memutils.h"
 #include "utils/resowner.h"
+#include "utils/wait_event.h"
 
 /*
  * Select the fd readiness primitive to use. Normally the "most modern"
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 517c55375b4..49382de88fc 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -85,6 +85,7 @@
 #include "storage/procnumber.h"
 #include "storage/spin.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 #ifdef LWLOCK_STATS
 #include "utils/hsearch.h"
diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c
index fe75ead3501..548b4f66470 100644
--- a/src/backend/storage/lmgr/predicate.c
+++ b/src/backend/storage/lmgr/predicate.c
@@ -214,6 +214,7 @@
 #include "utils/guc_hooks.h"
 #include "utils/rel.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 /* Uncomment the next line to test the graceful degradation code. */
 /* #define TEST_SUMMARIZE_SERIAL */
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index ccf9de0e67c..daf70d9ce2a 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -53,6 +53,7 @@
 #include "storage/standby.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 /* GUC variables */
 int			DeadlockTimeout = 1000;
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 443434e4ea8..dee29037b16 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -40,6 +40,7 @@
 #include "storage/smgr.h"
 #include "storage/sync.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * The magnetic disk storage manager keeps track of open file
diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c
index b1accc68b95..2c964b6f3d9 100644
--- a/src/backend/storage/sync/sync.c
+++ b/src/backend/storage/sync/sync.c
@@ -31,6 +31,7 @@
 #include "storage/md.h"
 #include "utils/hsearch.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 /*
  * In some contexts (currently, standalone backends and the checkpointer)
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index 32a787d7df7..864032c32bf 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -46,6 +46,7 @@
 #include "utils/ruleutils.h"
 #include "utils/syscache.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index b1df96e7b0b..50ea9e8fb83 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -31,6 +31,7 @@
 #include "utils/acl.h"
 #include "utils/builtins.h"
 #include "utils/timestamp.h"
+#include "utils/wait_event.h"
 
 #define UINT32_ACCESS_ONCE(var)		 ((uint32)(*((volatile uint32 *)&(var))))
 
diff --git a/src/backend/utils/cache/relmapper.c b/src/backend/utils/cache/relmapper.c
index 778b14a2318..3aaf466868d 100644
--- a/src/backend/utils/cache/relmapper.c
+++ b/src/backend/utils/cache/relmapper.c
@@ -54,6 +54,7 @@
 #include "storage/lwlock.h"
 #include "utils/inval.h"
 #include "utils/relmapper.h"
+#include "utils/wait_event.h"
 
 
 /*
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index 03f6c8479f2..ba191977697 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -55,6 +55,7 @@
 #include "utils/pidfile.h"
 #include "utils/syscache.h"
 #include "utils/varlena.h"
+#include "utils/wait_event.h"
 
 
 #define DIRECTORY_LOCK_FILE		"postmaster.pid"
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 14530c6489a..4ab116afcde 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -37,6 +37,7 @@
 #ifndef FRONTEND
 #include "pgstat.h"
 #include "storage/fd.h"
+#include "utils/wait_event.h"
 #endif
 
 /*
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 0e9d2b4c623..216b93492ba 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -18,7 +18,6 @@
 #include "utils/backend_progress.h" /* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/backend_status.h"	/* for backward compatibility */	/* IWYU pragma: export */
 #include "utils/pgstat_kind.h"
-#include "utils/wait_event.h"	/* for backward compatibility */	/* IWYU pragma: export */
 
 
 /* avoid including access/transam.h */
diff --git a/src/include/storage/latch.h b/src/include/storage/latch.h
index fbdadc86959..053a32ecf9d 100644
--- a/src/include/storage/latch.h
+++ b/src/include/storage/latch.h
@@ -104,6 +104,8 @@
 #include <signal.h>
 
 #include "storage/waiteventset.h"	/* for WL_* arguments to WaitLatch */
+#include "utils/wait_classes.h"  /* for backward compatibility */	/* IWYU pragma: keep */
+
 
 /*
  * Latch structure should be treated as opaque and only accessed through
diff --git a/src/test/modules/test_shm_mq/setup.c b/src/test/modules/test_shm_mq/setup.c
index 36bb255922c..4f40a61e3d9 100644
--- a/src/test/modules/test_shm_mq/setup.c
+++ b/src/test/modules/test_shm_mq/setup.c
@@ -22,6 +22,7 @@
 #include "storage/shm_toc.h"
 #include "test_shm_mq.h"
 #include "utils/memutils.h"
+#include "utils/wait_event.h"
 
 typedef struct
 {
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index ce97e6e1aa4..ccf5485cc55 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -18,6 +18,7 @@
 #include "pgstat.h"
 #include "storage/proc.h"
 #include "varatt.h"
+#include "utils/wait_event.h"
 
 #include "test_shm_mq.h"
 
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index d1e4a2bd952..b89954279c0 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -39,6 +39,7 @@
 #include "utils/acl.h"
 #include "utils/builtins.h"
 #include "utils/snapmgr.h"
+#include "utils/wait_event.h"
 
 PG_MODULE_MAGIC;
 
-- 
2.47.3

^ permalink  raw  reply  [nested|flat] 33+ messages in thread

* Re: pgstat include expansion
  2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
@ 2026-02-26 12:55 ` Alvaro Herrera <alvherre@kurilemu.de>
  4 siblings, 0 replies; 33+ messages in thread

From: Alvaro Herrera @ 2026-02-26 12:55 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers@postgresql.org, Amit Kapila <amit.kapila16@gmail.com>; Michael Paquier <michael@paquier.xyz>

Hello,

I committed the removal of transam.h and relcache.h from pgstat.h now.
No other files needed adjustment for these changes.

Thanks

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"La fuerza no está en los medios físicos
sino que reside en una voluntad indomable" (Gandhi)





^ permalink  raw  reply  [nested|flat] 33+ messages in thread


end of thread, other threads:[~2026-03-05 15:08 UTC | newest]

Thread overview: 33+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-02-13 22:14 pgstat include expansion Andres Freund <andres@anarazel.de>
2026-02-15 23:19 ` Chao Li <li.evan.chao@gmail.com>
2026-02-16 05:35   ` Amit Kapila <amit.kapila16@gmail.com>
2026-02-16 05:47     ` vignesh C <vignesh21@gmail.com>
2026-02-16 07:59     ` Michael Paquier <michael@paquier.xyz>
2026-02-16 16:32     ` Alvaro Herrera <alvherre@kurilemu.de>
2026-02-16 17:50       ` Andres Freund <andres@anarazel.de>
2026-02-17 04:45         ` Amit Kapila <amit.kapila16@gmail.com>
2026-02-17 07:00           ` Nisha Moond <nisha.moond412@gmail.com>
2026-02-17 11:14             ` Amit Kapila <amit.kapila16@gmail.com>
2026-02-18 04:39               ` Nisha Moond <nisha.moond412@gmail.com>
2026-02-19 04:46                 ` Amit Kapila <amit.kapila16@gmail.com>
2026-02-16 04:36 ` Michael Paquier <michael@paquier.xyz>
2026-02-16 17:18   ` Andres Freund <andres@anarazel.de>
2026-02-16 07:48 ` Nisha Moond <nisha.moond412@gmail.com>
2026-02-19 06:16   ` Amit Kapila <amit.kapila16@gmail.com>
2026-02-23 05:49     ` Amit Kapila <amit.kapila16@gmail.com>
2026-02-16 16:18 ` Alvaro Herrera <alvherre@kurilemu.de>
2026-02-16 16:19   ` Alvaro Herrera <alvherre@kurilemu.de>
2026-02-16 17:41   ` Andres Freund <andres@anarazel.de>
2026-02-16 18:34     ` Alvaro Herrera <alvherre@kurilemu.de>
2026-02-18 15:10       ` Alvaro Herrera <alvherre@kurilemu.de>
2026-02-20 04:35         ` Amit Kapila <amit.kapila16@gmail.com>
2026-02-26 13:52         ` Alvaro Herrera <alvherre@kurilemu.de>
2026-02-26 15:14           ` Andres Freund <andres@anarazel.de>
2026-02-26 15:59             ` Alvaro Herrera <alvherre@kurilemu.de>
2026-02-26 16:19               ` Alvaro Herrera <alvherre@kurilemu.de>
2026-02-26 16:27               ` Andres Freund <andres@anarazel.de>
2026-02-26 17:07                 ` Alvaro Herrera <alvherre@kurilemu.de>
2026-02-26 17:40                 ` Alvaro Herrera <alvherre@kurilemu.de>
2026-02-27 10:37                 ` Alvaro Herrera <alvherre@kurilemu.de>
2026-03-05 15:08                   ` Alvaro Herrera <alvherre@kurilemu.de>
2026-02-26 12:55 ` Alvaro Herrera <alvherre@kurilemu.de>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox