Add pg_rewind --no-sync
authorMichael Paquier <michael@paquier.xyz>
Mon, 9 Jul 2018 23:51:10 +0000 (08:51 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 9 Jul 2018 23:51:10 +0000 (08:51 +0900)
This is an option consistent with what pg_dump and pg_basebackup provide
which is useful for leveraging the I/O effort when testing things, not
to be used in a production environment.

Author: Michael Paquier
Reviewed-by: Heikki Linnakangas
Discussion: https://postgr.es/m/20180325122607.GB3707@paquier.xyz

doc/src/sgml/ref/pg_rewind.sgml
src/bin/pg_rewind/RewindTest.pm
src/bin/pg_rewind/pg_rewind.c

index ee35ce18b08071441828e0063679462534ceaefc..e2662bbf819becd096de862be162ad0b2b0ce430 100644 (file)
@@ -171,6 +171,22 @@ PostgreSQL documentation
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>-N</option></term>
+      <term><option>--no-sync</option></term>
+      <listitem>
+       <para>
+        By default, <command>pg_rewind</command> will wait for all files
+        to be written safely to disk.  This option causes
+        <command>pg_rewind</command> to return without waiting, which is
+        faster, but means that a subsequent operating system crash can leave
+        the synchronized data folder corrupt.  Generally, this option is
+        useful for testing but should not be used when creating a production
+        installation.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>-P</option></term>
       <term><option>--progress</option></term>
index 057b08f9a49d6bb4bbcc16efd0f07ac5d5e80c36..1dce56d0352e5cdc9059d1b01aa8d915076dd8db 100644 (file)
@@ -231,7 +231,8 @@ sub run_pg_rewind
                'pg_rewind',
                "--debug",
                "--source-pgdata=$standby_pgdata",
-               "--target-pgdata=$master_pgdata"
+               "--target-pgdata=$master_pgdata",
+               "--no-sync"
            ],
            'pg_rewind local');
    }
@@ -243,7 +244,8 @@ sub run_pg_rewind
            [
                'pg_rewind',       "--debug",
                "--source-server", $standby_connstr,
-               "--target-pgdata=$master_pgdata"
+               "--target-pgdata=$master_pgdata",
+               "--no-sync"
            ],
            'pg_rewind remote');
    }
index 441e8074b708796d434ca62ecfe1f6adaafffb1e..96531063869c63b060ccdda589fdfbab58cbbb73 100644 (file)
@@ -56,6 +56,7 @@ char     *connstr_source = NULL;
 bool       debug = false;
 bool       showprogress = false;
 bool       dry_run = false;
+bool       do_sync = true;
 
 /* Target history */
 TimeLineHistoryEntry *targetHistory;
@@ -71,6 +72,8 @@ usage(const char *progname)
    printf(_("      --source-pgdata=DIRECTORY  source data directory to synchronize with\n"));
    printf(_("      --source-server=CONNSTR    source server to synchronize with\n"));
    printf(_("  -n, --dry-run                  stop before modifying anything\n"));
+   printf(_("  -N, --no-sync                  do not wait for changes to be written\n"));
+   printf(_("                                 safely to disk\n"));
    printf(_("  -P, --progress                 write progress messages\n"));
    printf(_("      --debug                    write a lot of debug messages\n"));
    printf(_("  -V, --version                  output version information, then exit\n"));
@@ -89,6 +92,7 @@ main(int argc, char **argv)
        {"source-server", required_argument, NULL, 2},
        {"version", no_argument, NULL, 'V'},
        {"dry-run", no_argument, NULL, 'n'},
+       {"no-sync", no_argument, NULL, 'N'},
        {"progress", no_argument, NULL, 'P'},
        {"debug", no_argument, NULL, 3},
        {NULL, 0, NULL, 0}
@@ -125,7 +129,7 @@ main(int argc, char **argv)
        }
    }
 
-   while ((c = getopt_long(argc, argv, "D:nP", long_options, &option_index)) != -1)
+   while ((c = getopt_long(argc, argv, "D:nNP", long_options, &option_index)) != -1)
    {
        switch (c)
        {
@@ -141,6 +145,10 @@ main(int argc, char **argv)
                dry_run = true;
                break;
 
+           case 'N':
+               do_sync = false;
+               break;
+
            case 3:
                debug = true;
                break;
@@ -709,7 +717,7 @@ updateControlFile(ControlFileData *ControlFile)
 static void
 syncTargetDirectory(const char *argv0)
 {
-   if (dry_run)
+   if (!do_sync || dry_run)
        return;
 
    fsync_pgdata(datadir_target, progname, PG_VERSION_NUM);