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

