Skip to content

Commit 5231ed8

Browse files
committed
Use replay LSN as target for cascading logical WAL senders
A cascading WAL sender doing logical decoding (as known as doing its work on a standby) has been using as flush LSN the value returned by GetStandbyFlushRecPtr() (last position safely flushed to disk). This is incorrect as such processes are only able to decode changes up to the LSN that has been replayed by the startup process. This commit changes cascading logical WAL senders to use the replay LSN, as returned by GetXLogReplayRecPtr(). This distinction is important particularly during shutdown, when WAL senders need to send any remaining available data to their clients, switching WAL senders to a caught-up state. Using the latest flush LSN rather than the replay LSN could cause the WAL senders to be stuck in an infinite loop preventing them to shut down, as the startup process does not run when WAL senders attempt to catch up, so they could keep waiting for work that would never happen. Backpatch down to v16, where logical decoding on standbys has been introduced. Author: Alexey Makhmutov <a.makhmutov@postgrespro.ru> Reviewed-by: Ajin Cherian <itsajin@gmail.com> Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/52138028-7246-421c-9161-4fa108b88070@postgrespro.ru Backpatch-through: 16
1 parent c98975b commit 5231ed8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/backend/replication/walsender.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3449,8 +3449,16 @@ XLogSendLogical(void)
34493449
if (flushPtr == InvalidXLogRecPtr ||
34503450
logical_decoding_ctx->reader->EndRecPtr >= flushPtr)
34513451
{
3452+
/*
3453+
* For cascading logical WAL senders, we use the replay LSN instead of
3454+
* the flush LSN, since logical decoding on a standby only processes
3455+
* WAL that has been replayed. This distinction becomes particularly
3456+
* important during shutdown, as new WAL is no longer replayed and the
3457+
* last replayed LSN marks the furthest point up to which decoding can
3458+
* proceed.
3459+
*/
34523460
if (am_cascading_walsender)
3453-
flushPtr = GetStandbyFlushRecPtr(NULL);
3461+
flushPtr = GetXLogReplayRecPtr(NULL);
34543462
else
34553463
flushPtr = GetFlushRecPtr(NULL);
34563464
}

0 commit comments

Comments
 (0)