Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
pg_upgrade: preserve the timestamp epoch
authorBruce Momjian <bruce@momjian.us>
Fri, 5 Sep 2014 23:19:41 +0000 (19:19 -0400)
committerBruce Momjian <bruce@momjian.us>
Fri, 5 Sep 2014 23:19:41 +0000 (19:19 -0400)
This is useful for replication tools like Slony and Skytools.

Report by Sergey Konoplev

contrib/pg_upgrade/controldata.c
contrib/pg_upgrade/pg_upgrade.c
contrib/pg_upgrade/pg_upgrade.h
doc/src/sgml/ref/pg_resetxlog.sgml

index cce44ba783770ce29e94a3ab8dd2e312cf1ee413..9282b8e88e66d8303008072c912e7fa827aa62d0 100644 (file)
@@ -209,16 +209,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_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_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 b6f370f1d2c859303a8336de7e8da8dbc0852133..3b8241b37e2e897b34508bafb0da3fad341c5cc2 100644 (file)
@@ -420,12 +420,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 4b8facf5ce73ba1ef5321766514567566ce07ba1..1ac3394956940286e91a805fa9fb62aae45ade77 100644 (file)
@@ -190,6 +190,7 @@ typedef struct
    char        nextxlogfile[25];
    uint32      chkpnt_tli;
    uint32      chkpnt_nxtxid;
+   uint32      chkpnt_nxtepoch;
    uint32      chkpnt_nxtoid;
    uint32      chkpnt_nxtmulti;
    uint32      chkpnt_nxtmxoff;
index 34b06069556da6d41e30994172c8320d563c88c5..0b53bd68595a471e0723521c93fd95d2495e8413 100644 (file)
@@ -166,7 +166,8 @@ PostgreSQL documentation
       except in the field that is set by <command>pg_resetxlog</command>,
       so any value will work so far as the database itself is concerned.
       You might need to adjust this value to ensure that replication
-      systems such as <application>Slony-I</> work correctly &mdash;
+      systems such as <application>Slony-I</> and
+      <application>Skytools</> work correctly &mdash;
       if so, an appropriate value should be obtainable from the state of
       the downstream replicated database.
      </para>