Skip to content

Files

Latest commit

Dec 15, 2023
f400df2 · Dec 15, 2023

History

History
74 lines (31 loc) · 3.03 KB

20201112_01.md

File metadata and controls

74 lines (31 loc) · 3.03 KB

PostgreSQL 14 preview - [PATCH] Add truncate option to subscription commands - 支持逻辑订阅truncate本地表语法

作者

digoal

日期

2020-11-12

标签

PostgreSQL , 订阅 , truncate


背景

PostgreSQL内部逻辑订阅语法, 可以将远端数据表的全量+变化量同步到本地.

在使用logical replication的开始从远端同步数据到本地前, 将本地被订阅表的数据truncate. 也就是说支持自动清理动作.

pg 14以前, 需要显示的调用trucate table, 而pg 14的refresh publication, create subscription都支持truncate语法, 不需要额外调用truncate命令.

https://commitfest.postgresql.org/30/2758/

https://www.postgresql.org/message-id/flat/CF3B6672-2A43-4204-A60A-68F359218A9B@endpoint.com

-hackers,    
    
    
    
Enclosed find a patch to add a “truncate” option to subscription commands.    
    
    
    
When adding new tables to a subscription (either via `CREATE SUBSCRIPTION` or `REFRESH PUBLICATION`), tables on the target which are being newly subscribed will be truncated before the data copy step.  This saves explicit coordination of a manual `TRUNCATE` on the target tables and allows the results of the initial data sync to be the same as on the publisher at the time of sync.    
    
    
    
To preserve compatibility with existing behavior, the default value for this parameter is `false`.    
    
    
    
Best,    
    
    
    
David    

您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.

digoal's wechat