PostgreSQL 13: support "wal_keep_size"

Renamed from "wal_keep_segments" in core commit f5dff459.
This commit is contained in:
Ian Barwick
2020-08-31 17:17:00 +09:00
parent 0630d9644e
commit 1131e3aad2
4 changed files with 39 additions and 15 deletions

View File

@@ -46,6 +46,7 @@
<para> <para>
WAL management on the primary becomes much easier as there's no need WAL management on the primary becomes much easier as there's no need
to use replication slots, and <varname>wal_keep_segments</varname> to use replication slots, and <varname>wal_keep_segments</varname>
(PostgreSQL 13 and later: <varname>wal_keep_size</varname>)
does not need to be set. does not need to be set.
</para> </para>
</listitem> </listitem>
@@ -234,7 +235,8 @@ description = "Main cluster"
that any standby connected to the primary using a replication slot will always that any standby connected to the primary using a replication slot will always
be able to retrieve the required WAL files. This removes the need to manually be able to retrieve the required WAL files. This removes the need to manually
manage WAL file retention by estimating the number of WAL files that need to manage WAL file retention by estimating the number of WAL files that need to
be maintained on the primary using <varname>wal_keep_segments</varname>. be maintained on the primary using <varname>wal_keep_segments</varname>
(PostgreSQL 13 and later: <varname>wal_keep_size</varname>).
Do however be aware that if a standby is disconnected, WAL will continue to Do however be aware that if a standby is disconnected, WAL will continue to
accumulate on the primary until either the standby reconnects or the replication accumulate on the primary until either the standby reconnects or the replication
slot is dropped. slot is dropped.

View File

@@ -270,7 +270,7 @@
<varlistentry> <varlistentry>
<term><option>wal_keep_segments</option></term> <term><option>wal_keep_segments</option> / <option>wal_keep_size</option></term>
<listitem> <listitem>
@@ -279,25 +279,36 @@
<secondary>PostgreSQL configuration</secondary> <secondary>PostgreSQL configuration</secondary>
</indexterm> </indexterm>
<indexterm>
<primary>wal_keep_size</primary>
<secondary>PostgreSQL configuration</secondary>
</indexterm>
<para> <para>
Normally there is no need to set <option>wal_keep_segments</option> (default: <literal>0</literal>), as it Normally there is no need to set <option>wal_keep_segments</option>
is <emphasis>not</emphasis> a reliable way of ensuring that all required WAL segments are available to standbys. (PostgreSQL 13 and later: <varname>wal_keep_size</varname>; default: <literal>0</literal>),
Replication slots and/or an archiving solution such as Barman are recommended to ensure standbys have a reliable as it is <emphasis>not</emphasis> a reliable way of ensuring that all required WAL
segments are available to standbys. Replication slots and/or an archiving solution
such as Barman are recommended to ensure standbys have a reliable
source of WAL segments at all times. source of WAL segments at all times.
</para> </para>
<para> <para>
The only reason ever to set <option>wal_keep_segments</option> is you have The only reason ever to set <option>wal_keep_segments</option> / <option>wal_keep_size</option>
you have configured <option>pg_basebackup_options</option> is you have you have configured <option>pg_basebackup_options</option>
in <filename>repmgr.conf</filename> to include the setting <literal>--wal-method=fetch</literal> in <filename>repmgr.conf</filename> to include the setting <literal>--wal-method=fetch</literal>
(PostgreSQL 9.6 and earlier: <literal>--xlog-method=fetch</literal>) (PostgreSQL 9.6 and earlier: <literal>--xlog-method=fetch</literal>)
<emphasis>and</emphasis> you have <emphasis>not</emphasis> set <option>restore_command</option> <emphasis>and</emphasis> you have <emphasis>not</emphasis> set <option>restore_command</option>
in <filename>repmgr.conf</filename> to fetch WAL files from a reliable source such as Barman, in <filename>repmgr.conf</filename> to fetch WAL files from a reliable source such as Barman,
in which case you'll need to set <option>wal_keep_segments</option> in which case you'll need to set <option>wal_keep_segments</option>
to a sufficiently high number to ensure that all WAL files required by the standby to a sufficiently high number to ensure that all WAL files required by the standby
are retained. However we do not recommend managing replication in this way. are retained. However we do not recommend WAL retention in this way.
</para> </para>
<para> <para>
PostgreSQL documentation: <ulink url="https://www.postgresql.org/docs/current/runtime-config-replication.html#GUC-WAL-KEEP-SEGMENTS">wal_keep_segments</ulink>. PostgreSQL documentation: <ulink url="https://www.postgresql.org/docs/current/runtime-config-replication.html#GUC-WAL-KEEP-SEGMENTS">wal_keep_segments</ulink>.
<!--
PostgreSQL documentation: <ulink url="https://www.postgresql.org/docs/current/runtime-config-replication.html#GUC-WAL-KEEP-SIZE">wal_keep_size</ulink>.
-->
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@@ -175,7 +175,10 @@
<programlisting> <programlisting>
pg_basebackup_options='--wal-method=fetch'</programlisting> pg_basebackup_options='--wal-method=fetch'</programlisting>
and ensure that <literal>wal_keep_segments</literal> is set to an appropriately high value. and ensure that <literal>wal_keep_segments</literal> (PostgreSQL 13 and later:
<literal>wal_keep_size</literal>) is set to an appropriately high value. Note
however that this is not a particularly reliable way of ensuring sufficient
WAL is retained and is not recommended.
See the <ulink url="https://www.postgresql.org/docs/current/app-pgbasebackup.html"> See the <ulink url="https://www.postgresql.org/docs/current/app-pgbasebackup.html">
pg_basebackup</ulink> documentation for details. pg_basebackup</ulink> documentation for details.
</para> </para>

