Skip to content

Commit 8a00b96

Browse files
committed
Add pg_rewind --no-sync
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
1 parent 9a4059d commit 8a00b96

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

doc/src/sgml/ref/pg_rewind.sgml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@ PostgreSQL documentation
171171
</listitem>
172172
</varlistentry>
173173

174+
<varlistentry>
175+
<term><option>-N</option></term>
176+
<term><option>--no-sync</option></term>
177+
<listitem>
178+
<para>
179+
By default, <command>pg_rewind</command> will wait for all files
180+
to be written safely to disk. This option causes
181+
<command>pg_rewind</command> to return without waiting, which is
182+
faster, but means that a subsequent operating system crash can leave
183+
the synchronized data folder corrupt. Generally, this option is
184+
useful for testing but should not be used when creating a production
185+
installation.
186+
</para>
187+
</listitem>
188+
</varlistentry>
189+
174190
<varlistentry>
175191
<term><option>-P</option></term>
176192
<term><option>--progress</option></term>

src/bin/pg_rewind/RewindTest.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ sub run_pg_rewind
231231
'pg_rewind',
232232
"--debug",
233233
"--source-pgdata=$standby_pgdata",
234-
"--target-pgdata=$master_pgdata"
234+
"--target-pgdata=$master_pgdata",
235+
"--no-sync"
235236
],
236237
'pg_rewind local');
237238
}
@@ -243,7 +244,8 @@ sub run_pg_rewind
243244
[
244245
'pg_rewind', "--debug",
245246
"--source-server", $standby_connstr,
246-
"--target-pgdata=$master_pgdata"
247+
"--target-pgdata=$master_pgdata",
248+
"--no-sync"
247249
],
248250
'pg_rewind remote');
249251
}

src/bin/pg_rewind/pg_rewind.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ char *connstr_source = NULL;
5656
bool debug = false;
5757
bool showprogress = false;
5858
bool dry_run = false;
59+
bool do_sync = true;
5960

6061
/* Target history */
6162
TimeLineHistoryEntry *targetHistory;
@@ -71,6 +72,8 @@ usage(const char *progname)
7172
printf(_(" --source-pgdata=DIRECTORY source data directory to synchronize with\n"));
7273
printf(_(" --source-server=CONNSTR source server to synchronize with\n"));
7374
printf(_(" -n, --dry-run stop before modifying anything\n"));
75+
printf(_(" -N, --no-sync do not wait for changes to be written\n"));
76+
printf(_(" safely to disk\n"));
7477
printf(_(" -P, --progress write progress messages\n"));
7578
printf(_(" --debug write a lot of debug messages\n"));
7679
printf(_(" -V, --version output version information, then exit\n"));
@@ -89,6 +92,7 @@ main(int argc, char **argv)
8992
{"source-server", required_argument, NULL, 2},
9093
{"version", no_argument, NULL, 'V'},
9194
{"dry-run", no_argument, NULL, 'n'},
95+
{"no-sync", no_argument, NULL, 'N'},
9296
{"progress", no_argument, NULL, 'P'},
9397
{"debug", no_argument, NULL, 3},
9498
{NULL, 0, NULL, 0}
@@ -125,7 +129,7 @@ main(int argc, char **argv)
125129
}
126130
}
127131

128-
while ((c = getopt_long(argc, argv, "D:nP", long_options, &option_index)) != -1)
132+
while ((c = getopt_long(argc, argv, "D:nNP", long_options, &option_index)) != -1)
129133
{
130134
switch (c)
131135
{
@@ -141,6 +145,10 @@ main(int argc, char **argv)
141145
dry_run = true;
142146
break;
143147

148+
case 'N':
149+
do_sync = false;
150+
break;
151+
144152
case 3:
145153
debug = true;
146154
break;
@@ -709,7 +717,7 @@ updateControlFile(ControlFileData *ControlFile)
709717
static void
710718
syncTargetDirectory(const char *argv0)
711719
{
712-
if (dry_run)
720+
if (!do_sync || dry_run)
713721
return;
714722

715723
fsync_pgdata(datadir_target, progname, PG_VERSION_NUM);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy