postgres.git / summary / log / commit / refs
commit 9842e8aca096d9b988a3ae924cdf4aa7e1bb2ea2
Author: Amit Kapila <akapila@postgresql.org>
Date: Fri Feb 20 03:56:33 2026 +0000
First released in: 19.0
Avoid including worker_internal.h in pgstat.h.
pgstat.h is a widely included header. Including worker_internal.h there is
unnecessary and creates tight coupling. By refactoring
pgstat_report_subscription_error() to fetch the required
LogicalRepWorkerType internally rather than receiving it as an argument,
we can eliminate the need for the internal header.
Reported-by: Andres Freund <andres@anarazel.de>
Author: Nisha Moond <nisha.moond412@gmail.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://postgr.es/m/aY-UE-4t7FiYgH3t@alap3.anarazel.de
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 adbdec49a0c..bae8c011390 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -5644,8 +5644,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();
}
@@ -6000,8 +5999,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 33fb7f552b4..4ecbdcfadac 100644
--- a/src/include/replication/worker_internal.h
+++ b/src/include/replication/worker_internal.h
@@ -393,4 +393,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"
[parent: ba401828c194]