Skip to content

Commit 16222f3

Browse files
Wake WALSender to reduce data loss at failover for async commit.
WALSender now woken up after each background flush by WALwriter, avoiding multi-second replication delay for an all-async commit workload. Replication delay reduced from 7s with default settings to 200ms, allowing significantly reduced data loss at failover. Andres Freund and Simon Riggs
1 parent 5c35328 commit 16222f3

File tree

1 file changed

+9
-0
lines changed
  • src/backend/access/transam

1 file changed

+9
-0
lines changed

src/backend/access/transam/xlog.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,6 +2168,7 @@ XLogBackgroundFlush(void)
21682168
{
21692169
XLogRecPtr WriteRqstPtr;
21702170
bool flexible = true;
2171+
bool wrote_something = false;
21712172

21722173
/* XLOG doesn't need flushing during recovery */
21732174
if (RecoveryInProgress())
@@ -2236,10 +2237,18 @@ XLogBackgroundFlush(void)
22362237
WriteRqst.Write = WriteRqstPtr;
22372238
WriteRqst.Flush = WriteRqstPtr;
22382239
XLogWrite(WriteRqst, flexible, false);
2240+
wrote_something = true;
22392241
}
22402242
LWLockRelease(WALWriteLock);
22412243

22422244
END_CRIT_SECTION();
2245+
2246+
/*
2247+
* If we wrote something then we have something to send to standbys also,
2248+
* otherwise the replication delay become around 7s with just async commit.
2249+
*/
2250+
if (wrote_something)
2251+
WalSndWakeup();
22432252
}
22442253

22452254
/*

0 commit comments

Comments
 (0)