Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w5IGi-0036MQ-13 for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 07:03:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5IGg-00CX9B-1c for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 07:03:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w5IGg-00CX93-0K for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 07:03:06 +0000 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w5IGe-00000000vTr-2KdB for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 07:03:05 +0000 Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-8cfd44fa075so274987485a.0 for ; Wed, 25 Mar 2026 00:03:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774422184; cv=none; d=google.com; s=arc-20240605; b=WFYTlZh143BG4noqwkgqhMIT625ZD0YAnhrgz92o2AI1PYc0nULw/rCa3o13JB/tDE lr/jD1q37aBaWgGzfZ+6pi+xamL4tXn6NKLlRUtfal6GKZsxbQxG80YF7BQkR38G2AFT 2oSGnqdcNzUo9BTNBJx6Wlhpddx3Jnw10BOQyNDouxk7zMAeg/0JHnxHjT7vlvvvAZIw Vtgzzdcx3dCkdG6pXA6k4mrQDdKdLrKJcgkrDEBhxNPRAj1AQuMqr3orKOgXVkb+LnZc sG/aDO61eaLLh9AB6I0YpqvVfJGdj3sB+jnUQE1fK/fT5vrXTxl1rE0GWch/Uhb6vVkQ vrTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=aKltSoTGx38XpshZe1NzyDxMeL9afJVm+b9zTefzXyA=; fh=x4xgi4tdDukVB0fBuAIe3vORvD36rbbTBlhrrGN8QbM=; b=JI4DKGFMZkM46Kt7+5ojeX21zcXNW1A3zwtBXtzotC2sibWq8xJ9+PNslJt0PB9has ugLdYJHqIgod83HVXVBgUPukiI9A6TCXmF4D/FStKpbWyXUKr8TbJG8pYbm6WChbaiEz cNSvO+bxNH7vwLKlxCghbBmc2D4ZZWAIzsKQjcNTBxi5q0G7ciXlvNhch7aCL8cgDe9z iebHe/WlVkw/rViJolIBsvxm2Me/2d0dz0WfnLqv/e6S/go+zDKtNbiBQTIaJyS7M4DB ATDQ72aKY3TBVEX9hcsk7eNQhx3sKYUfAD5YB28mJt5tmsCLE5DM8kmvSCjX507cZDM5 OOzg==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774422184; x=1775026984; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=aKltSoTGx38XpshZe1NzyDxMeL9afJVm+b9zTefzXyA=; b=XJWhVWuXQYLxvwlqUt9VPaKw+wsPo/OjVCegL8LinARhqRadVQ37xSqez8JXvsn1Zc TuxyTvrBGddPAtl+xRJ2T9wh9tLiUfdWF0CJhFL/Hytdbag8m1z9yjzCC2Uxye81XzQ8 hz5Rm5+W6Crj8k5Ojz5gaUadUvs2+SGDutbbs8lG8XUWxwI5sQ2rm+lMS7ZVU8B/9sAh /8Th4uduvaphqAAps5BHpWi5i+xtiq7mYChk4Sn1gWeodGwGACQ3lQSRl3D/ukVGgy76 FzMK8Do4QWbZMliOhIn6nirifwFWCRZTMwCRRLOzNDe9jQtGCYOleyXLlpfAduh5IIf3 D5zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774422184; x=1775026984; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=aKltSoTGx38XpshZe1NzyDxMeL9afJVm+b9zTefzXyA=; b=mK4zrGQkGlndRI6+HI1qvfItpbNFaXlAbJ0+lW9VgeU3Efp+3E0PcYbOKjL+7efsJw mnDwUBosHogZ6vmIM8C3556sgp+Pzzh8FEf3ZFUiUYk1gH1rmdvGM7u1LmYXnr6eJh4i um3+1bNN8NSg/muLHYMB8YRM46AIoC7gbOk+smYh6AO/Q7xgk7HYSpoHKqTWkhR23qdr J5SlxgJztaqury6WCftjjRGNzmQRX5x6BVlPO29S1WoL1DIZYZnF8YjqsEibAgpSBDZi 4En1N54MjDhyCn1zsmL6bB2oXHO2j4IsR6alttdxh9h3c6R/Mrx3TON3AQK/1ld8wWyR MNXA== X-Gm-Message-State: AOJu0YwdelTCCEwmFuPzahgN3Fv+0/lp2ZJO8zPSzjQkPSLKYcbrv8Vh w89AffZMihNS6wVWiBffrcCLHmg5/c92uYgsLL6zK7evAPBRIxj3OYqSVqJBF/4XQ4Gt6PXyRr8 3P3vMNOsbcdRhWByUDjEtvqjl5ozB3w== X-Gm-Gg: ATEYQzxlHEvLe8doIlkGhWbhANZjFfsoWkAXTdXn1oZX71eFLthG+m5ZqcvPLvzvZNq v+0b0KgLA9Fn1qGY0aybC7kZ5u9C1YQjA3rBi8JYG6Tl8wqOFIX85k/TX50SDfSx61skBE5xcfm vETvYq+p3v85QH6dxorc/3OkS3QxzMAl5SJTMtcUWIBAyCdcRAJVaI9jynN6kJnQ+j5kUimRQFy duKcp6EoNls0YPNX3Z2AT6YoqRBGqHJwEdoEsiQcCMkZylIIA2lsUN8jE5TL4+KM8nem6OKeZim WTXuby0= X-Received: by 2002:a05:622a:4aca:b0:509:2618:cefb with SMTP id d75a77b69052e-50b80e31f79mr34432081cf.38.1774422183857; Wed, 25 Mar 2026 00:03:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Shinya Kato Date: Wed, 25 Mar 2026 16:02:53 +0900 X-Gm-Features: AaiRm51Bq1t4oPMY6k5LWHnE4WQIW9ySGOGxG-Xowy44SfJaxYZvis0iCYO2Cds Message-ID: Subject: Re: pg_stat_replication.*_lag sometimes shows NULL during active replication To: Fujii Masao Cc: PostgreSQL Hackers Content-Type: multipart/alternative; boundary="000000000000f34f99064dd3dbe6" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000f34f99064dd3dbe6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 24, 2026, 00:31 Fujii Masao wrote: > On Sat, Mar 21, 2026 at 11:05=E2=80=AFAM Shinya Kato > wrote: > > > > On Fri, Mar 20, 2026 at 2:13=E2=80=AFAM Fujii Masao > wrote: > > > I think the issue occurs when the positions in the first message poin= t > 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 ma= y > 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. > Thanks for the updated patch. LGTM. Regarding the backpatch, I'd personally appreciate it if the walsender.c changes were backpatched to stable branches. As you noted, it don't fully solve the reported issue, but they do help reduce the cases where lag columns in pg_stat_replication unexpectedly become NULL. Even a partial mitigation in the back branches would be valuable for users running stable releases. -- Best regards, Shinya Kato > --000000000000f34f99064dd3dbe6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Tue, Mar 24, 2026, 00:31 Fuji= i Masao <masao.fujii@gmail.com<= /a>> wrote:
On Sat, Mar 21, 2026= at 11:05=E2=80=AFAM Shinya Kato <shinya11.kato@gmail.com> w= rote:
>
> On Fri, Mar 20, 2026 at 2:13=E2=80=AFAM Fujii Masao <masao.fujii= @gmail.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 t= he same but
> > larger LSN (e.g., 0/030D52E0).
>
> Thanks for the explanation!
>
> > I've updated the patch to address this. It removes fullyAppli= edLastTime,
> > tracks the positions from the previous reply, and clears the lag = values only
> > when the positions remain unchanged across two consecutive messag= es.
> >
> > Patch attached. Could you test and review this updated patch?
>
> The patch works properly. I think it looks nice to me, except for the<= br> > typo I sent in the previous message.

Thanks for the review!

I've fixed the typo and attached an updated patch. I also incorporated<= br> Chao's comments from upthread. I'm planning to commit this to maste= r.

As for backpatching, I'm hesitant to backpatch the full patch since it = may
reduce the number of replication feedback messages, which feels too invasiv= e
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.

Thanks for the updated patch. LGTM.

Regarding the backpatch, I'd personally= appreciate it if the walsender.c changes were backpatched to stable branch= es. As you noted, it don't fully solve the reported issue, but they do = help reduce the cases where lag columns in pg_stat_replication unexpectedly= become NULL.

Even a par= tial mitigation in the back branches would be valuable for users running st= able releases.

--
<= div dir=3D"auto">Best regards,
Shinya Kato
--000000000000f34f99064dd3dbe6--