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