]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix stalled lag columns in pg_stat_replication when replay LSN stops advancing.
authorFujii Masao <fujii@postgresql.org>
Wed, 22 Oct 2025 02:27:15 +0000 (11:27 +0900)
committerFujii Masao <fujii@postgresql.org>
Wed, 22 Oct 2025 02:29:13 +0000 (11:29 +0900)
commita7ab6ce6a0fccf016e74794a896508ba2546cce8
treeb36745ffd7db2fe431d039c5881131d67afc95cd
parent58ba7e5ebfdff6ecfd760bb5b5aecb7b06d48237
Fix stalled lag columns in pg_stat_replication when replay LSN stops advancing.

Previously, when the replay LSN reported in feedback messages from a standby
stopped advancing, for example, due to a recovery conflict, the write_lag and
flush_lag columns in pg_stat_replication would initially update but then stop
progressing. This prevented users from correctly monitoring replication lag.

The problem occurred because when any LSN stopped updating, the lag tracker's
cyclic buffer became full (the write head reached the slowest read head).
In that state, the lag tracker could no longer compute round-trip lag values
correctly.

This commit fixes the issue by handling the slowest read entry (the one
causing the buffer to fill) as a separate overflow entry and freeing space
so the write and other read heads can continue advancing in the buffer.
As a result, write_lag and flush_lag now continue updating even if the reported
replay LSN remains stalled.

Backpatch to all supported versions.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Chao Li <lic@highgo.com>
Reviewed-by: Shinya Kato <shinya11.kato@gmail.com>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwGdGQ=1-X-71Caee-LREBUXSzyohkoQJd4yZZCMt24C0g@mail.gmail.com
Backpatch-through: 13
src/backend/replication/walsender.c