Re: Fix lag columns in pg_stat_replication not advancing when replay LSN stalls
Xuneng Zhou <xunengzhou@gmail.com>
From: Xuneng Zhou <xunengzhou@gmail.com>
To: Fujii Masao <masao.fujii@gmail.com>
Cc: Shinya Kato <shinya11.kato@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>,
Chao Li <li.evan.chao@gmail.com>
Date: 2025-10-21T14:52:39Z
Lists: pgsql-hackers
Hi Fujii-san, On Tue, Oct 21, 2025 at 7:45 AM Fujii Masao <masao.fujii@gmail.com> wrote: > > On Mon, Oct 20, 2025 at 1:45 PM Shinya Kato <shinya11.kato@gmail.com> wrote: > > > > On Mon, Oct 20, 2025 at 10:17 AM Fujii Masao <masao.fujii@gmail.com> wrote: > > > > > > On Sun, Oct 19, 2025 at 2:04 AM Shinya Kato <shinya11.kato@gmail.com> wrote: > > > > Thank you for the patch. I have one comment. > > > > > > > > + if (lag_tracker->overflowed[head].lsn > lsn) > > > > + return now - lag_tracker->overflowed[head].time; > > > > > > > > Could this return a negative value if the clock somehow went > > > > backwards? The original code returns -1 in this case, so I'm curious > > > > about this. > > > > > > Thanks for the review! > > > > > > Yes, you're right. So I've updated the patch so that -1 is returned > > > when the current time is earlier than the time in the overflow entry, > > > treating it as "no new sample found". > > > > Thank you for updating the patch. It looks nice to me. > > Thanks for the review! > Unless there are any objections, I'll commit the patch and > backpatch it to all supported branches. > Thanks for working on this. The patch LGTM. I am wondering whether it is helpful to add some comments for this overflowed array WalTimeSample overflowed[NUM_SYNC_REP_WAIT_MODE]; and replacing literal zeros with the constant InvalidXLogRecPtr for better readability. /* InvalidXLogRecPtr means no overflow yet */ if (lag_tracker->overflowed[i].lsn == InvalidXLogRecPtr) Best, Xuneng
Commits
-
Add comments explaining overflow entries in the replication lag tracker.
- b4810b4bb885 13.23 landed
- 10799d025f2c 14.20 landed
- c16154bfa2a1 15.15 landed
- 4d707f2fd728 16.11 landed
- 8ceab82ca526 17.7 landed
- 5f88da5de3f2 18.1 landed
- abc2b71383b4 19 (unreleased) landed
-
Fix stalled lag columns in pg_stat_replication when replay LSN stops advancing.
- 7d7ebdb800fe 13.23 landed
- a7ab6ce6a0fc 14.20 landed
- 59b215f7217f 15.15 landed
- 2e55cf4efc8d 16.11 landed
- 62d5ee75bbc4 17.7 landed
- 9670032cc51f 18.1 landed
- 883a95646a8e 19 (unreleased) landed