1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-17 17:02:08 +03:00

Hot Standby feedback for avoidance of cleanup conflicts on standby.

Standby optionally sends back information about oldestXmin of queries
which is then checked and applied to the WALSender's proc->xmin.
GetOldestXmin() is modified slightly to agree with GetSnapshotData(),
so that all backends on primary include WALSender within their snapshots.
Note this does nothing to change the snapshot xmin on either master or
standby. Feedback piggybacks on the standby reply message.
vacuum_defer_cleanup_age is no longer used on standby, though parameter
still exists on primary, since some use cases still exist.

Simon Riggs, review comments from Fujii Masao, Heikki Linnakangas, Robert Haas
This commit is contained in:
Simon Riggs
2011-02-16 19:29:37 +00:00
parent 65076269ea
commit bca8b7f16a
11 changed files with 245 additions and 50 deletions

View File

@ -2006,6 +2006,10 @@ SET ENABLE_SEQSCAN TO OFF;
This parameter can only be set in the <filename>postgresql.conf</>
file or on the server command line.
</para>
<para>
You should also consider setting <varname>hot_standby_feedback</>
as an alternative to using this parameter.
</para>
</listitem>
</varlistentry>
</variablelist>
@ -2121,6 +2125,22 @@ SET ENABLE_SEQSCAN TO OFF;
</listitem>
</varlistentry>
<varlistentry id="guc-hot-standby-feedback" xreflabel="hot_standby">
<term><varname>hot_standby_feedback</varname> (<type>boolean</type>)</term>
<indexterm>
<primary><varname>hot_standby_feedback</> configuration parameter</primary>
</indexterm>
<listitem>
<para>
Specifies whether or not a hot standby will send feedback to the primary
about queries currently executing on the standby. This parameter can
be used to eliminate query cancels caused by cleanup records, though
it can cause database bloat on the primary for some workloads.
The default value is <literal>off</literal>.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
</sect1>

View File

@ -1483,23 +1483,6 @@ if (!triggered)
on the primary, if it delays application of WAL records.
</para>
<para>
The most common reason for conflict between standby queries and WAL replay
is <quote>early cleanup</>. Normally, <productname>PostgreSQL</> allows
cleanup of old row versions when there are no transactions that need to
see them to ensure correct visibility of data according to MVCC rules.
However, this rule can only be applied for transactions executing on the
master. So it is possible that cleanup on the master will remove row
versions that are still visible to a transaction on the standby.
</para>
<para>
Experienced users should note that both row version cleanup and row version
freezing will potentially conflict with standby queries. Running a manual
<command>VACUUM FREEZE</> is likely to cause conflicts even on tables with
no updated or deleted rows.
</para>
<para>
Once the delay specified by <varname>max_standby_archive_delay</> or
<varname>max_standby_streaming_delay</> has been exceeded, conflicting
@ -1526,6 +1509,23 @@ if (!triggered)
as a result of being unable to keep up with a heavy update load.
</para>
<para>
The most common reason for conflict between standby queries and WAL replay
is <quote>early cleanup</>. Normally, <productname>PostgreSQL</> allows
cleanup of old row versions when there are no transactions that need to
see them to ensure correct visibility of data according to MVCC rules.
However, this rule can only be applied for transactions executing on the
master. So it is possible that cleanup on the master will remove row
versions that are still visible to a transaction on the standby.
</para>
<para>
Experienced users should note that both row version cleanup and row version
freezing will potentially conflict with standby queries. Running a manual
<command>VACUUM FREEZE</> is likely to cause conflicts even on tables with
no updated or deleted rows.
</para>
<para>
Users should be clear that tables that are regularly and heavily updated
on the primary server will quickly cause cancellation of longer running
@ -1537,12 +1537,10 @@ if (!triggered)
<para>
Remedial possibilities exist if the number of standby-query cancellations
is found to be unacceptable. The first option is to connect to the
primary server and keep a query active for as long as needed to
run queries on the standby. This prevents <command>VACUUM</> from removing
recently-dead rows and so cleanup conflicts do not occur.
This could be done using <xref linkend="dblink"> and
<function>pg_sleep()</>, or via other mechanisms. If you do this, you
is found to be unacceptable. The first option is to set the parameter
<varname>hot_standby_feedback</>, which prevents <command>VACUUM</> from
removing recently-dead rows and so cleanup conflicts do not occur.
If you do this, you
should note that this will delay cleanup of dead rows on the primary,
which may result in undesirable table bloat. However, the cleanup
situation will be no worse than if the standby queries were running