Skip to content

Commit c2638d1

Browse files
author
Alexander Korotkov
committed
Fix pg_upgrade.
1 parent 085b44f commit c2638d1

File tree

4 files changed

+31
-36
lines changed

4 files changed

+31
-36
lines changed

src/bin/pg_upgrade/controldata.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -195,26 +195,7 @@ get_control_data(ClusterInfo *cluster, bool live_check)
195195
pg_fatal("%d: controldata retrieval problem\n", __LINE__);
196196

197197
p++; /* remove ':' char */
198-
cluster->controldata.chkpnt_nxtepoch = str2uint(p);
199-
200-
/*
201-
* Delimiter changed from '/' to ':' in 9.6. We don't test for
202-
* the catalog version of the change because the catalog version
203-
* is pulled from pg_controldata too, and it isn't worth adding an
204-
* order dependency for this --- we just check the string.
205-
*/
206-
if (strchr(p, '/') != NULL)
207-
p = strchr(p, '/');
208-
else if (GET_MAJOR_VERSION(cluster->major_version) >= 906)
209-
p = strchr(p, ':');
210-
else
211-
p = NULL;
212-
213-
if (p == NULL || strlen(p) <= 1)
214-
pg_fatal("%d: controldata retrieval problem\n", __LINE__);
215-
216-
p++; /* remove '/' or ':' char */
217-
cluster->controldata.chkpnt_nxtxid = str2uint(p);
198+
cluster->controldata.chkpnt_nxtxid = str2uint64(p);
218199
got_xid = true;
219200
}
220201
else if ((p = strstr(bufin, "Latest checkpoint's NextOID:")) != NULL)
@@ -236,7 +217,7 @@ get_control_data(ClusterInfo *cluster, bool live_check)
236217
pg_fatal("%d: controldata retrieval problem\n", __LINE__);
237218

238219
p++; /* remove ':' char */
239-
cluster->controldata.chkpnt_nxtmulti = str2uint(p);
220+
cluster->controldata.chkpnt_nxtmulti = str2uint64(p);
240221
got_multi = true;
241222
}
242223
else if ((p = strstr(bufin, "Latest checkpoint's oldestMultiXid:")) != NULL)
@@ -247,7 +228,7 @@ get_control_data(ClusterInfo *cluster, bool live_check)
247228
pg_fatal("%d: controldata retrieval problem\n", __LINE__);
248229

249230
p++; /* remove ':' char */
250-
cluster->controldata.chkpnt_oldstMulti = str2uint(p);
231+
cluster->controldata.chkpnt_oldstMulti = str2uint64(p);
251232
got_oldestmulti = true;
252233
}
253234
else if ((p = strstr(bufin, "Latest checkpoint's NextMultiOffset:")) != NULL)
@@ -258,7 +239,7 @@ get_control_data(ClusterInfo *cluster, bool live_check)
258239
pg_fatal("%d: controldata retrieval problem\n", __LINE__);
259240

260241
p++; /* remove ':' char */
261-
cluster->controldata.chkpnt_nxtmxoff = str2uint(p);
242+
cluster->controldata.chkpnt_nxtmxoff = str2uint64(p);
262243
got_mxoff = true;
263244
}
264245
else if ((p = strstr(bufin, "First log segment after reset:")) != NULL)

