1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-18 17:42:25 +03:00

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
This commit is contained in:
Simon Riggs
2012-06-07 19:26:03 +01:00
parent 110ebff209
commit 090e8a984c

View File

@ -2115,6 +2115,7 @@ XLogBackgroundFlush(void)
{ {
XLogRecPtr WriteRqstPtr; XLogRecPtr WriteRqstPtr;
bool flexible = true; bool flexible = true;
bool wrote_something = false;
/* XLOG doesn't need flushing during recovery */ /* XLOG doesn't need flushing during recovery */
if (RecoveryInProgress()) if (RecoveryInProgress())
@ -2183,10 +2184,18 @@ XLogBackgroundFlush(void)
WriteRqst.Write = WriteRqstPtr; WriteRqst.Write = WriteRqstPtr;
WriteRqst.Flush = WriteRqstPtr; WriteRqst.Flush = WriteRqstPtr;
XLogWrite(WriteRqst, flexible, false); XLogWrite(WriteRqst, flexible, false);
wrote_something = true;
} }
LWLockRelease(WALWriteLock); LWLockRelease(WALWriteLock);
END_CRIT_SECTION(); END_CRIT_SECTION();
/*
* If we wrote something then we have something to send to standbys also,
* otherwise the replication delay become around 7s with just async commit.
*/
if (wrote_something)
WalSndWakeup();
} }
/* /*