0002-Use-PGAlignedXLogBlock-in-BootStrapXLOG.patch

text/plain

Filename: 0002-Use-PGAlignedXLogBlock-in-BootStrapXLOG.patch
Type: text/plain
Part: 1
Message: missing PG_IO_ALIGN_SIZE uses

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch 0002
Subject: Use PGAlignedXLogBlock in BootStrapXLOG()
File+
src/backend/access/transam/xlog.c 4 8
From ee89bc0b07725adc3dc9c61df15fc2e87e8eb353 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 1 Dec 2025 08:06:26 +0100
Subject: [PATCH 2/3] Use PGAlignedXLogBlock in BootStrapXLOG()

for code simplification
---
 src/backend/access/transam/xlog.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 44e1d4eeabd..89cbda9cc7c 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -5089,7 +5089,7 @@ void
 BootStrapXLOG(uint32 data_checksum_version)
 {
 	CheckPoint	checkPoint;
-	char	   *buffer;
+	PGAlignedXLogBlock buffer;
 	XLogPageHeader page;
 	XLogLongPageHeader longpage;
 	XLogRecord *record;
@@ -5118,10 +5118,8 @@ BootStrapXLOG(uint32 data_checksum_version)
 	sysidentifier |= ((uint64) tv.tv_usec) << 12;
 	sysidentifier |= getpid() & 0xFFF;
 
-	/* page buffer must be aligned suitably for O_DIRECT */
-	buffer = (char *) palloc(XLOG_BLCKSZ + PG_IO_ALIGN_SIZE);
-	page = (XLogPageHeader) TYPEALIGN(PG_IO_ALIGN_SIZE, buffer);
-	memset(page, 0, XLOG_BLCKSZ);
+	memset(&buffer, 0, sizeof buffer);
+	page = (XLogPageHeader) &buffer;
 
 	/*
 	 * Set up information for the initial checkpoint record
@@ -5202,7 +5200,7 @@ BootStrapXLOG(uint32 data_checksum_version)
 	/* Write the first page with the initial record */
 	errno = 0;
 	pgstat_report_wait_start(WAIT_EVENT_WAL_BOOTSTRAP_WRITE);
-	if (write(openLogFile, page, XLOG_BLCKSZ) != XLOG_BLCKSZ)
+	if (write(openLogFile, &buffer, XLOG_BLCKSZ) != XLOG_BLCKSZ)
 	{
 		/* if write didn't set errno, assume problem is no disk space */
 		if (errno == 0)
@@ -5242,8 +5240,6 @@ BootStrapXLOG(uint32 data_checksum_version)
 	BootStrapSUBTRANS();
 	BootStrapMultiXact();
 
-	pfree(buffer);
-
 	/*
 	 * Force control file to be read - in contrast to normal processing we'd
 	 * otherwise never run the checks and GUC related initializations therein.
-- 
2.52.0