pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Don't make WAIT FOR LSN depend on WAL written after a page bound 2+ messages / 1 participants [nested] [flat]
* pgsql: Don't make WAIT FOR LSN depend on WAL written after a page bound @ 2026-11-18 14:23 Alexander Korotkov <akorotkov@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Alexander Korotkov @ 2026-11-18 14:23 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Don't make WAIT FOR LSN depend on WAL written after a page boundary When the last WAL record ends exactly at a page boundary, pg_current_wal_insert_lsn() reports the position after the next page's header, 24 bytes past the boundary, or 40 bytes at a segment start. The flush, write, and replay positions stay at the boundary until more WAL is written. So WAIT FOR LSN on the value recommended in the documentation could hang until some unrelated record, such as bgwriter's RUNNING_XACTS, or until its timeout expired. This was first seen as an unexplained delay in 049_wait_for_lsn.pl and then hit about once in 2000 waits by an application doing read-your-writes. No WAL record can end inside a page header, so a target pointing into or just past the header denotes the same point in the WAL as the start of the page. Map such targets to the page start in WAIT itself, so that existing callers of pg_current_wal_insert_lsn() don't need a workaround. Do this in ExecWaitStmt() rather than in WaitForLSN(), whose internal callers may want to wait for any WAL past a given record end. Similar off-by-header problem was fixed for gistGetFakeLSN() in b1f14c9672 by introducing GetXLogInsertEndRecPtr(). Reported-by: Jobin Augustine <jobin.augustine@percona.com> Author: Alexander Korotkov <aekorotkov@gmail.com> Co-authored-by: Xuneng Zhou <xunengzhou@gmail.com> Discussion: https://postgr.es/m/CABPTF7WZ1yuYz8V=xsbghg8e7qaAm5MpyNw6BthWcbN7+P6biw@mail.gmail.com Backpatch-through: 19 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/24723e7cf397fc0f79b0b14412831db36882a29a Modified Files -------------- src/backend/commands/wait.c | 37 ++++++++++++++- src/test/recovery/t/049_wait_for_lsn.pl | 81 +++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Don't make WAIT FOR LSN depend on WAL written after a page bound @ 2026-11-18 14:23 Alexander Korotkov <akorotkov@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Alexander Korotkov @ 2026-11-18 14:23 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Don't make WAIT FOR LSN depend on WAL written after a page boundary When the last WAL record ends exactly at a page boundary, pg_current_wal_insert_lsn() reports the position after the next page's header, 24 bytes past the boundary, or 40 bytes at a segment start. The flush, write, and replay positions stay at the boundary until more WAL is written. So WAIT FOR LSN on the value recommended in the documentation could hang until some unrelated record, such as bgwriter's RUNNING_XACTS, or until its timeout expired. This was first seen as an unexplained delay in 049_wait_for_lsn.pl and then hit about once in 2000 waits by an application doing read-your-writes. No WAL record can end inside a page header, so a target pointing into or just past the header denotes the same point in the WAL as the start of the page. Map such targets to the page start in WAIT itself, so that existing callers of pg_current_wal_insert_lsn() don't need a workaround. Do this in ExecWaitStmt() rather than in WaitForLSN(), whose internal callers may want to wait for any WAL past a given record end. Similar off-by-header problem was fixed for gistGetFakeLSN() in b1f14c9672 by introducing GetXLogInsertEndRecPtr(). Reported-by: Jobin Augustine <jobin.augustine@percona.com> Author: Alexander Korotkov <aekorotkov@gmail.com> Co-authored-by: Xuneng Zhou <xunengzhou@gmail.com> Discussion: https://postgr.es/m/CABPTF7WZ1yuYz8V=xsbghg8e7qaAm5MpyNw6BthWcbN7+P6biw@mail.gmail.com Backpatch-through: 19 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/19aa5713be2b32109c006b3bce9b0881aef3a723 Modified Files -------------- src/backend/commands/wait.c | 37 ++++++++++++++- src/test/recovery/t/049_wait_for_lsn.pl | 81 +++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-11-18 14:23 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-11-18 14:23 pgsql: Don't make WAIT FOR LSN depend on WAL written after a page bound Alexander Korotkov <akorotkov@postgresql.org> 2026-11-18 14:23 pgsql: Don't make WAIT FOR LSN depend on WAL written after a page bound Alexander Korotkov <akorotkov@postgresql.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox