Per some discussions with a number of different people at pgconfeu, here is a patch that changes the default mode of pg_basebackup to be streaming the wal, as this is what most users would want -- and those that don't want it have to make other changes as well. Doing the "most safe" thing by default is a good idea.
The new option "-x none" is provided to turn this off and get the previous behavior back. I will add this to the next (January) commitfest. //Magnus -- Magnus Hagander Me: http://www.hagander.net/ Work: http://www.redpill-linpro.com/
diff --git a/doc/src/sgml/ref/pg_basebackup.sgml b/doc/src/sgml/ref/pg_basebackup.sgml index 1f15a17..0db0ffb 100644 --- a/doc/src/sgml/ref/pg_basebackup.sgml +++ b/doc/src/sgml/ref/pg_basebackup.sgml @@ -302,10 +302,10 @@ PostgreSQL documentation <para> Includes the required transaction log files (WAL files) in the backup. This will include all transaction logs generated during - the backup. If this option is specified, it is possible to start - a postmaster directly in the extracted directory without the need - to consult the log archive, thus making this a completely standalone - backup. + the backup. Unless the option <literal>none</literal> is specified, + it is possible to start a postmaster directly in the extracted + directory without the need to consult the log archive, thus + making this a completely standalone backup. </para> <para> The following methods for collecting the transaction logs are @@ -313,6 +313,16 @@ PostgreSQL documentation <variablelist> <varlistentry> + <term><literal>n</literal></term> + <term><literal>none</literal></term> + <listitem> + <para> + Don't include transaction log in the backup. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><literal>f</literal></term> <term><literal>fetch</literal></term> <listitem> @@ -349,6 +359,9 @@ PostgreSQL documentation named <filename>pg_wal.tar</filename> (if the server is a version earlier than 10, the file will be named <filename>pg_xlog.tar</filename>). </para> + <para> + This value is the default. + </para> </listitem> </varlistentry> </variablelist> diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index e2875df..7e294d8 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -71,8 +71,9 @@ static bool noclean = false; static bool showprogress = false; static int verbose = 0; static int compresslevel = 0; -static bool includewal = false; -static bool streamwal = false; +static bool includewal = true; +static bool streamwal = true; +static bool set_walmode = false; static bool fastcheckpoint = false; static bool writerecoveryconf = false; static bool do_sync = true; @@ -326,7 +327,7 @@ usage(void) printf(_(" -T, --tablespace-mapping=OLDDIR=NEWDIR\n" " relocate tablespace in OLDDIR to NEWDIR\n")); printf(_(" -x, --xlog include required WAL files in backup (fetch mode)\n")); - printf(_(" -X, --xlog-method=fetch|stream\n" + printf(_(" -X, --xlog-method=none|fetch|stream\n" " include required WAL files with specified method\n")); printf(_(" --xlogdir=XLOGDIR location for the transaction log directory\n")); printf(_(" -z, --gzip compress tar output\n")); @@ -1700,7 +1701,11 @@ BaseBackup(void) */ if (streamwal && !CheckServerVersionForStreaming(conn)) { - /* Error message already written in CheckServerVersionForStreaming() */ + /* + * Error message already written in CheckServerVersionForStreaming(), + * but add a hint about using -X none. + */ + fprintf(stderr, _("HINT: use -X none or -X fetch to disable log streaming\n")); disconnect_and_exit(1); } @@ -2112,7 +2117,7 @@ main(int argc, char **argv) tablespace_list_append(optarg); break; case 'x': - if (includewal) + if (set_walmode) { fprintf(stderr, _("%s: cannot specify both --xlog and --xlog-method\n"), @@ -2120,11 +2125,12 @@ main(int argc, char **argv) exit(1); } + set_walmode = true; includewal = true; streamwal = false; break; case 'X': - if (includewal) + if (set_walmode) { fprintf(stderr, _("%s: cannot specify both --xlog and --xlog-method\n"), @@ -2132,13 +2138,30 @@ main(int argc, char **argv) exit(1); } - includewal = true; - if (strcmp(optarg, "f") == 0 || + /* + * Indicate that this has been configured, so we can complain + * if it's configured more than once. + */ + set_walmode = true; + + if (strcmp(optarg, "n") == 0 || + strcmp(optarg, "none") == 0) + { + includewal = false; + streamwal = false; + } + else if (strcmp(optarg, "f") == 0 || strcmp(optarg, "fetch") == 0) + { + includewal = true; streamwal = false; + } else if (strcmp(optarg, "s") == 0 || strcmp(optarg, "stream") == 0) + { + includewal = true; streamwal = true; + } else { fprintf(stderr, diff --git a/src/bin/pg_basebackup/t/010_pg_basebackup.pl b/src/bin/pg_basebackup/t/010_pg_basebackup.pl index 7811093..4c6670c 100644 --- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl +++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl @@ -4,7 +4,7 @@ use Cwd; use Config; use PostgresNode; use TestLib; -use Test::More tests => 69; +use Test::More tests => 71; program_help_ok('pg_basebackup'); program_version_ok('pg_basebackup'); @@ -63,7 +63,7 @@ foreach my $filename (qw(backup_label tablespace_map postgresql.auto.conf.tmp)) close FILE; } -$node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backup" ], +$node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backup", '-X', 'none' ], 'pg_basebackup runs'); ok(-f "$tempdir/backup/PG_VERSION", 'backup was created'); @@ -225,6 +225,11 @@ like( qr/^primary_conninfo = '.*port=$port.*'\n/m, 'recovery.conf sets primary_conninfo'); +$node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backupxd" ], + 'pg_basebackup runs in default xlog mode'); +ok(grep(/^[0-9A-F]{24}$/, slurp_dir("$tempdir/backupxd/pg_wal")), + 'WAL files copied'); + $node->command_ok( [ 'pg_basebackup', '-D', "$tempdir/backupxf", '-X', 'fetch' ], 'pg_basebackup -X fetch runs');
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers