]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Minimal fix for WAIT FOR ... MODE 'standby_flush'
authorAndres Freund <andres@anarazel.de>
Tue, 7 Apr 2026 13:11:07 +0000 (09:11 -0400)
committerAndres Freund <andres@anarazel.de>
Tue, 7 Apr 2026 13:48:09 +0000 (09:48 -0400)
The investigation into the negative test performance impact of 7e8aeb9e483
lead to discovering that there are a few issues with WAIT FOR.

This commit is just a minimal fix to prevent hangs in standby_flush mode, due
to WAIT FOR ... 'standby_flush' seeing a 0 LSN if a newly started walreceiver
does not receive any writes, because the stanby is already caught up.

There are several other issues and this is isn't necessarily the best fix. But
this way we get the hangs out of the way.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/zqbppucpmkeqecfy4s5kscnru4tbk6khp3ozqz6ad2zijz354k@w4bdf4z3wqoz

src/backend/replication/walreceiver.c
src/backend/replication/walreceiverfuncs.c

index a437273cf9a94b330364ef5d9907d17e492670d8..09fde92bfd747fcdbc4fabc24cdca3e07f9447f5 100644 (file)
@@ -242,8 +242,6 @@ WalReceiverMain(const void *startup_data, size_t startup_data_len)
 
        SpinLockRelease(&walrcv->mutex);
 
-       pg_atomic_write_u64(&WalRcv->writtenUpto, 0);
-
        /* Arrange to clean up at walreceiver exit */
        on_shmem_exit(WalRcvDie, PointerGetDatum(&startpointTLI));
 
index 4e03e721872c708af5ca7005892bd1d98a9c44a5..bd5d47be964cdae163112da77b6f4d244a62eecd 100644 (file)
@@ -321,6 +321,7 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo,
                walrcv->flushedUpto = recptr;
                walrcv->receivedTLI = tli;
                walrcv->latestChunkStart = recptr;
+               pg_atomic_write_u64(&walrcv->writtenUpto, recptr);
        }
        walrcv->receiveStart = recptr;
        walrcv->receiveStartTLI = tli;