Re: Fix lag columns in pg_stat_replication not advancing when replay LSN stalls - Mailing list pgsql-hackers

From Fujii Masao
Subject Re: Fix lag columns in pg_stat_replication not advancing when replay LSN stalls
Date
Msg-id CAHGQGwEyzPoB+9eRRABp7oKFX12ACdU0oifz7oexmuJpQuMxTQ@mail.gmail.com
Whole thread Raw
In response to Re: Fix lag columns in pg_stat_replication not advancing when replay LSN stalls  (Chao Li <li.evan.chao@gmail.com>)
Responses Re: Fix lag columns in pg_stat_replication not advancing when replay LSN stalls
List pgsql-hackers
On Fri, Oct 17, 2025 at 5:11 PM Chao Li <li.evan.chao@gmail.com> wrote:
> It took me some time to understand this fix. My most confusing was that once overwrite happens, how a reader head to
catchup again? Finally I figured it out: 
>
> ```
> +               lag_tracker->read_heads[head] =
> +                       (lag_tracker->write_head + 1) % LAG_TRACKER_BUFFER_SIZE;
> ```
>
> "(lag_tracker->write_head + 1) % LAG_TRACKER_BUFFER_SIZE” points to the oldest LSN in the ring, from where an
overflowedreader head starts to catch up. 
>
> I have no comment on the code change. Nice patch!

Thanks for the review!

I've updated the source comment to make the code easier to understand.
The updated patch is attached.


> All I wonder is if we can add a TAP test for this fix?

I think it would be good to add a test for this fix, but reproducing
the condition
where the buffer fills up and the slowest read entry overflows takes a time.
Because of that, I'm not sure adding such a potentially slow test is a
good idea.

Regards,

--
Fujii Masao

Attachment

pgsql-hackers by date:

Previous
From: Daniele Varrazzo
Date:
Subject: Getting the SQLSTATE after a failed connection
Next
From: Tom Lane
Date:
Subject: Re: Minor spelling fix in memnodes.h