Re: pgstat include expansion
Nisha Moond <nisha.moond412@gmail.com>
From: Nisha Moond <nisha.moond412@gmail.com>
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>
Date: 2026-02-18T04:39:03Z
Lists: pgsql-hackers
Attachments
- v2-0001-Add-get_logical_worker_type-to-retrieve-the-worke.patch (application/octet-stream) patch v2-0001
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
Commits
-
Don't include wait_event.h in pgstat.h
- 868825aaeb40 19 (unreleased) landed
-
Don't include proc.h in shm_mq.h
- a2c89835f512 19 (unreleased) landed
-
Don't include latch.h in libpq/libpq.h
- 7b9b620d8fc7 19 (unreleased) landed
-
Reduce includes in pgstat.h
- 7bb50dd7d6b9 19 (unreleased) landed
-
Avoid including utils/timestamp.h in conflict.h.
- 308622edf174 19 (unreleased) landed
-
Avoid including worker_internal.h in pgstat.h.
- 9842e8aca096 19 (unreleased) landed
-
Add seq_sync_error_count to subscription statistics.
- f6a4c498dcf6 19 (unreleased) cited
-
Don't include execnodes.h in replication/conflict.h
- 7e638d7f5093 19 (unreleased) cited
-
Collect statistics about conflicts in logical replication.
- 6c2b5edecc0d 18.0 cited