Skip to content

Commit 5f39712

Browse files
committed
pg_receivewal: Add --no-sync option.
Michael Paquier, reviewed by Kuntal Ghosh and by me. I did a little wordsmithing on the documentation, too. Discussion: http://postgr.es/m/CAB7nPqTuXuyEoVKcWcExh_b0uAjgWd_14KfGLrCTccBZ=VA0KA@mail.gmail.com
1 parent b7f3eb3 commit 5f39712

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

doc/src/sgml/ref/pg_receivewal.sgml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ PostgreSQL documentation
135135
</listitem>
136136
</varlistentry>
137137

138+
<varlistentry>
139+
<term><option>--no-sync</option></term>
140+
<listitem>
141+
<para>
142+
This option causes <command>pg_receivewal</command> to not force WAL
143+
data to be flushed to disk. This is faster, but means that a
144+
subsequent operating system crash can leave the WAL segments corrupt.
145+
Generally, this option is useful for testing but should not be used
146+
when doing WAL archiving on a production deployment.
147+
</para>
148+
149+
<para>
150+
This option is incompatible with <literal>--synchronous</literal>.
151+
</para>
152+
</listitem>
153+
</varlistentry>
154+
138155
<varlistentry>
139156
<term><option>-s <replaceable class="parameter">interval</replaceable></option></term>
140157
<term><option>--status-interval=<replaceable class="parameter">interval</replaceable></option></term>

src/bin/pg_basebackup/pg_receivewal.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static volatile bool time_to_stop = false;
4040
static bool do_create_slot = false;
4141
static bool slot_exists_ok = false;
4242
static bool do_drop_slot = false;
43+
static bool do_sync = true;
4344
static bool synchronous = false;
4445
static char *replication_slot = NULL;
4546
static XLogRecPtr endpos = InvalidXLogRecPtr;
@@ -81,6 +82,7 @@ usage(void)
8182
printf(_(" -E, --endpos=LSN exit after receiving the specified LSN\n"));
8283
printf(_(" --if-not-exists do not error if slot already exists when creating a slot\n"));
8384
printf(_(" -n, --no-loop do not loop on connection lost\n"));
85+
printf(_(" --no-sync do not wait for changes to be written safely to disk\n"));
8486
printf(_(" -s, --status-interval=SECS\n"
8587
" time between status packets sent to server (default: %d)\n"), (standby_message_timeout / 1000));
8688
printf(_(" -S, --slot=SLOTNAME replication slot to use\n"));
@@ -425,7 +427,7 @@ StreamLog(void)
425427
stream.stop_socket = PGINVALID_SOCKET;
426428
stream.standby_message_timeout = standby_message_timeout;
427429
stream.synchronous = synchronous;
428-
stream.do_sync = true;
430+
stream.do_sync = do_sync;
429431
stream.mark_done = false;
430432
stream.walmethod = CreateWalDirectoryMethod(basedir, compresslevel,
431433
stream.do_sync);
@@ -487,6 +489,7 @@ main(int argc, char **argv)
487489
{"drop-slot", no_argument, NULL, 2},
488490
{"if-not-exists", no_argument, NULL, 3},
489491
{"synchronous", no_argument, NULL, 4},
492+
{"no-sync", no_argument, NULL, 5},
490493
{NULL, 0, NULL, 0}
491494
};
492495

@@ -595,6 +598,9 @@ main(int argc, char **argv)
595598
case 4:
596599
synchronous = true;
597600
break;
601+
case 5:
602+
do_sync = false;
603+
break;
598604
default:
599605

600606
/*
@@ -637,6 +643,14 @@ main(int argc, char **argv)
637643
exit(1);
638644
}
639645

646+
if (synchronous && !do_sync)
647+
{
648+
fprintf(stderr, _("%s: cannot use --synchronous together with --no-sync\n"), progname);
649+
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
650+
progname);
651+
exit(1);
652+
}
653+
640654
/*
641655
* Required arguments
642656
*/

src/bin/pg_basebackup/t/020_pg_receivewal.pl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use warnings;
33
use TestLib;
44
use PostgresNode;
5-
use Test::More tests => 17;
5+
use Test::More tests => 18;
66

77
program_help_ok('pg_receivewal');
88
program_version_ok('pg_receivewal');
@@ -24,6 +24,9 @@
2424
$primary->command_fails(
2525
[ 'pg_receivewal', '-D', $stream_dir, '--create-slot' ],
2626
'failure if --create-slot specified without --slot');
27+
$primary->command_fails(
28+
[ 'pg_receivewal', '-D', $stream_dir, '--synchronous', '--no-sync' ],
29+
'failure if --synchronous specified with --no-sync');
2730

2831
# Slot creation and drop
2932
my $slot_name = 'test';

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