View File

@@ -6068,7 +6068,7 @@ check_upstream_config(PGconn *conn, int server_version_num, t_node_info *upstrea
} }
/* /*
* physical replication slots not available or not requested - check if * physical replication slots not available or not requested - check if
* there are any circumstances where `wal_keep_segments` should be set * there are any circumstances where "wal_keep_segments" should be set
*/ */
else if (mode != barman) else if (mode != barman)
{ {
@@ -6087,14 +6087,19 @@ check_upstream_config(PGconn *conn, int server_version_num, t_node_info *upstrea
if (check_wal_keep_segments == true) if (check_wal_keep_segments == true)
{ {
const char *wal_keep_parameter_name = "wal_keep_size";
pg_setting_ok = get_pg_setting_int(conn, "wal_keep_segments", &i); if (PQserverVersion(conn) < 130000)
wal_keep_parameter_name = "wal_keep_segments";
pg_setting_ok = get_pg_setting_int(conn, wal_keep_parameter_name, &i);
if (pg_setting_ok == false || i < 1) if (pg_setting_ok == false || i < 1)
{ {
if (pg_setting_ok == true) if (pg_setting_ok == true)
{ {
log_error(_("parameter \"wal_keep_segments\" on the upstream server must be be set to a non-zero value")); log_error(_("parameter \"%s\" on the upstream server must be be set to a non-zero value"),
wal_keep_parameter_name);
log_hint(_("Choose a value sufficiently high enough to retain enough WAL " log_hint(_("Choose a value sufficiently high enough to retain enough WAL "
"until the standby has been cloned and started.\n " "until the standby has been cloned and started.\n "
"Alternatively set up WAL archiving using e.g. PgBarman and configure " "Alternatively set up WAL archiving using e.g. PgBarman and configure "
@@ -6103,8 +6108,9 @@ check_upstream_config(PGconn *conn, int server_version_num, t_node_info *upstrea
if (server_version_num >= 90400) if (server_version_num >= 90400)
{ {
log_hint(_("In PostgreSQL 9.4 and later, replication slots can be used, which " log_hint(_("In PostgreSQL 9.4 and later, replication slots can be used, which "
"do not require \"wal_keep_segments\" to be set " "do not require \"%s\" to be set "
"(set parameter \"use_replication_slots\" in repmgr.conf to enable)\n")); "(set parameter \"use_replication_slots\" in repmgr.conf to enable)\n"),
wal_keep_parameter_name);
} }
} }
@@ -6119,7 +6125,9 @@ check_upstream_config(PGconn *conn, int server_version_num, t_node_info *upstrea
if (pg_setting_ok == true && i > 0 && runtime_options.dry_run == true) if (pg_setting_ok == true && i > 0 && runtime_options.dry_run == true)
{ {
log_info(_("parameter \"wal_keep_segments\" set to %i"), i); log_info(_("parameter \"%s\" set to %i"),
wal_keep_parameter_name,
i);
} }
} }
} }