src/bin/pg_upgrade/pg_upgrade.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,18 @@ copy_clog_xlog_xid(void)
407407
/* set the next transaction id and epoch of the new cluster */
408408
prep_status("Setting next transaction ID and epoch for new cluster");
409409
exec_prog(UTILITY_LOG_FILE, NULL, true,
410-
"\"%s/pg_resetxlog\" -f -x %u \"%s\"",
410+
"\"%s/pg_resetxlog\" -f -x " XID_FMT " \"%s\"",
411411
new_cluster.bindir, old_cluster.controldata.chkpnt_nxtxid,
412412
new_cluster.pgdata);
413+
#ifdef NOT_USED
413414
exec_prog(UTILITY_LOG_FILE, NULL, true,
414415
"\"%s/pg_resetxlog\" -f -e %u \"%s\"",
415416
new_cluster.bindir, old_cluster.controldata.chkpnt_nxtepoch,
416417
new_cluster.pgdata);
418+
#endif
417419
/* must reset commit timestamp limits also */
418420
exec_prog(UTILITY_LOG_FILE, NULL, true,
419-
"\"%s/pg_resetxlog\" -f -c %u,%u \"%s\"",
421+
"\"%s/pg_resetxlog\" -f -c " XID_FMT "," XID_FMT " \"%s\"",
420422
new_cluster.bindir,
421423
old_cluster.controldata.chkpnt_nxtxid,
422424
old_cluster.controldata.chkpnt_nxtxid,
@@ -442,7 +444,7 @@ copy_clog_xlog_xid(void)
442444
* counters here and the oldest multi present on system.
443445
*/
444446
exec_prog(UTILITY_LOG_FILE, NULL, true,
445-
"\"%s/pg_resetxlog\" -O %u -m %u,%u \"%s\"",
447+
"\"%s/pg_resetxlog\" -O " XID_FMT " -m " XID_FMT "," XID_FMT " \"%s\"",
446448
new_cluster.bindir,
447449
old_cluster.controldata.chkpnt_nxtmxoff,
448450
old_cluster.controldata.chkpnt_nxtmulti,
@@ -470,7 +472,7 @@ copy_clog_xlog_xid(void)
470472
* next=MaxMultiXactId, but multixact.c can cope with that just fine.
471473
*/
472474
exec_prog(UTILITY_LOG_FILE, NULL, true,
473-
"\"%s/pg_resetxlog\" -m %u,%u \"%s\"",
475+
"\"%s/pg_resetxlog\" -m " XID_FMT "," XID_FMT " \"%s\"",
474476
new_cluster.bindir,
475477
old_cluster.controldata.chkpnt_nxtmulti + 1,
476478
old_cluster.controldata.chkpnt_nxtmulti,
@@ -521,13 +523,13 @@ set_frozenxids(bool minmxid_only)
521523
/* set pg_database.datfrozenxid */
522524
PQclear(executeQueryOrDie(conn_template1,
523525
"UPDATE pg_catalog.pg_database "
524-
"SET datfrozenxid = '%u'",
526+
"SET datfrozenxid = '" XID_FMT "'",
525527
old_cluster.controldata.chkpnt_nxtxid));
526528

527529
/* set pg_database.datminmxid */
528530
PQclear(executeQueryOrDie(conn_template1,
529531
"UPDATE pg_catalog.pg_database "
530-
"SET datminmxid = '%u'",
532+
"SET datminmxid = '" XID_FMT "'",
531533
old_cluster.controldata.chkpnt_nxtmulti));
532534

533535
/* get database names */
@@ -562,15 +564,15 @@ set_frozenxids(bool minmxid_only)
562564
/* set pg_class.relfrozenxid */
563565
PQclear(executeQueryOrDie(conn,
564566
"UPDATE pg_catalog.pg_class "
565-
"SET relfrozenxid = '%u' "
567+
"SET relfrozenxid = '" XID_FMT "' "
566568
/* only heap, materialized view, and TOAST are vacuumed */
567569
"WHERE relkind IN ('r', 'm', 't')",
568570
old_cluster.controldata.chkpnt_nxtxid));
569571

570572
/* set pg_class.relminmxid */
571573
PQclear(executeQueryOrDie(conn,
572574
"UPDATE pg_catalog.pg_class "
573-
"SET relminmxid = '%u' "
575+
"SET relminmxid = '" XID_FMT "' "
574576
/* only heap, materialized view, and TOAST are vacuumed */
575577
"WHERE relkind IN ('r', 'm', 't')",
576578
old_cluster.controldata.chkpnt_nxtmulti));

src/bin/pg_upgrade/pg_upgrade.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,11 @@ typedef struct
209209
uint32 ctrl_ver;
210210
uint32 cat_ver;
211211
char nextxlogfile[25];
212-
uint32 chkpnt_nxtxid;
213-
uint32 chkpnt_nxtepoch;
212+
uint64 chkpnt_nxtxid;
214213
uint32 chkpnt_nxtoid;
215-
uint32 chkpnt_nxtmulti;
216-
uint32 chkpnt_nxtmxoff;
217-
uint32 chkpnt_oldstMulti;
214+
uint64 chkpnt_nxtmulti;
215+
uint64 chkpnt_nxtmxoff;
216+
uint64 chkpnt_oldstMulti;
218217
uint32 align;
219218
uint32 blocksz;
220219
uint32 largesz;
@@ -433,6 +432,7 @@ void prep_status(const char *fmt,...) pg_attribute_printf(1, 2);
433432
void check_ok(void);
434433
const char *getErrorText(void);
435434
unsigned int str2uint(const char *str);
435+
uint64 str2uint64(const char *str);
436436
void pg_putenv(const char *var, const char *val);
437437

438438

src/bin/pg_upgrade/util.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,18 @@ str2uint(const char *str)
259259
}
260260

261261

262+
/*
263+
* str2uint64()
264+
*
265+
* convert string to 64-bit unsigned int
266+
*/
267+
uint64
268+
str2uint64(const char *str)
269+
{
270+
return strtouq(str, NULL, 10);
271+
}
272+
273+
262274
/*
263275
* pg_putenv()
264276
*

0 commit comments

Comments
 (0)