pg_upgrade: preserve the timestamp epoch
authorBruce Momjian <bruce@momjian.us>
Thu, 11 Sep 2014 22:39:46 +0000 (18:39 -0400)
committerBruce Momjian <bruce@momjian.us>
Thu, 11 Sep 2014 22:39:46 +0000 (18:39 -0400)
This is useful for replication tools like Slony and Skytools.  This is a
backpatch of a74a4aa23bb95b590ff01ee564219d2eacea3706.

Report by Sergey Konoplev

Backpatch through 9.3

contrib/pg_upgrade/controldata.c
contrib/pg_upgrade/pg_upgrade.c
contrib/pg_upgrade/pg_upgrade.h

index 275aeb37907fc6dd5cd0e61808fe73cf1ed12f55..b0da994c14114f9dad46b0536ddf7995e06a95b4 100644 (file)
@@ -234,16 +234,20 @@ get_control_data(ClusterInfo *cluster, bool live_check)
        }
        else if ((p = strstr(bufin, "Latest checkpoint's NextXID:")) != NULL)
        {
-           char       *op = strchr(p, '/');
+           p = strchr(p, ':');
+
+           if (p == NULL || strlen(p) <= 1)
+               pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
 
-           if (op == NULL)
-               op = strchr(p, ':');
+           p++;                /* removing ':' char */
+           cluster->controldata.chkpnt_nxtepoch = str2uint(p);
 
-           if (op == NULL || strlen(op) <= 1)
+           p = strchr(p, '/');
+           if (p == NULL || strlen(p) <= 1)
                pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
 
-           op++;               /* removing ':' char */
-           cluster->controldata.chkpnt_nxtxid = str2uint(op);
+           p++;                /* removing '/' char */
+           cluster->controldata.chkpnt_nxtxid = str2uint(p);
            got_xid = true;
        }
        else if ((p = strstr(bufin, "Latest checkpoint's NextOID:")) != NULL)
index 1fc9d903e1c4c8ef2cdc14acb27ee08552692846..d7d88644953d35e0db1e87c652a60bd810359969 100644 (file)
@@ -423,12 +423,16 @@ copy_clog_xlog_xid(void)
    /* copy old commit logs to new data dir */
    copy_subdir_files("pg_clog");
 
-   /* set the next transaction id of the new cluster */
-   prep_status("Setting next transaction ID for new cluster");
+   /* set the next transaction id and epoch of the new cluster */
+   prep_status("Setting next transaction ID and epoch for new cluster");
    exec_prog(UTILITY_LOG_FILE, NULL, true,
              "\"%s/pg_resetxlog\" -f -x %u \"%s\"",
              new_cluster.bindir, old_cluster.controldata.chkpnt_nxtxid,
              new_cluster.pgdata);
+   exec_prog(UTILITY_LOG_FILE, NULL, true,
+             "\"%s/pg_resetxlog\" -f -e %u \"%s\"",
+             new_cluster.bindir, old_cluster.controldata.chkpnt_nxtepoch,
+             new_cluster.pgdata);
    check_ok();
 
    /*
index 38d37a6c63f3c1c5784a83f51f86b05577a1ac25..f50388fedbd70a40ceefcc98de37efc27b61fe37 100644 (file)
@@ -188,6 +188,7 @@ typedef struct
    char        nextxlogfile[25];
    uint32      chkpnt_tli;
    uint32      chkpnt_nxtxid;
+   uint32      chkpnt_nxtepoch;
    uint32      chkpnt_nxtoid;
    uint32      chkpnt_nxtmulti;
    uint32      chkpnt_nxtmxoff;