作者
digoal
日期
2022-03-22
标签
PostgreSQL , 逻辑订阅 , alter subscription skip , 约束错误 , 跳过逻辑错误
现在支持ALTER SUBSCRIPTION ... SKIP
语法直接跳过LSN了.
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=208c5d65bbd60e33e272964578cb74182ac726a8
Add ALTER SUBSCRIPTION ... SKIP. author Amit Kapila <akapila@postgresql.org> Tue, 22 Mar 2022 01:41:19 +0000 (07:11 +0530) committer Amit Kapila <akapila@postgresql.org> Tue, 22 Mar 2022 01:41:19 +0000 (07:11 +0530) commit 208c5d65bbd60e33e272964578cb74182ac726a8 tree 5f3a99783f4c7be35c16237c5b10ebc711b37293 tree parent 315ae75e9b6da72456eaa44e55ace9ab1b95ef74 commit | diff Add ALTER SUBSCRIPTION ... SKIP. This feature allows skipping the transaction on subscriber nodes. If incoming change violates any constraint, logical replication stops until it's resolved. Currently, users need to either manually resolve the conflict by updating a subscriber-side database or by using function pg_replication_origin_advance() to skip the conflicting transaction. This commit introduces a simpler way to skip the conflicting transactions. The user can specify LSN by ALTER SUBSCRIPTION ... SKIP (lsn = XXX), which allows the apply worker to skip the transaction finished at specified LSN. The apply worker skips all data modification changes within the transaction. Author: Masahiko Sawada Reviewed-by: Takamichi Osumi, Hou Zhijie, Peter Eisentraut, Amit Kapila, Shi Yu, Vignesh C, Greg Nancarrow, Haiying Tang, Euler Taveira Discussion: https://postgr.es/m/CAD21AoDeScrsHhLyEPYqN3sydg6PxAPVBboK=30xJfUVihNZDA@mail.gmail.com
复制
参考手册:
https://www.postgresql.org/docs/devel/sql-altersubscription.html
SKIP ( skip_option = value ) Skips applying all changes of the remote transaction. If incoming data violates any constraints, logical replication will stop until it is resolved. By using ALTER SUBSCRIPTION ... SKIP command, the logical replication worker skips all data modification changes within the transaction. This option has no effect on the transactions that are already prepared by enabling two_phase on subscriber. After logical replication worker successfully skips the transaction or finishes a transaction, LSN (stored in pg_subscription.subskiplsn) is cleared. See Section 31.3 for the details of logical replication conflicts. Using this command requires superuser privilege. skip_option specifies options for this operation. The supported option is: lsn (pg_lsn) Specifies the finish LSN of the remote transaction whose changes are to be skipped by the logical replication worker. The finish LSN is the LSN at which the transaction is either committed or prepared. Skipping individual subtransaction is not supported. Setting NONE resets the LSN.
复制
https://www.postgresql.org/docs/devel/logical-replication-conflicts.html
ERROR: duplicate key value violates unique constraint "test_pkey" DETAIL: Key (c)=(1) already exists. CONTEXT: processing remote data for replication origin "pg_16395" during "INSERT" for replication target relation "public.test" in transaction 725 finished at 0/14C0378 The LSN of the transaction that contains the change violating the constraint and the replication origin name can be found from the server log (LSN 0/14C0378 and replication origin pg_16395 in the above case). The transaction that produces conflict can be skipped by using ALTER SUBSCRIPTION ... SKIP with the finish LSN (i.e., LSN 0/14C0378). The finish LSN could be an LSN at which the transaction is committed or prepared on the publisher. Alternatively, the transaction can also be skipped by calling the pg_replication_origin_advance() function transaction. Before using this function, the subscription needs to be disabled temporarily either by ALTER SUBSCRIPTION ... DISABLE or, the subscription can be used with the disable_on_error option. Then, you can use pg_replication_origin_advance() function with the node_name (i.e., pg_16395) and the next LSN of the finish LSN (i.e., 0/14C0379). The current position of origins can be seen in the pg_replication_origin_status system view. Please note that skipping the whole transaction include skipping changes that might not violate any constraint. This can easily make the subscriber inconsistent.
复制
注意事项:
- 跳过整个事务, 包括事务中之前已经apply的未引发冲突的SQL.
期望 PostgreSQL 增加什么功能?
PolarDB for PostgreSQL云原生分布式开源数据库
PostgreSQL 解决方案集合
德哥 / digoal's github - 公益是一辈子的事.
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
外国CTO也感兴趣的开源数据库项目——openHalo
小满未满、
1942次阅读
2025-04-21 16:58:09
3月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
382次阅读
2025-04-15 14:48:05
转发有奖 | PostgreSQL 16 PGCM高级认证课程直播班招生中!
墨天轮小教习
235次阅读
2025-04-14 15:58:34
中国PostgreSQL培训认证体系新增PGAI应用工程师方向
开源软件联盟PostgreSQL分会
189次阅读
2025-05-06 10:21:13
4月“墨力原创作者计划”获奖名单公布!
墨天轮编辑部
187次阅读
2025-05-13 16:21:59
华象新闻 | PostgreSQL 18 Beta 1、17.5、16.9、15.13、14.18、13.21 发布
严少安
169次阅读
2025-05-09 11:34:10
QPlus V6.3 更新,新增PostgreSQL与PolarDB PG支持,OceanBase 容灾管理重磅上线
沃趣科技
168次阅读
2025-05-13 09:39:27
PG生态赢得资本市场青睐:Databricks收购Neon,Supabase融资两亿美元,微软财报点名PG
老冯云数
159次阅读
2025-05-07 10:06:22
SQL 优化之 OR 子句改写
xiongcc
147次阅读
2025-04-21 00:08:06
告别老旧mysql_fdw,升级正当时
NickYoung
127次阅读
2025-04-29 11:15:18
热门文章
阿里巴巴的使命、愿景、核心价值观
2021-01-04 67774浏览
MacOS 关闭和开启虚拟内存(swap)
2022-01-20 17957浏览
[珍藏级] PostgreSQL ssl 证书配置 - 防止中间攻击者 - 以及如何使用证书无密码登录配置cert
2020-06-19 16560浏览
PostgreSQL md5hash插件 - 128bit 存储,压缩空间、提升效率
2019-11-08 14381浏览
产品与运营-OKR的设计、总结、复盘、规划、组织保障和考核例子
2022-01-20 13417浏览
最新文章
PostgreSQL 15 preview - PostgreSQL 15 pg_stat_statements 增加对temp file blocks io timing的统计, 增加JIT的统计.
2022-01-20 273浏览
德说-第92期, 怎么解决躺平|不想奋斗?
2022-01-20 303浏览
PostgreSQL 增量物化视图插件 - pg_ivm incremental materialized view maintenance
2022-01-20 1415浏览
PostgreSQL 15 preview - ARM多核适配 性能提升 - Use ISB as a spin-delay instruction on ARM64
2022-01-20 803浏览
PostgreSQL 15 preview - recovery(包括崩溃恢复、逻辑流复制、物理流复制、归档恢复) 加速, 支持异步prefetch 预读接下来要恢复的wal record相关的data block到shared buffer
2022-01-20 1231浏览