=== Applying patches on top of PostgreSQL commit ID 81b2179b492e3af891544813b7e22a42386b34d0 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Sun Nov 15 17:41:28 UTC 2026 On branch cf/6768 nothing to commit, working tree clean === using 'git am' to apply patch ./v9.0001-pg_rewind-use-UUIDs-to-detect-independent-same-TLI-p.patch === Applying: pg_rewind: use UUIDs to detect independent same-TLI promotions Using index info to reconstruct a base tree... M src/backend/access/transam/timeline.c M src/backend/access/transam/xlog.c M src/backend/utils/adt/uuid.c Falling back to patching base and 3-way merge... Auto-merging src/backend/utils/adt/uuid.c Auto-merging src/backend/access/transam/xlog.c Auto-merging src/backend/access/transam/timeline.c CONFLICT (content): Merge conflict in src/backend/access/transam/timeline.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 pg_rewind: use UUIDs to detect independent same-TLI promotions 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". === using patch(1) to apply patch ./v9.0001-pg_rewind-use-UUIDs-to-detect-independent-same-TLI-p.patch === patching file src/backend/access/transam/timeline.c Hunk #1 succeeded at 43 (offset 1 line). Hunk #2 succeeded at 113 (offset 1 line). Hunk #3 succeeded at 132 (offset 1 line). Hunk #4 FAILED at 162. Hunk #5 FAILED at 171. Hunk #6 FAILED at 183. Hunk #7 succeeded at 225 (offset 21 lines). Hunk #8 succeeded at 324 (offset 21 lines). Hunk #9 succeeded at 440 (offset 21 lines). 3 out of 9 hunks FAILED -- saving rejects to file src/backend/access/transam/timeline.c.rej patching file src/backend/access/transam/xlog.c Hunk #2 succeeded at 6659 (offset 14 lines). Hunk #3 succeeded at 6692 (offset 14 lines). patching file src/backend/utils/adt/uuid.c Hunk #2 succeeded at 702 (offset -5 lines). Hunk #3 succeeded at 726 (offset -5 lines). patching file src/bin/pg_rewind/pg_rewind.c patching file src/bin/pg_rewind/t/005_same_timeline.pl patching file src/bin/pg_rewind/timeline.c patching file src/include/access/timeline.h patching file src/include/access/xlog_internal.h patching file src/include/utils/uuid.h Unstaged changes after reset: M src/backend/access/transam/timeline.c M src/backend/access/transam/xlog.c M src/backend/utils/adt/uuid.c M src/bin/pg_rewind/pg_rewind.c M src/bin/pg_rewind/t/005_same_timeline.pl M src/bin/pg_rewind/timeline.c M src/include/access/timeline.h M src/include/access/xlog_internal.h M src/include/utils/uuid.h Removing src/backend/access/transam/timeline.c.rej === using 'git apply' to apply patch ./v9.0001-pg_rewind-use-UUIDs-to-detect-independent-same-TLI-p.patch === Applied patch to 'src/backend/access/transam/timeline.c' with conflicts. Applied patch to 'src/backend/access/transam/xlog.c' cleanly. Applied patch to 'src/backend/utils/adt/uuid.c' cleanly. Applied patch to 'src/bin/pg_rewind/pg_rewind.c' cleanly. Applied patch to 'src/bin/pg_rewind/t/005_same_timeline.pl' cleanly. Applied patch to 'src/bin/pg_rewind/timeline.c' cleanly. Applied patch to 'src/include/access/timeline.h' cleanly. Applied patch to 'src/include/access/xlog_internal.h' cleanly. Applied patch to 'src/include/utils/uuid.h' cleanly. U src/backend/access/transam/timeline.c diff --cc src/backend/access/transam/timeline.c index cc27587a07c,1d1175c1b34..00000000000 --- a/src/backend/access/transam/timeline.c +++ b/src/backend/access/transam/timeline.c @@@ -159,33 -162,17 +166,44 @@@ readTimeLineHistory(TimeLineID targetTL if (*ptr == '\0' || *ptr == '#') continue; ++<<<<<<< ours + if (sscanf(fline, "%u%n", &tli, &nchars) != 1) ++======= + nfields = + sscanf(fline, "%u\t%X/%08X\t%36s", &tli, &switchpoint_hi, &switchpoint_lo, uuid_str); + + if (nfields < 1) ++>>>>>>> theirs { /* expect a numeric timeline ID as first field of line */ ereport(FATAL, (errmsg("syntax error in history file: %s", fline), errhint("Expected a numeric timeline ID."))); } ++<<<<<<< ours + + /* the switchpoint location follows, separated by whitespace */ + ptr = fline + nchars; + nspaces = strspn(ptr, " \t\n\r\f\v"); + if (nspaces > 0) + { + ptr += nspaces; + + /* + * isolate the location from the rest of the line before parsing + * it + */ + token_end = ptr + strcspn(ptr, " \t\n\r\f\v"); + save = *token_end; + *token_end = '\0'; + valid_switchpoint = pg_parse_lsn(ptr, &switchpoint); + *token_end = save; + } + + if (!valid_switchpoint) ++======= + if (nfields < 3) ++>>>>>>> theirs ereport(FATAL, (errmsg("syntax error in history file: %s", fline), errhint("Expected a write-ahead log switchpoint location."))); @@@ -197,12 -184,50 +215,50 @@@ lasttli = tli; - entry = palloc_object(TimeLineHistoryEntry); + /* + * We use palloc0_object to ensure that tluuid is all-zero, which is + * important for pg_rewind to detect whether the history file is + * missing or not. + */ + entry = palloc0_object(TimeLineHistoryEntry); entry->tli = tli; entry->begin = prevend; - entry->end = ((uint64) (switchpoint_hi)) << 32 | (uint64) switchpoint_lo; + entry->end = switchpoint; prevend = entry->end; + /* + * Parse the optional UUID field. Old history files have the reason + * string in field 4. It is in theory possible that the reason string + * starts with a UUID, but the current usage do not store a UUID. This + * allows us to support both old and new formats of history files + * without breaking compatibility by checking if the field contains a + * valid UUID. + */ + if (nfields == 4 && strlen(uuid_str) == UUID_STR_LEN) + { + MemoryContext oldcontext = CurrentMemoryContext; + + PG_TRY(); + { + Datum datum = DirectFunctionCall1(uuid_in, CStringGetDatum(uuid_str)); + + memcpy(&entry->tluuid, DatumGetUUIDP(datum), sizeof(pg_uuid_t)); + } + PG_CATCH(); + { + ErrorData *edata; + + MemoryContextSwitchTo(oldcontext); + edata = CopyErrorData(); + FlushErrorState(); + + ereport(FATAL, + errmsg("invalid UUID in history file \"%s\"", path), + errdetail("%s", edata->message)); + } + PG_END_TRY(); + } + /* Build list with newest item first */ result = lcons(entry, result);