Skip to content

Commit 090e8a9

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 110ebff commit 090e8a9

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
@@ -2115,6 +2115,7 @@ XLogBackgroundFlush(void)
21152115
{
21162116
XLogRecPtr WriteRqstPtr;
21172117
bool flexible = true;
2118+
bool wrote_something = false;
21182119

21192120
/* XLOG doesn't need flushing during recovery */
21202121
if (RecoveryInProgress())
@@ -2183,10 +2184,18 @@ XLogBackgroundFlush(void)
21832184
WriteRqst.Write = WriteRqstPtr;
21842185
WriteRqst.Flush = WriteRqstPtr;
21852186
XLogWrite(WriteRqst, flexible, false);
2187+
wrote_something = true;
21862188
}
21872189
LWLockRelease(WALWriteLock);
21882190

21892191
END_CRIT_SECTION();
2192+
2193+
/*
2194+
* If we wrote something then we have something to send to standbys also,
2195+
* otherwise the replication delay become around 7s with just async commit.
2196+
*/
2197+
if (wrote_something)
2198+
WalSndWakeup();
21902199
}
21912200

21922201
/*

0 commit comments

Comments
 (0)