=== Applying patches on top of PostgreSQL commit ID 4d936c3fff1ac8dead2cc240ba3da2ed6337257c === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Fri Dec 5 16:57:22 UTC 2025 On branch cf/6038 nothing to commit, working tree clean === using 'git am' to apply patch ./v3-0001-Handle-WAL-timeline-switches-with-incomplete-records.patch === Applying: Handle WAL timeline switches with incomplete records Using index info to reconstruct a base tree... M src/backend/access/transam/xlog.c M src/backend/access/transam/xlogrecovery.c Falling back to patching base and 3-way merge... Auto-merging src/backend/access/transam/xlogrecovery.c CONFLICT (content): Merge conflict in src/backend/access/transam/xlogrecovery.c Auto-merging src/backend/access/transam/xlog.c CONFLICT (content): Merge conflict in src/backend/access/transam/xlog.c error: Failed to merge in the changes. hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 Handle WAL timeline switches with incomplete records When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". Unstaged changes after reset: M src/backend/access/transam/xlog.c M src/backend/access/transam/xlogrecovery.c === using patch(1) to apply patch ./v3-0001-Handle-WAL-timeline-switches-with-incomplete-records.patch === patching file src/backend/access/transam/xlog.c Hunk #1 succeeded at 5919 (offset 34 lines). Hunk #2 succeeded at 5992 (offset 34 lines). Hunk #3 FAILED at 5966. Hunk #4 succeeded at 6065 (offset 34 lines). Hunk #5 FAILED at 6163. 2 out of 5 hunks FAILED -- saving rejects to file src/backend/access/transam/xlog.c.rej patching file src/backend/access/transam/xlogrecovery.c Hunk #1 FAILED at 3168. 1 out of 1 hunk FAILED -- saving rejects to file src/backend/access/transam/xlogrecovery.c.rej Unstaged changes after reset: M src/backend/access/transam/xlog.c Removing src/backend/access/transam/xlog.c.rej Removing src/backend/access/transam/xlogrecovery.c.rej === using 'git apply' to apply patch ./v3-0001-Handle-WAL-timeline-switches-with-incomplete-records.patch === Applied patch to 'src/backend/access/transam/xlog.c' with conflicts. Applied patch to 'src/backend/access/transam/xlogrecovery.c' with conflicts. U src/backend/access/transam/xlog.c U src/backend/access/transam/xlogrecovery.c diff --cc src/backend/access/transam/xlog.c index 22d0a2e8c3a,654a5851eb2..00000000000 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@@ -6058,17 -5964,11 +5998,15 @@@ StartupXLOG(void * (It's critical to first write an OVERWRITE_CONTRECORD message, which * we'll do as soon as we're open for writing new WAL.) */ - if (!XLogRecPtrIsInvalid(missingContrecPtr)) + if (XLogRecPtrIsValid(missingContrecPtr)) { - /* - * We should only have a missingContrecPtr if we're not switching to a - * new timeline. When a timeline switch occurs, WAL is copied from the - * old timeline to the new only up to the end of the last complete - * record, so there can't be an incomplete WAL record that we need to - * disregard. - */ Assert(newTLI == endOfRecoveryInfo->lastRecTLI); ++<<<<<<< ours + Assert(XLogRecPtrIsValid(abortedRecPtr)); ++======= + Assert(!XLogRecPtrIsInvalid(abortedRecPtr)); + Assert(EndOfLog == abortedRecPtr); ++>>>>>>> theirs EndOfLog = missingContrecPtr; } @@@ -6168,16 -6157,6 +6195,19 @@@ /* Shut down xlogreader */ ShutdownWalRecovery(); ++<<<<<<< ours + /* Enable WAL writes for this backend only. */ + LocalSetXLogInsertAllowed(); + + /* If necessary, write overwrite-contrecord before doing anything else */ + if (XLogRecPtrIsValid(abortedRecPtr)) + { + Assert(XLogRecPtrIsValid(missingContrecPtr)); + CreateOverwriteContrecordRecord(abortedRecPtr, missingContrecPtr, newTLI); + } + ++======= ++>>>>>>> theirs /* * Update full_page_writes in shared memory and write an XLOG_FPW_CHANGE * record before resource manager writes cleanup WAL records or checkpoint diff --cc src/backend/access/transam/xlogrecovery.c index 21b8f179ba0,41f6577989e..00000000000 --- a/src/backend/access/transam/xlogrecovery.c +++ b/src/backend/access/transam/xlogrecovery.c @@@ -3182,19 -3168,9 +3182,18 @@@ ReadRecord(XLogPrefetcher *xlogprefetch * of that record. After recovery is done, we'll write a record * to indicate to downstream WAL readers that that portion is to * be ignored. - * - * However, when ArchiveRecoveryRequested = true, we're going to - * switch to a new timeline at the end of recovery. We will only - * copy WAL over to the new timeline up to the end of the last - * complete record, so if we did this, we would later create an - * overwrite contrecord in the wrong place, breaking everything. */ ++<<<<<<< ours + if (!ArchiveRecoveryRequested && + XLogRecPtrIsValid(xlogreader->abortedRecPtr)) + { + abortedRecPtr = xlogreader->abortedRecPtr; + missingContrecPtr = xlogreader->missingContrecPtr; + } ++======= + abortedRecPtr = xlogreader->abortedRecPtr; + missingContrecPtr = xlogreader->missingContrecPtr; ++>>>>>>> theirs if (readFile >= 0) {