PG 19 发布端支持FOR ALL SEQUENCES, 通过逻辑复制进行大版本升级丝滑了亿点点
PostgreSQL 19 preview - 发布端支持FOR ALL SEQUENCES, 通过逻辑复制进行大版本升级丝滑了亿点点
PostgreSQL 19 逻辑复制功能对大版本升级场景更友好了, 在发布端支持了FOR ALL SEQUENCES , 一次将所有序列发布到逻辑复制订阅端.
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=96b37849734673e7c82fb86c4f0a46a28f500ac8
Add "ALL SEQUENCES" support to publications.
author Amit Kapila <[email protected]>
Thu, 9 Oct 2025 03:48:54 +0000 (03:48 +0000)
committer Amit Kapila <[email protected]>
Thu, 9 Oct 2025 03:48:54 +0000 (03:48 +0000)
commit 96b37849734673e7c82fb86c4f0a46a28f500ac8
tree bd12627fe6ff240f26d7ff2db36e29a9c3e751e4 tree
parent ef5e60a9d352a97791af632e0d26a572bc88e921 commit | diff
Add "ALL SEQUENCES" support to publications. This patch adds support for the ALL SEQUENCES clause in publications,
enabling synchronization/replication of all sequences that is useful for
upgrades.
Publications can now include all sequences via FOR ALL SEQUENCES.
psql enhancements:
\d shows publications for a given sequence.
\dRp indicates if a publication includes all sequences.
ALL SEQUENCES can be combined with ALL TABLES, but not with other options
like TABLE or TABLES IN SCHEMA. We can extend support for more granular
clauses in future.
The view pg_publication_sequences provides information about the mapping
between publications and sequences.
This patch enables publishing of sequences; subscriber-side support will
be added in upcoming patches.
Author: vignesh C <[email protected]>
Author: Tomas Vondra <[email protected]>
Reviewed-by: shveta malik <[email protected]>
Reviewed-by: Dilip Kumar <[email protected]>
Reviewed-by: Peter Smith <[email protected]>
Reviewed-by: Hayato Kuroda <[email protected]>
Reviewed-by: Masahiko Sawada <[email protected]>
Reviewed-by: Nisha Moond <[email protected]>
Reviewed-by: Shlok Kyal <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Discussion: https://postgr.es/m/CAA4eK1LC+KJiAkSrpE_NwvNdidw9F2os7GERUeSxSKv71gXysQ@mail.gmail.com
来看看Qwen如何解读这个patch.
该 patch 为 PostgreSQL 的发布(publication)功能新增了 ALL SEQUENCES 支持,也就是允许用户在创建 publication 时用 FOR ALL SEQUENCES 来一次性加入所有序列对象。这样可以同步/复制数据库中的所有序列,特别适用于数据库升级等场景(比如主从切换、逻辑复制时保持序列一致性)。
主要变更点:
FOR ALL SEQUENCES 语法
创建 publication 时可用: CREATE PUBLICATION mypub FORALL SEQUENCES;也可以与 ALL TABLES组合:CREATE PUBLICATION mypub FORALLTABLES, ALL SEQUENCES;不能和 TABLE或TABLES IN SCHEMA等更细粒度选项混用。
psql 工具增强
\d命令显示某个序列的发布信息。\dRp命令显示某 publication 是否包含 ALL SEQUENCES。
系统视图新增
pg_publication_sequences:用于展示 publication 与 sequence 的映射关系,方便查询和管理。
应用场景
数据库升级、迁移时,需保证序列同步,避免主/备/订阅端的自增 ID 不一致。 逻辑复制场景下,除了表数据,还可确保序列(如自增主键)的值在订阅端准确更新。 简化运维,一次性发布所有序列,无需逐个指定。
用法举例
创建发布并同步所有表和序列: CREATE PUBLICATION pub_all FORALLTABLES, ALL SEQUENCES;查看序列的发布归属: \d my_sequence查询 publication 是否包含所有序列: \dRp pub_all查看序列发布映射: SELECT * FROM pg_publication_sequences;
注意事项
目前仅发布端支持,订阅端支持将在后续 patch 加入。 ALL SEQUENCES 不能与更细粒度的 TABLE/TABLES IN SCHEMA 混用,未来可能扩展。
总结:
本 patch 大大提升了 PostgreSQL 逻辑复制场景下对序列对象的支持,简化了数据库升级和迁移时的序列同步问题,是运维和高可用场景的实用增强。