diff --git a/doc/src/sgml/ref/pg_rewind.sgml b/doc/src/sgml/ref/pg_rewind.sgml index ee35ce18b0..e2662bbf81 100644 --- a/doc/src/sgml/ref/pg_rewind.sgml +++ b/doc/src/sgml/ref/pg_rewind.sgml @@ -171,6 +171,22 @@ PostgreSQL documentation + + + + + + By default, pg_rewind will wait for all files + to be written safely to disk. This option causes + pg_rewind 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. + + + + diff --git a/src/bin/pg_rewind/RewindTest.pm b/src/bin/pg_rewind/RewindTest.pm index 057b08f9a4..1dce56d035 100644 --- a/src/bin/pg_rewind/RewindTest.pm +++ b/src/bin/pg_rewind/RewindTest.pm @@ -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'); } diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c index 441e8074b7..9653106386 100644 --- a/src/bin/pg_rewind/pg_rewind.c +++ b/src/bin/pg_rewind/pg_rewind.c @@ -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);