standby clone: honour --waldir setting when cloning from Barman

By setting --waldir in "pg_basebackup_options", standbys cloned using
pg_basebackup would have their WAL directory set to the specified
location and symlinked from the data directory.

This commit causes repmgr to honour that setting even when cloning
from Barman.
This commit is contained in:
Ian Barwick
2020-10-07 15:09:56 +09:00
parent b3b9281253
commit 4b524c52b6
7 changed files with 87 additions and 2 deletions

View File

@@ -5,6 +5,8 @@
repmgr: "primary unregister --force" will unregister an active primary
with no registered standby nodes (Ian)
repmgr: add option --verify-backup to "standby clone" (Ian)
repmgr: "standby clone" honours --waldir option if set in
"pg_basebackup_options" (Ian)
repmgr: add option --db-connection to "node check" (Ian)
repmgr: report database connection error if the --optformat option was
provided to "node check" (Ian)

View File

@@ -350,6 +350,9 @@
and earlier) with the absolute path to the WAL directory in <varname>pg_basebackup_options</varname>.
For more details see <xref linkend="cloning-advanced-pg-basebackup-options"/>.
</para>
<para>
In &repmgr; 5.2 and later, this setting will also be honoured when cloning from Barman.
</para>
</sect2>
<sect2 id="faq-repmgr-events-no-fkey" xreflabel="No foreign key on node_id in repmgr.events">

View File

@@ -82,6 +82,18 @@
</para>
</listitem>
<listitem>
<para>
<link linkend="repmgr-standby-clone">repmgr standby clone</link>:
when cloning from Barman, setting <option>--waldir</option>
(PostgreSQL 9.6 and earlier: <option>--xlogdir</option>) in
<option>pg_basebackup_options</option> will cause &repmgr; to create
a WAL directory outside of the main data directory and symlink
it from there, in the same way as would happen when cloning
using <application>pg_basebackup</application>.
</para>
</listitem>
<listitem>
<para>
<link linkend="repmgr-standby-follow">repmgr standby follow</link>:

View File

@@ -148,6 +148,15 @@ description = "Main cluster"
section in <command>man 5 ssh_config</command> for more details.
</simpara>
</tip>
<para>
If you wish to place WAL files in a location outside the main
PostgreSQL data directory, set <option>--waldir</option>
(PostgreSQL 9.6 and earlier: <option>--xlogdir</option>) in
<option>pg_basebackup_options</option> to the target directory
(must be an absolute filepath). &repmgr; will create and
symlink to this directory in exactly the same way
<application>pg_basebackup</application> would.
</para>
<para>
It's now possible to clone a standby from Barman, e.g.:
<programlisting>
@@ -440,6 +449,13 @@ description = "Main cluster"
WAL directory. Any WALs generated during the cloning process will be copied here, and
a symlink will automatically be created from the main data directory.
</para>
<tip>
<para>
The <literal>--waldir</literal> (<literal>--xlogdir</literal>) option,
if present in <varname>pg_basebackup_options</varname>, will be honoured by &repmgr;
when cloning from Barman (&repmgr; 5.2 and later).
</para>
</tip>
<para>
See the <ulink url="https://www.postgresql.org/docs/current/app-pgbasebackup.html">PostgreSQL pg_basebackup documentation</ulink>
for more details of available options.

View File

@@ -191,6 +191,25 @@
</note>
</refsect1>
<refsect1 id="repmgr-standby-clone-wal-directory">
<title>Placing WAL files into a different directory</title>
<para>
To ensure that WAL files are placed in a directory outside of the main data
directory (e.g. to keep them on a separate disk for performance reasons),
specify the location with <option>--waldir</option>
(PostgreSQL 9.6 and earlier: <option>--xlogdir</option>) in
the <filename>repmgr.conf</filename> parameter <option>pg_basebackup_options</option>,
e.g.:
<programlisting>
pg_basebackup_options='--waldir=/path/to/wal-directory'</programlisting>
This setting will also be honored by &repmgr; when cloning from Barman
(&repmgr; 5.2 and later).
</para>
</refsect1>
<!-- don't rename this id as it may be used in external links -->
<refsect1 id="repmgr-standby-create-recovery-conf">

View File

@@ -6941,9 +6941,20 @@ run_file_backup(t_node_info *local_node_record)
/* For the foreseeable future, no other modes are supported */
Assert(mode == barman);
if (mode == barman)
{
t_basebackup_options backup_options = T_BASEBACKUP_OPTIONS_INITIALIZER;
Assert(source_server_version_num != UNKNOWN_SERVER_VERSION_NUM);
/*
* Parse the pg_basebackup_options provided in repmgr.conf - we need to
* check if --waldir/--xlogdir was provided.
*/
parse_pg_basebackup_options(config_file_options.pg_basebackup_options,
&backup_options,
source_server_version_num,
NULL);
/*
* Locate Barman's base backups directory
*/
@@ -7203,11 +7214,31 @@ run_file_backup(t_node_info *local_node_record)
if (vers[i] < 0 && source_server_version_num >= abs(vers[i]))
continue;
maxlen_snprintf(filename, "%s/%s", local_data_directory, dirs[i]);
/*
* If --waldir/--xlogdir specified in "pg_basebackup_options",
* create a symlink rather than make a directory.
*/
maxlen_snprintf(filename, "%s/%s", local_data_directory, dirs[i]);
if (strcmp(dirs[i], "pg_wal") == 0 || strcmp(dirs[i], "pg_xlog") == 0)
{
if (backup_options.waldir[0] != '\0')
{
if (create_pg_dir(backup_options.waldir, false) == false)
{
/* create_pg_dir() will log any errors */
exit(ERR_BAD_CONFIG);
}
if (symlink(backup_options.waldir, filename) != 0)
{
log_error(_("could not create symbolic link \"%s\""), filename);
exit(ERR_BAD_CONFIG);
}
continue;
}
}
if (mkdir(filename, S_IRWXU) != 0 && errno != EEXIST)
{
log_error(_("unable to create the %s directory"), dirs[i]);

View File

@@ -181,6 +181,8 @@
#pg_ctl_options='' # Options to append to "pg_ctl"
#pg_basebackup_options='' # Options to append to "pg_basebackup"
# (Note: when cloning from Barman, repmgr will honour any
# --waldir/--xlogdir setting present in "pg_basebackup_options"
#rsync_options='' # Options to append to "rsync"
ssh_options='-q -o ConnectTimeout=10' # Options to append to "ssh"