From 1afcff4eacdcb8c7d9c5547432d546d16ebef3a2 Mon Sep 17 00:00:00 2001 From: Takashi Menjo Date: Mon, 16 Mar 2020 11:13:59 +0900 Subject: [PATCH v2 1/5] Preallocate more WAL segments --- src/backend/access/transam/xlog.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 4361568882..b0362dce44 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -894,7 +894,7 @@ static bool WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, bool fetching_ckpt, XLogRecPtr tliRecPtr); static int emode_for_corrupt_record(int emode, XLogRecPtr RecPtr); static void XLogFileClose(void); -static void PreallocXlogFiles(XLogRecPtr endptr); +static void PreallocXlogFiles(XLogRecPtr RedoRecPtr, XLogRecPtr endptr); static void RemoveTempXlogFiles(void); static void RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr lastredoptr, XLogRecPtr endptr); static void RemoveXlogFile(const char *segname, XLogRecPtr lastredoptr, XLogRecPtr endptr); @@ -3824,27 +3824,20 @@ XLogFileClose(void) /* * Preallocate log files beyond the specified log endpoint. - * - * XXX this is currently extremely conservative, since it forces only one - * future log segment to exist, and even that only if we are 75% done with - * the current one. This is only appropriate for very low-WAL-volume systems. - * High-volume systems will be OK once they've built up a sufficient set of - * recycled log segments, but the startup transient is likely to include - * a lot of segment creations by foreground processes, which is not so good. */ static void -PreallocXlogFiles(XLogRecPtr endptr) +PreallocXlogFiles(XLogRecPtr RedoRecPtr, XLogRecPtr endptr) { XLogSegNo _logSegNo; + XLogSegNo endSegNo; + XLogSegNo recycleSegNo; int lf; bool use_existent; - uint64 offset; - XLByteToPrevSeg(endptr, _logSegNo, wal_segment_size); - offset = XLogSegmentOffset(endptr - 1, wal_segment_size); - if (offset >= (uint32) (0.75 * wal_segment_size)) + XLByteToPrevSeg(endptr, endSegNo, wal_segment_size); + recycleSegNo = XLOGfileslop(RedoRecPtr); + for (_logSegNo = endSegNo + 1; _logSegNo <= recycleSegNo; _logSegNo++) { - _logSegNo++; use_existent = true; lf = XLogFileInit(_logSegNo, &use_existent, true); close(lf); @@ -7748,7 +7741,7 @@ StartupXLOG(void) /* * Preallocate additional log files, if wanted. */ - PreallocXlogFiles(EndOfLog); + PreallocXlogFiles(RedoRecPtr, EndOfLog); /* * Okay, we're officially UP. @@ -8962,7 +8955,7 @@ CreateCheckPoint(int flags) * segments, since that may supply some of the needed files.) */ if (!shutdown) - PreallocXlogFiles(recptr); + PreallocXlogFiles(RedoRecPtr, recptr); /* * Truncate pg_subtrans if possible. We can throw away all data before @@ -9312,7 +9305,7 @@ CreateRestartPoint(int flags) * Make more log segments if needed. (Do this after recycling old log * segments, since that may supply some of the needed files.) */ - PreallocXlogFiles(endptr); + PreallocXlogFiles(RedoRecPtr, endptr); /* * ThisTimeLineID is normally not set when we're still in recovery. -- 2.17.1