Skip to content

Commit 5724f49

Browse files
committed
pg_upgrade: preserve the timestamp epoch
This is useful for replication tools like Slony and Skytools. This is a backpatch of a74a4aa. Report by Sergey Konoplev Backpatch through 9.3
1 parent bca9123 commit 5724f49

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

contrib/pg_upgrade/controldata.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,20 @@ get_control_data(ClusterInfo *cluster, bool live_check)
234234
}
235235
else if ((p = strstr(bufin, "Latest checkpoint's NextXID:")) != NULL)
236236
{
237-
char *op = strchr(p, '/');
237+
p = strchr(p, ':');
238+
239+
if (p == NULL || strlen(p) <= 1)
240+
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
238241

239-
if (op == NULL)
240-
op = strchr(p, ':');
242+
p++; /* removing ':' char */
243+
cluster->controldata.chkpnt_nxtepoch = str2uint(p);
241244

242-
if (op == NULL || strlen(op) <= 1)
245+
p = strchr(p, '/');
246+
if (p == NULL || strlen(p) <= 1)
243247
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
244248

245-
op++; /* removing ':' char */
246-
cluster->controldata.chkpnt_nxtxid = str2uint(op);
249+
p++; /* removing '/' char */
250+
cluster->controldata.chkpnt_nxtxid = str2uint(p);
247251
got_xid = true;
248252
}
249253
else if ((p = strstr(bufin, "Latest checkpoint's NextOID:")) != NULL)

contrib/pg_upgrade/pg_upgrade.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,16 @@ copy_clog_xlog_xid(void)
423423
/* copy old commit logs to new data dir */
424424
copy_subdir_files("pg_clog");
425425

426-
/* set the next transaction id of the new cluster */
427-
prep_status("Setting next transaction ID for new cluster");
426+
/* set the next transaction id and epoch of the new cluster */
427+
prep_status("Setting next transaction ID and epoch for new cluster");
428428
exec_prog(UTILITY_LOG_FILE, NULL, true,
429429
"\"%s/pg_resetxlog\" -f -x %u \"%s\"",
430430
new_cluster.bindir, old_cluster.controldata.chkpnt_nxtxid,
431431
new_cluster.pgdata);
432+
exec_prog(UTILITY_LOG_FILE, NULL, true,
433+
"\"%s/pg_resetxlog\" -f -e %u \"%s\"",
434+
new_cluster.bindir, old_cluster.controldata.chkpnt_nxtepoch,
435+
new_cluster.pgdata);
432436
check_ok();
433437

434438
/*

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ typedef struct
188188
char nextxlogfile[25];
189189
uint32 chkpnt_tli;
190190
uint32 chkpnt_nxtxid;
191+
uint32 chkpnt_nxtepoch;
191192
uint32 chkpnt_nxtoid;
192193
uint32 chkpnt_nxtmulti;
193194
uint32 chkpnt_nxtmxoff;

0 commit comments

Comments
 (0)