From dd5775184a729c2b5cfff40ff5ab55eed936d2fb Mon Sep 17 00:00:00 2001 From: Maxim Orlov Date: Fri, 20 Jun 2025 17:21:08 +0300 Subject: [PATCH v1 2/2] Fix the mxid and mxoff wraparound issues in pg_upgrade. Per bags: - BUG #18863: Multixact wraparound and pg_resetwal error "multitransaction ID (-m) must not be 0" - BUG #18865: pg_resetwal error: multitransaction offset (-O) must not be -1 --- src/bin/pg_resetwal/pg_resetwal.c | 5 +---- src/bin/pg_upgrade/pg_upgrade.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c index e876f35f38..3b984eeae0 100644 --- a/src/bin/pg_resetwal/pg_resetwal.c +++ b/src/bin/pg_resetwal/pg_resetwal.c @@ -273,8 +273,6 @@ main(int argc, char *argv[]) pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } - if (set_mxoff == -1) - pg_fatal("multitransaction offset (-O) must not be -1"); break; case 'l': @@ -463,8 +461,7 @@ main(int argc, char *argv[]) ControlFile.checkPointCopy.oldestMultiDB = InvalidOid; } - if (set_mxoff != -1) - ControlFile.checkPointCopy.nextMultiOffset = set_mxoff; + ControlFile.checkPointCopy.nextMultiOffset = set_mxoff; if (minXlogTli > ControlFile.checkPointCopy.ThisTimeLineID) { diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index 536e49d261..0bfca6865e 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -793,6 +793,15 @@ copy_xact_xlog_xid(void) if (old_cluster.controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER && new_cluster.controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER) { + uint32 old_chkpnt_nxtmulti = old_cluster.controldata.chkpnt_nxtmulti; + + /* + * Beware of the possibility that chkpnt_nxtmulti is in the + * wrapped-around state in old cluster. + */ + if (old_chkpnt_nxtmulti == 0) + old_chkpnt_nxtmulti = 1; /* FirstMultiXactId */ + copy_subdir_files("pg_multixact/offsets", "pg_multixact/offsets"); copy_subdir_files("pg_multixact/members", "pg_multixact/members"); @@ -806,7 +815,7 @@ copy_xact_xlog_xid(void) "\"%s/pg_resetwal\" -O %u -m %u,%u \"%s\"", new_cluster.bindir, old_cluster.controldata.chkpnt_nxtmxoff, - old_cluster.controldata.chkpnt_nxtmulti, + old_chkpnt_nxtmulti, old_cluster.controldata.chkpnt_oldstMulti, new_cluster.pgdata); check_ok(); -- 2.43.0