=== Applying patches on top of PostgreSQL commit ID 26a3c0a45cc6017ee7f334c0ef63292d5e101b58 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Fri Sep 18 07:55:31 UTC 2026 On branch cf/7317 nothing to commit, working tree clean === using 'git am' to apply patch ./v7.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 M src/bin/pg_rewind/pg_rewind.c M src/bin/pg_rewind/timeline.c M src/include/access/timeline.h M src/include/access/xlog_internal.h Falling back to patching base and 3-way merge... Auto-merging src/include/access/xlog_internal.h Auto-merging src/include/access/timeline.h CONFLICT (content): Merge conflict in src/include/access/timeline.h Auto-merging src/bin/pg_rewind/timeline.c CONFLICT (content): Merge conflict in src/bin/pg_rewind/timeline.c Auto-merging src/bin/pg_rewind/pg_rewind.c 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 ./v7.0001-pg_rewind-use-UUIDs-to-detect-independent-same-TLI-p.patch === patching file src/backend/access/transam/timeline.c Hunk #8 FAILED at 342. 1 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 6645 (offset 267 lines). Hunk #3 succeeded at 6678 (offset 267 lines). patching file src/backend/utils/adt/uuid.c Hunk #1 succeeded at 91 (offset 19 lines). Hunk #2 succeeded at 707 (offset 126 lines). Hunk #3 succeeded at 731 (offset 126 lines). patching file src/bin/pg_rewind/pg_rewind.c Hunk #2 succeeded at 67 (offset 1 line). Hunk #3 succeeded at 158 (offset 1 line). Hunk #4 succeeded at 393 (offset 4 lines). Hunk #5 succeeded at 421 (offset 4 lines). Hunk #6 succeeded at 1012 (offset 122 lines). Hunk #7 succeeded at 1101 (offset 122 lines). Hunk #8 succeeded at 1172 (offset 122 lines). patching file src/bin/pg_rewind/t/005_same_timeline.pl patching file src/bin/pg_rewind/timeline.c Hunk #1 FAILED at 9. Hunk #2 FAILED at 48. Hunk #3 FAILED at 66. Hunk #4 FAILED at 75. Hunk #5 succeeded at 120 with fuzz 1 (offset 21 lines). Hunk #6 succeeded at 152 (offset 21 lines). 4 out of 6 hunks FAILED -- saving rejects to file src/bin/pg_rewind/timeline.c.rej patching file src/include/access/timeline.h Hunk #3 FAILED at 35. 1 out of 3 hunks FAILED -- saving rejects to file src/include/access/timeline.h.rej 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 Removing src/bin/pg_rewind/timeline.c.rej Removing src/include/access/timeline.h.rej === using 'git apply' to apply patch ./v7.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' with conflicts. Applied patch to 'src/include/access/timeline.h' with conflicts. 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 U src/bin/pg_rewind/timeline.c U src/include/access/timeline.h diff --cc src/backend/access/transam/timeline.c index d80c8ffe0a7,dee579c039b..00000000000 --- a/src/backend/access/transam/timeline.c +++ b/src/backend/access/transam/timeline.c @@@ -303,15 -361,17 +361,21 @@@ findNewestTimeLine(TimeLineID startTLI */ void writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI, ++<<<<<<< ours + XLogRecPtr switchpoint, const char *reason) ++======= + const pg_uuid_t *newTLUUID, + XLogRecPtr switchpoint, char *reason) ++>>>>>>> theirs { char path[MAXPGPATH]; char tmppath[MAXPGPATH]; char histfname[MAXFNAMELEN]; char buffer[BLCKSZ]; + char *uuid_str; int srcfd; int fd; - int nbytes; + ssize_t nbytes; Assert(newTLI > parentTLI); /* else bad selection of newTLI */ diff --cc src/bin/pg_rewind/timeline.c index f4e1d7f7d1b,7bfadc21bdd..00000000000 --- a/src/bin/pg_rewind/timeline.c +++ b/src/bin/pg_rewind/timeline.c @@@ -9,10 -9,40 +9,41 @@@ */ #include "postgres_fe.h" + #include + #include + #include "access/timeline.h" +#include "common/pg_parse_lsn.h" #include "pg_rewind.h" + /* + * Parse a UUID string in standard dashed form into a pg_uuid_t. + * Returns true on success, false if str is not a valid UUID string. + */ + static bool + rewind_parse_uuid(const char *str, pg_uuid_t *uuid) + { + const char *src = str; + + for (int i = 0; i < UUID_LEN; i++) + { + char buf[3]; + + if (!isxdigit((unsigned char) src[0]) || + !isxdigit((unsigned char) src[1])) + return false; + buf[0] = src[0]; + buf[1] = src[1]; + buf[2] = '\0'; + uuid->data[i] = (unsigned char) strtoul(buf, NULL, 16); + src += 2; + /* skip dash at positions after bytes 3, 5, 7, 9 (i == 3,5,7,9) */ + if (src[0] == '-' && (i == 3 || i == 5 || i == 7 || i == 9)) + src++; + } + return (*src == '\0'); + } + /* * This is copy-pasted from the backend readTimeLineHistory, modified to * return a malloc'd array and to work without backend functions. @@@ -45,13 -75,13 +76,22 @@@ rewind_parseTimeLineHistory(char *buffe while (!lastline) { char *ptr; + char *token_end; + char save; TimeLineID tli; ++<<<<<<< ours + XLogRecPtr switchpoint; + bool valid_switchpoint = false; + int nchars; + size_t nspaces; ++======= + uint32 switchpoint_hi; + uint32 switchpoint_lo; + int nfields; + char uuid_str[UUID_STR_LEN + 1] = {0}; + pg_uuid_t buf; + ++>>>>>>> theirs fline = bufptr; while (*bufptr && *bufptr != '\n') @@@ -70,33 -100,17 +110,44 @@@ 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 */ pg_log_error("syntax error in history file: %s", fline); pg_log_error_detail("Expected a numeric timeline ID."); exit(1); } ++<<<<<<< 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 { pg_log_error("syntax error in history file: %s", fline); pg_log_error_detail("Expected a write-ahead log switchpoint location."); @@@ -117,10 -131,18 +168,18 @@@ entry = &entries[nlines - 1]; entry->tli = tli; entry->begin = prevend; - entry->end = ((uint64) (switchpoint_hi)) << 32 | (uint64) switchpoint_lo; + entry->end = switchpoint; prevend = entry->end; - /* we ignore the remainder of each line */ + /* + * Parse the optional UUID field. Old history files have the reason + * string in field 4; its first word is much shorter than UUID_STR_LEN + * so the length check safely distinguishes old from new format. + */ + memset(&entry->tluuid, 0, sizeof(pg_uuid_t)); + if (nfields == 4 && strlen(uuid_str) == UUID_STR_LEN) + if (rewind_parse_uuid(uuid_str, &buf)) + memcpy(&entry->tluuid, &buf, sizeof(pg_uuid_t)); } if (entries && targetTLI <= lasttli) diff --cc src/include/access/timeline.h index 3aee3419a5c,cdd642c94f0..00000000000 --- a/src/include/access/timeline.h +++ b/src/include/access/timeline.h @@@ -33,8 -35,9 +35,14 @@@ extern List *readTimeLineHistory(TimeLi extern bool existsTimeLineHistory(TimeLineID probeTLI); extern TimeLineID findNewestTimeLine(TimeLineID startTLI); extern void writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI, ++<<<<<<< ours + XLogRecPtr switchpoint, const char *reason); +extern void writeTimeLineHistoryFile(TimeLineID tli, const char *content, size_t size); ++======= + const pg_uuid_t *newTLUUID, + XLogRecPtr switchpoint, char *reason); + extern void writeTimeLineHistoryFile(TimeLineID tli, char *content, int size); ++>>>>>>> theirs extern void restoreTimeLineHistoryFiles(TimeLineID begin, TimeLineID end); extern bool tliInHistory(TimeLineID tli, List *expectedTLEs); extern TimeLineID tliOfPointInHistory(XLogRecPtr ptr, List *history);