Skip to content

Commit 9a4d510

Browse files
committed
Make wal streaming the default mode for pg_basebackup
Since streaming is now supported for all output formats, make this the default as this is what most people want. To get the old behavior, the parameter -X none can be specified to turn it off. This also removes the parameter -x for fetch, now requiring -X fetch to be specified to use that. Reviewed by Vladimir Rusinov, Michael Paquier and Simon Riggs
1 parent 1d25779 commit 9a4d510

File tree

4 files changed

+50
-52
lines changed

4 files changed

+50
-52
lines changed

doc/src/sgml/ref/pg_basebackup.sgml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ PostgreSQL documentation
5656
and <filename>pg_hba.conf</filename> must explicitly permit the replication
5757
connection. The server must also be configured
5858
with <xref linkend="guc-max-wal-senders"> set high enough to leave at least
59-
one session available for the backup.
59+
one session available for the backup and one for WAL streaming (if used).
6060
</para>
6161

6262
<para>
@@ -85,10 +85,8 @@ PostgreSQL documentation
8585
</listitem>
8686
<listitem>
8787
<para>
88-
There is no guarantee that all WAL files required for the backup are archived
89-
at the end of backup. If you are planning to use the backup for an archive
90-
recovery and want to ensure that all required files are available at that moment,
91-
you need to include them into the backup by using the <literal>-x</> option.
88+
If you are using <literal>-X none</>, there is no guarantee that all
89+
WAL files required for the backup are archived at the end of backup.
9290
</para>
9391
</listitem>
9492
<listitem>
@@ -284,34 +282,33 @@ PostgreSQL documentation
284282
</listitem>
285283
</varlistentry>
286284

287-
<varlistentry>
288-
<term><option>-x</option></term>
289-
<term><option>--xlog</option></term>
290-
<listitem>
291-
<para>
292-
Using this option is equivalent of using <literal>-X</literal> with
293-
method <literal>fetch</literal>.
294-
</para>
295-
</listitem>
296-
</varlistentry>
297-
298285
<varlistentry>
299286
<term><option>-X <replaceable class="parameter">method</replaceable></option></term>
300287
<term><option>--xlog-method=<replaceable class="parameter">method</replaceable></option></term>
301288
<listitem>
302289
<para>
303290
Includes the required transaction log files (WAL files) in the
304291
backup. This will include all transaction logs generated during
305-
the backup. If this option is specified, it is possible to start
306-
a postmaster directly in the extracted directory without the need
307-
to consult the log archive, thus making this a completely standalone
308-
backup.
292+
the backup. Unless the method <literal>none</literal> is specified,
293+
it is possible to start a postmaster directly in the extracted
294+
directory without the need to consult the log archive, thus
295+
making this a completely standalone backup.
309296
</para>
310297
<para>
311298
The following methods for collecting the transaction logs are
312299
supported:
313300

