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热门书籍等,奖品丰富,快来许愿。开不开森.