From 34ef02b4d4c06e2bae6ad09cfd6d9c097eb73743 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Mon, 17 Jan 2011 12:22:24 +0200 Subject: [PATCH] Before exiting walreceiver, fsync() all the WAL received. Otherwise WAL recovery will replay the un-flushed WAL after walreceiver has exited, which can lead to a non-recoverable standby if the system crashes hard at that point. --- src/backend/replication/walreceiver.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index d257caf913..7005307dc2 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -324,6 +324,9 @@ WalRcvDie(int code, Datum arg) /* use volatile pointer to prevent code rearrangement */ volatile WalRcvData *walrcv = WalRcv; + /* Ensure that all WAL records received are flushed to disk */ + XLogWalRcvFlush(); + SpinLockAcquire(&walrcv->mutex); Assert(walrcv->walRcvState == WALRCV_RUNNING || walrcv->walRcvState == WALRCV_STOPPING); -- 2.11.0