Re: pg_stat_replication.*_lag sometimes shows NULL during active replication

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: Shinya Kato <shinya11(dot)kato(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: pg_stat_replication.*_lag sometimes shows NULL during active replication
Date: 2026-03-24 05:32:00
Message-ID: A50F02CE-67E1-4044-8CD8-DE1CDFBFB7C3@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Mar 23, 2026, at 23:31, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>
> On Sat, Mar 21, 2026 at 11:05 AM Shinya Kato <shinya11(dot)kato(at)gmail(dot)com> wrote:
>>
>> On Fri, Mar 20, 2026 at 2:13 AM Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>>> I think the issue occurs when the positions in the first message point to
>>> the same LSN (e.g., 0/030D5230), and the second message reports the same but
>>> larger LSN (e.g., 0/030D52E0).
>>
>> Thanks for the explanation!
>>
>>> I've updated the patch to address this. It removes fullyAppliedLastTime,
>>> tracks the positions from the previous reply, and clears the lag values only
>>> when the positions remain unchanged across two consecutive messages.
>>>
>>> Patch attached. Could you test and review this updated patch?
>>
>> The patch works properly. I think it looks nice to me, except for the
>> typo I sent in the previous message.
>
> Thanks for the review!
>
> I've fixed the typo and attached an updated patch. I also incorporated
> Chao's comments from upthread. I'm planning to commit this to master.
>
> As for backpatching, I'm hesitant to backpatch the full patch since it may
> reduce the number of replication feedback messages, which feels too invasive
> for stable branches.
>
> That said, the patch's changes in walsender.c could be backpatched.
> As discussed earlier, they don't fully address the reported issue,
> but they do help mitigate cases where lag becomes NULL unexpectedly
> in logical replication. So it might be worth considering those changes
> for stable branches.
>
> Thoughts?
>
> Regards,
>
> --
> Fujii Masao
> <v6-0001-Avoid-sending-duplicate-WAL-locations-in-standby-.patch>

Thank you for updating the patch. I saw that the variable name and function name were changed to reflect my earlier comments.

v6 looks good to me.

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2026-03-24 05:46:34 Re: bugfix - fix broken output in expanded aligned format, when data are too short
Previous Message Chao Li 2026-03-24 05:18:17 Re: unclear OAuth error message