Use replay position as floor for WAIT FOR LSN standby_(write|flush)
Alexander Korotkov <akorotkov@postgresql.org>
Author:
Alexander Korotkov <akorotkov@postgresql.org>
Date: 2026-05-03T13:22:02Z
Releases:
19 (unreleased)
Use replay position as floor for WAIT FOR LSN standby_(write|flush) GetCurrentLSNForWaitType() for standby_write and standby_flush modes returned only the walreceiver position, which may lag behind WAL already present on the standby from a base backup, archive restore, or prior streaming. This could cause unnecessary blocking if the target LSN falls between the walreceiver's tracked position and the replay position. Fix by returning the maximum of the walreceiver position and the replay position. WAL up to the replay point is physically on disk regardless of its origin, so there is no reason to wait for the walreceiver to re-receive it. This complements 29e7dbf5e4d, which seeded writtenUpto to receiveStart in RequestXLogStreaming() to fix the most common hang scenario. The getter-level floor handles the remaining edge cases: targets between receiveStart and the replay position, and standbys running with archive recovery only (no walreceiver). Reported-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/1957514.1775526774%40sss.pgh.pa.us Author: Xuneng Zhou <xunengzhou@gmail.com> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Files
| Path | Change | +/− |
|---|---|---|
| doc/src/sgml/ref/wait_for.sgml | modified | +17 −21 |
| src/backend/access/transam/xlogwait.c | modified | +19 −2 |
| src/test/recovery/t/049_wait_for_lsn.pl | modified | +73 −0 |
Discussion
- Implement waiting for wal lsn replay: reloaded 154 messages · 2024-11-27 → 2026-07-08