mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Add the "snapshot too old" feature
This feature is controlled by a new old_snapshot_threshold GUC. A value of -1 disables the feature, and that is the default. The value of 0 is just intended for testing. Above that it is the number of minutes a snapshot can reach before pruning and vacuum are allowed to remove dead tuples which the snapshot would otherwise protect. The xmin associated with a transaction ID does still protect dead tuples. A connection which is using an "old" snapshot does not get an error unless it accesses a page modified recently enough that it might not be able to produce accurate results. This is similar to the Oracle feature, and we use the same SQLSTATE and error message for compatibility.
This commit is contained in:
@ -2041,6 +2041,42 @@ include_dir 'conf.d'
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry id="guc-old-snapshot-threshold" xreflabel="old_snapshot_threshold">
|
||||
<term><varname>old_snapshot_threshold</varname> (<type>integer</type>)
|
||||
<indexterm>
|
||||
<primary><varname>old_snapshot_threshold</> configuration parameter</primary>
|
||||
</indexterm>
|
||||
</term>
|
||||
<listitem>
|
||||
<para>
|
||||
Sets the minimum time that a snapshot can be used without risk of a
|
||||
<literal>snapshot too old</> error occurring when using the snapshot.
|
||||
This parameter can only be set at server start.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Beyond the threshold, old data may be vacuumed away. This can help
|
||||
prevent bloat in the face of snapshots which remain in use for a
|
||||
long time. To prevent incorrect results due to cleanup of data which
|
||||
would otherwise be visible to the snapshot, an error is generated
|
||||
when the snapshot is older than this threshold and the snapshot is
|
||||
used to read a page which has been modified since the snapshot was
|
||||
built.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
A value of <literal>-1</> disables this feature, and is the default.
|
||||
Useful values for production work probably range from a small number
|
||||
of hours to a few days. The setting will be coerced to a granularity
|
||||
of minutes, and small numbers (such as <literal>0</> or
|
||||
<literal>1min</>) are only allowed because they may sometimes be
|
||||
useful for testing. While a setting as high as <literal>60d</> is
|
||||
allowed, please note that in many workloads extreme bloat or
|
||||
transaction ID wraparound may occur in much shorter time frames.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</sect2>
|
||||
</sect1>
|
||||
@ -3051,6 +3087,10 @@ include_dir 'conf.d'
|
||||
You should also consider setting <varname>hot_standby_feedback</>
|
||||
on standby server(s) as an alternative to using this parameter.
|
||||
</para>
|
||||
<para>
|
||||
This does not prevent cleanup of dead rows which have reached the age
|
||||
specified by <varname>old_snapshot_threshold</>.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
@ -3198,6 +3238,16 @@ include_dir 'conf.d'
|
||||
until it eventually reaches the primary. Standbys make no other use
|
||||
of feedback they receive other than to pass upstream.
|
||||
</para>
|
||||
<para>
|
||||
This setting does not override the behavior of
|
||||
<varname>old_snapshot_threshold</> on the primary; a snapshot on the
|
||||
standby which exceeds the primary's age threshold can become invalid,
|
||||
resulting in cancellation of transactions on the standby. This is
|
||||
because <varname>old_snapshot_threshold</> is intended to provide an
|
||||
absolute limit on the time which dead rows can contribute to bloat,
|
||||
which would otherwise be violated because of the configuration of a
|
||||
standby.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
Reference in New Issue
Block a user