PostgreSQL 18 preview - 订阅数控制参数: max_active_replication_origins
PostgreSQL 18 preview - 订阅数控制参数: max_active_replication_origins
max_replication_slots 在上游节点中进行配置, 用于限制能创建多少个replication slot.
PostgreSQL 18 新增一个下游控制参数, max_active_replication_origins, 在逻辑订阅端节点进行配置, 用于限制可以创建多少个订阅.
max_active_replication_origins
Specifies how many replication origins (see Chapter 48) can be tracked simultaneously, effectively limiting how many logical replication subscriptions can be created on the server. Setting it to a lower value than the current number of tracked replication origins (reflected in pg_replication_origin_status) will prevent the server from starting. It defaults to 10. This parameter can only be set at server start. max_active_replication_origins must be set to at least the number of subscriptions that will be added to the subscriber, plus some reserve for table synchronization.
max_active_replication_origins 指定可同时跟踪多少个复制源,从而有效限制订阅端数据库服务上可创建的逻辑复制订阅数量。 如果设置的值小于当前跟踪的复制源数量(反映在 pg_replication_origin_status),数据库服务将无法启动。 默认值为 10。 max_active_replication_origins 必须至少设置为将添加到订阅者的订阅数,再加上一些用于表同步的预留数。
参考:
https://www.postgresql.org/docs/devel/runtime-config-replication.html
https://www.postgresql.org/docs/devel/replication-origins.html
补丁如下:
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=04ff636cbce4b91fba1f334e1bc0dc88686e7b2d
Add GUC option to control maximum active replication origins.
author Masahiko Sawada <[email protected]>
Fri, 21 Mar 2025 19:20:15 +0000 (12:20 -0700)
committer Masahiko Sawada <[email protected]>
Fri, 21 Mar 2025 19:20:15 +0000 (12:20 -0700)
commit 04ff636cbce4b91fba1f334e1bc0dc88686e7b2d
tree b312f82dff3129a246c20f19e25aff7a803c8c06 tree
parent 0e032a2240a98669546023f7707030ea3ce4ded7 commit | diff
Add GUC option to control maximum active replication origins. This commit introduces a new GUC option max_active_replication_origins
to control the maximum number of active replication
origins. Previously, this was controlled by
'max_replication_slots'. Having a separate GUC option provides better
flexibility for setting up subscribers, as they may not require
replication slots (for cascading replication) but always require
replication origins.
Author: Euler Taveira <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Reviewed-by: Masahiko Sawada <[email protected]>
Reviewed-by: Peter Eisentraut <[email protected]>
Reviewed-by: vignesh C <[email protected]>
Discussion: https://postgr.es/m/[email protected]
AI 解读
好的,我来用中文解读这个 PostgreSQL 的 Patch,并解释它背后的含义。
核心内容:
这个 Patch 引入了一个新的 GUC (Grand Unified Configuration) 选项 max_active_replication_origins,用于控制最大活跃的复制源 (Replication Origins) 的数量。
背景知识:
Replication (复制): PostgreSQL 支持多种复制方式,允许将数据从一个数据库服务器(主库)复制到其他数据库服务器(备库)。 Replication Slots (复制槽): 复制槽是主库上的一种机制,用于确保在备库连接并接收更改之前,主库不会删除 WAL (Write-Ahead Logging) 日志。这保证了备库可以跟上主库的进度,避免数据丢失。 Replication Origins (复制源): 复制源用于跟踪逻辑复制中的数据来源。在复杂的复制拓扑中(例如,级联复制),一个备库可能既是另一个备库的复制源,又是另一个备库的复制目标。复制源用于防止复制循环和确保数据一致性。 GUC (Grand Unified Configuration): PostgreSQL 的配置参数,可以通过 postgresql.conf文件、命令行选项或ALTER SYSTEM命令进行设置。
Patch 的动机:
在之前的 PostgreSQL 版本中,最大活跃复制源的数量是由 max_replication_slots 这个 GUC 选项控制的。这意味着,如果你想增加最大活跃复制源的数量,你也必须增加最大复制槽的数量。
级联复制节点可能既需要作为源, 又是目标, 既是上游节点又是下游节点. max_replication_slots 在上游节点中进行配置, 用于限制能创建多少个replication slot. PostgreSQL 18 新增一个下游控制参数, max_active_replication_origins, 在逻辑订阅端节点进行配置, 用于限制可以创建多少个订阅.
Patch 的解决方案:
这个 Patch 引入了一个新的 GUC 选项 max_active_replication_origins,专门用于控制最大活跃复制源的数量。这使得用户可以独立地设置最大活跃复制源的数量和最大复制槽的数量,从而提供更大的灵活性。
具体变化:
引入新的 GUC 选项 max_active_replication_origins。max_active_replication_origins控制最大活跃复制源的数量。max_replication_slots仍然控制最大复制槽的数量。用户可以根据需要独立地设置这两个选项。