↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / 配置参数

recovery_min_apply_delay

默认情况下,备库会尽快恢复来自发送服务器的 WAL 记录。保留一份延迟的数据副本可能很有用,因为它提供了纠正数据丢失错误的机会。此参数允许将恢复延迟指定的时间。例如,将此参数设置为 5min 时,只有当备库系统时间比主库报告的提交时间至少晚五分钟,备库才会重放各事务的提交。如果没有指定单位,则以毫秒计。默认值为零,不增加延迟。 服务器之间的复制延迟可能超过此参数的值,这种情况下不会增加延迟。注意,延迟根据主库写入的 WAL 时间戳与备库当前时间之差计算。网络延迟或级联复制配置导致的传输延迟,可能显著缩短实际等待时间。如果主库和备库的系统时钟不同步,恢复时可能比预期更早应用记录;但这通常不是主要问题,因为此参数的实用取值远大于服务器间常见的时间偏差。 延迟仅发生在事务提交的 WAL 记录上。其他记录会尽快重放;这不会造成问题,因为 MVCC 可见性规则确保在对应提交记录被应用之前,它们的效果不会可见。 恢复中的数据库达到一致状态后开始延迟,直到备库被提升或触发。此后,备库会结束恢复,不再等待。 WAL 记录必须保留在备库上,直到可以应用它们。因此,更长的延迟会导致更多 WAL 文件积压,增加备库 pg_wal 目录所需的磁盘空间。 此参数旨在用于流式物理复制部署;不过,只要指定了此参数,它就会在除崩溃恢复以外的所有情况下生效。使用此功能也会延迟 hot_standby_feedback,可能导致主库膨胀;同时使用两者时应谨慎。 警告 当 synchronous_commit 设置为 remote_apply 时,同步复制会受到此设置影响;每个 COMMIT 都必须等待提交被应用。 此参数只能在 postgresql.conf 文件中或服务器命令行上设置。

英文手册覆盖始于 PostgreSQL 7.4. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 19·选择有来源记录的版本

boot val
0
category
Replication / Standby Servers
context
sighup
doc same as
未知
documented
true
enumvals
未知
extra desc
未知
lang
en
max val
2147483647
metadata version
19beta4
min val
0
name
recovery_min_apply_delay
short desc
Sets the minimum delay for applying changes during recovery.
source
pg-settings-source-snapshot
unit
ms
vartype
integer

版本定义 PG 19

默认情况下,备库会尽快恢复来自发送服务器的 WAL 记录。保留一份延迟的数据副本可能很有用,因为它提供了纠正数据丢失错误的机会。此参数允许将恢复延迟指定的时间。例如,将此参数设置为 5min 时,只有当备库系统时间比主库报告的提交时间至少晚五分钟,备库才会重放各事务的提交。如果没有指定单位,则以毫秒计。默认值为零,不增加延迟。

服务器之间的复制延迟可能超过此参数的值,这种情况下不会增加延迟。注意,延迟根据主库写入的 WAL 时间戳与备库当前时间之差计算。网络延迟或级联复制配置导致的传输延迟,可能显著缩短实际等待时间。如果主库和备库的系统时钟不同步,恢复时可能比预期更早应用记录;但这通常不是主要问题,因为此参数的实用取值远大于服务器间常见的时间偏差。

延迟仅发生在事务提交的 WAL 记录上。其他记录会尽快重放;这不会造成问题,因为 MVCC 可见性规则确保在对应提交记录被应用之前,它们的效果不会可见。

恢复中的数据库达到一致状态后开始延迟,直到备库被提升或触发。此后,备库会结束恢复,不再等待。

WAL 记录必须保留在备库上,直到可以应用它们。因此,更长的延迟会导致更多 WAL 文件积压,增加备库 pg_wal 目录所需的磁盘空间。

此参数旨在用于流式物理复制部署;不过,只要指定了此参数,它就会在除崩溃恢复以外的所有情况下生效。使用此功能也会延迟 hot_standby_feedback,可能导致主库膨胀;同时使用两者时应谨慎。

警告

当 synchronous_commit 设置为 remote_apply 时,同步复制会受到此设置影响;每个 COMMIT 都必须等待提交被应用。

此参数只能在 postgresql.conf 文件中或服务器命令行上设置。

比较版本

完整来源事实

doc html

<p>
        By default, a standby server restores WAL records from the
        sending server as soon as possible. It may be useful to have a time-delayed
        copy of the data, offering opportunities to correct data loss errors.
        This parameter allows you to delay recovery by a specified amount
        of time.  For example, if
        you set this parameter to <code class="literal">5min</code>, the standby will
        replay each transaction commit only when the system time on the standby
        is at least five minutes past the commit time reported by the primary.
        If this value is specified without units, it is taken as milliseconds.
        The default is zero, adding no delay.
       </p><p>
        It is possible that the replication delay between servers exceeds the
        value of this parameter, in which case no delay is added.
        Note that the delay is calculated between the WAL time stamp as written
        on primary and the current time on the standby. Delays in transfer
        because of network lag or cascading replication configurations
        may reduce the actual wait time significantly. If the system
        clocks on primary and standby are not synchronized, this may lead to
        recovery applying records earlier than expected; but that is not a
        major issue because useful settings of this parameter are much larger
        than typical time deviations between servers.
       </p><p>
        The delay occurs only on WAL records for transaction commits.
        Other records are replayed as quickly as possible, which
        is not a problem because MVCC visibility rules ensure their effects
        are not visible until the corresponding commit record is applied.
       </p><p>
        The delay occurs once the database in recovery has reached a consistent
        state, until the standby is promoted or triggered. After that the standby
        will end recovery without further waiting.
       </p><p>
        WAL records must be kept on the standby until they are ready to be
        applied. Therefore, longer delays will result in a greater accumulation
        of WAL files, increasing disk space requirements for the standby's
        <code class="filename">pg_wal</code> directory.
       </p><p>
        This parameter is intended for use with streaming physical replication deployments;
        however, if the parameter is specified it will be honored in all cases
        except crash recovery.

        <code class="varname">hot_standby_feedback</code> will be delayed by use of this feature
        which could lead to bloat on the primary; use both together with care.

        </p><div class="warning"><h3 class="title">Warning</h3><p>
          Synchronous replication is affected by this setting when <code class="varname">synchronous_commit</code>
          is set to <code class="literal">remote_apply</code>; every <code class="literal">COMMIT</code>
          will need to wait to be applied.
         </p></div><p>
</p><p>
        This parameter can only be set in the <code class="filename">postgresql.conf</code>
        file or on the server command line.
       </p>

documentation revision

{"inputs":[{"file":"runtime-config-replication.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"76b3c1615af7dd60d031cefd485568e6336b3d13c366e8a473304bd7ef2fb92d","version":"19rc2"},{"file":"runtime-config-replication.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"935f29b71e863329c3c39caae902de37d5bbf03c2adcf42322225d3cefe71a84","version":"19rc2"}],"release":"19rc2","runtime_remeasured":false,"source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552"}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 19 · wiki-repair-20261023:559663fa4b3be19d7d8daa12d62f372e9e265c036cf87e077fa945b6bffd2a17

正文语言: zh-Hans · wiki-repair-20261023:559663fa4b3be19d7d8daa12d62f372e9e265c036cf87e077fa945b6bffd2a17