314301
<variablelist>
302+
<varlistentry>
303+
<term><literal>n</literal></term>
304+
<term><literal>none</literal></term>
305+
<listitem>
306+
<para>
307+
Don't include transaction log in the backup.
308+
</para>
309+
</listitem>
310+
</varlistentry>
311+
315312
<varlistentry>
316313
<term><literal>f</literal></term>
317314
<term><literal>fetch</literal></term>
@@ -349,6 +346,9 @@ PostgreSQL documentation
349346
named <filename>pg_wal.tar</filename> (if the server is a version
350347
earlier than 10, the file will be named <filename>pg_xlog.tar</filename>).
351348
</para>
349+
<para>
350+
This value is the default.
351+
</para>
352352
</listitem>
353353
</varlistentry>
354354
</variablelist>
@@ -699,7 +699,7 @@ PostgreSQL documentation
699699
To create a backup of a single-tablespace local database and compress
700700
this with <productname>bzip2</productname>:
701701
<screen>
702-
<prompt>$</prompt> <userinput>pg_basebackup -D - -Ft | bzip2 &gt; backup.tar.bz2</userinput>
702+
<prompt>$</prompt> <userinput>pg_basebackup -D - -Ft -X fetch | bzip2 &gt; backup.tar.bz2</userinput>
703703
</screen>
704704
(This command will fail if there are multiple tablespaces in the
705705
database.)

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ static bool noclean = false;
7171
static bool showprogress = false;
7272
static int verbose = 0;
7373
static int compresslevel = 0;
74-
static bool includewal = false;
75-
static bool streamwal = false;
74+
static bool includewal = true;
75+
static bool streamwal = true;
7676
static bool fastcheckpoint = false;
7777
static bool writerecoveryconf = false;
7878
static bool do_sync = true;
@@ -325,8 +325,7 @@ usage(void)
325325
printf(_(" -S, --slot=SLOTNAME replication slot to use\n"));
326326
printf(_(" -T, --tablespace-mapping=OLDDIR=NEWDIR\n"
327327
" relocate tablespace in OLDDIR to NEWDIR\n"));
328-
printf(_(" -x, --xlog include required WAL files in backup (fetch mode)\n"));
329-
printf(_(" -X, --xlog-method=fetch|stream\n"
328+
printf(_(" -X, --xlog-method=none|fetch|stream\n"
330329
" include required WAL files with specified method\n"));
331330
printf(_(" --xlogdir=XLOGDIR location for the transaction log directory\n"));
332331
printf(_(" -z, --gzip compress tar output\n"));
@@ -1700,7 +1699,11 @@ BaseBackup(void)
17001699
*/
17011700
if (streamwal && !CheckServerVersionForStreaming(conn))
17021701
{
1703-
/* Error message already written in CheckServerVersionForStreaming() */
1702+
/*
1703+
* Error message already written in CheckServerVersionForStreaming(),
1704+
* but add a hint about using -X none.
1705+
*/
1706+
fprintf(stderr, _("HINT: use -X none or -X fetch to disable log streaming\n"));
17041707
disconnect_and_exit(1);
17051708
}
17061709

@@ -2035,7 +2038,6 @@ main(int argc, char **argv)
20352038
{"write-recovery-conf", no_argument, NULL, 'R'},
20362039
{"slot", required_argument, NULL, 'S'},
20372040
{"tablespace-mapping", required_argument, NULL, 'T'},
2038-
{"xlog", no_argument, NULL, 'x'},
20392041
{"xlog-method", required_argument, NULL, 'X'},
20402042
{"gzip", no_argument, NULL, 'z'},
20412043
{"compress", required_argument, NULL, 'Z'},
@@ -2078,7 +2080,7 @@ main(int argc, char **argv)
20782080

20792081
atexit(cleanup_directories_atexit);
20802082

2081-
while ((c = getopt_long(argc, argv, "D:F:r:RT:xX:l:nNzZ:d:c:h:p:U:s:S:wWvP",
2083+
while ((c = getopt_long(argc, argv, "D:F:r:RT:X:l:nNzZ:d:c:h:p:U:s:S:wWvP",
20822084
long_options, &option_index)) != -1)
20832085
{
20842086
switch (c)
@@ -2111,38 +2113,29 @@ main(int argc, char **argv)
21112113
case 'T':
21122114
tablespace_list_append(optarg);
21132115
break;
2114-
case 'x':
2115-
if (includewal)
2116-
{
2117-
fprintf(stderr,
2118-
_("%s: cannot specify both --xlog and --xlog-method\n"),
2119-
progname);
2120-
exit(1);
2121-
}
2122-
2123-
includewal = true;
2124-
streamwal = false;
2125-
break;
21262116
case 'X':
2127-
if (includewal)
2117+
if (strcmp(optarg, "n") == 0 ||
2118+
strcmp(optarg, "none") == 0)
21282119
{
2129-
fprintf(stderr,
2130-
_("%s: cannot specify both --xlog and --xlog-method\n"),
2131-
progname);
2132-
exit(1);
2120+
includewal = false;
2121+
streamwal = false;
21332122
}
2134-
2135-
includewal = true;
2136-
if (strcmp(optarg, "f") == 0 ||
2123+
else if (strcmp(optarg, "f") == 0 ||
21372124
strcmp(optarg, "fetch") == 0)
2125+
{
2126+
includewal = true;
21382127
streamwal = false;
2128+
}
21392129
else if (strcmp(optarg, "s") == 0 ||
21402130
strcmp(optarg, "stream") == 0)
2131+
{
2132+
includewal = true;
21412133
streamwal = true;
2134+
}
21422135
else
21432136
{
21442137
fprintf(stderr,
2145-
_("%s: invalid xlog-method option \"%s\", must be \"fetch\" or \"stream\"\n"),
2138+
_("%s: invalid xlog-method option \"%s\", must be \"fetch\", \"stream\" or \"none\"\n"),
21462139
progname, optarg);
21472140
exit(1);
21482141
}

src/bin/pg_basebackup/t/010_pg_basebackup.pl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use Config;
55
use PostgresNode;
66
use TestLib;
7-
use Test::More tests => 69;
7+
use Test::More tests => 71;
88

99
program_help_ok('pg_basebackup');
1010
program_version_ok('pg_basebackup');
@@ -63,7 +63,7 @@
6363
close FILE;
6464
}
6565

66-
$node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backup" ],
66+
$node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backup", '-X', 'none' ],
6767
'pg_basebackup runs');
6868
ok(-f "$tempdir/backup/PG_VERSION", 'backup was created');
6969

@@ -225,6 +225,11 @@
225225
qr/^primary_conninfo = '.*port=$port.*'\n/m,
226226
'recovery.conf sets primary_conninfo');
227227

228+
$node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backupxd" ],
229+
'pg_basebackup runs in default xlog mode');
230+
ok(grep(/^[0-9A-F]{24}$/, slurp_dir("$tempdir/backupxd/pg_wal")),
231+
'WAL files copied');
232+
228233
$node->command_ok(
229234
[ 'pg_basebackup', '-D', "$tempdir/backupxf", '-X', 'fetch' ],
230235
'pg_basebackup -X fetch runs');

src/test/perl/PostgresNode.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ sub backup
484484

485485
print "# Taking pg_basebackup $backup_name from node \"$name\"\n";
486486
TestLib::system_or_bail('pg_basebackup', '-D', $backup_path, '-p', $port,
487-
'-x', '--no-sync');
487+
'--no-sync');
488488
print "# Backup finished\n";
489489
}
490490

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