Re: Fix lag columns in pg_stat_replication not advancing when replay LSN stalls
Fujii Masao <masao.fujii@gmail.com>
From: Fujii Masao <masao.fujii@gmail.com>
To: Chao Li <li.evan.chao@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-10-17T14:28:17Z
Lists: pgsql-hackers
Attachments
- v2-0001-Fix-stalled-lag-columns-in-pg_stat_replication-wh.patch (application/octet-stream) patch v2-0001
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 catch up 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 overflowed reader 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
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