千家信息网

Publication的 immediate_sync 属性

发表于:2025-01-19 作者:千家信息网编辑
千家信息网最后更新 2025年01月19日,Publication的属性 immediate_sync 控制 Snapshot 文件的创建,如果属性 immediate_sync设置为true,那么snapshot file在snapshot
千家信息网最后更新 2025年01月19日Publication的 immediate_sync 属性

Publication的属性 immediate_sync 控制 Snapshot 文件的创建,如果属性 immediate_sync设置为true,那么snapshot file在snapshot agent 每次 run的时候都会创建。如果设置为false,snapshot file 只在subscription创建时才会创建。

在创建Snapshot file之后,如果对article 进行update,会产生 pending transaction,这些transaction会被写入到distribution db中。

如果immediate_sync设置为true,那么replication 会保持 pending transaction,不会因为transaction被replcated而删除,优点是snapshot file 和 pending transaction 能被多个subscription重用,缺点是会导致distribution db增长。pending transaction的maximum retention time是由Publication的Retention属性确定的,Default值是336hours, 即14days。

如果immediate_sync属性设置为false,那么在将pending transaction推送到subscriptions之后,replication 将pending transaction 和 snapshot file删除。

引用《SQL Server "Distribution clean up: distribution" Job Failing Large MSRepl_commands》:

-- Check to see if "immediate sync" is set to 1.--  This will cause transactions to be held in MSRepl_commands -- rather than deleted when distributed. EXEC sp_changepublication     @publication = '', -- put your publication name here     @property = 'immediate_sync',     @value = 'false'

distribution size增长,会导致distribution latency,推荐将immediate_sync属性设置为false。在每次新建subscriber database时,使用新的snapshot。

如果要将Publication的 immediate_sync 设置为false,前提条件 allow_anonymous 必须是false。

EXEC sys.sp_changepublication     @publication = '', -- put your publication name here     @property = 'allow_anonymous',     @value = 'false'

allow_anonymous:Anonymous subscriptions can be created for the given publication, and immediate_sync must also be true.

使用以下脚本批量更新publication

select     name,    immediate_sync,    allow_anonymous,    N'exec sys.sp_changepublication  @publication =  '''+name+'''     , @property =  ''immediate_sync''     , @value =  ''false''' as Alter_immediate_sync,    case         when allow_anonymous=1 then             N'exec sys.sp_changepublication  @publication =  '''+name+'''             , @property =  ''allow_anonymous''             , @value =  ''false'''         else ''     end as alter_allow_anonymousfrom dbo.syspublicationswhere immediate_sync=1

Appendix:

一,sp_addpublication 重要参数
[ @immediate_sync=] 'immediate_synchronization'

Specifies if the synchronization files for the publication are created each time the Snapshot Agent runs. immediate_synchronization is nvarchar(5), with a default of FALSE.

If true, the synchronization files are created or re-created each time the Snapshot Agent runs. Subscribers are able to get the synchronization files immediately if the Snapshot Agent has completed before the subscription is created. New subscriptions get the newest synchronization files generated by the most recent execution of the Snapshot Agent.independent_agent must be true for immediate_synchronization to be true.

If false, the synchronization files are created only if there are new subscriptions. You must call sp_addsubscription for each subscription when you incrementally add a new article to an existing publication. Subscribers cannot receive the synchronization files after the subscription until the Snapshot Agents are started and completed.

[ @independent_agent=] 'independent_agent'

Specifies if there is a stand-alone Distribution Agent for this publication. independent_agent is nvarchar(5), with a default of FALSE. If true, there is a stand-alone Distribution Agent for this publication. If false, the publication uses a shared Distribution Agent, and each Publisher database/Subscriber database pair has a single, shared Agent.

[ @retention=] retention

Is the retention period in hours for subscription activity. retention is int, with a default of 336 hours. If a subscription is not active within the retention period, it expires and is removed. The value can be greater than the maximum retention period of the distribution database used by the Publisher. If 0, well-known subscriptions to the publication will never expire and be removed by the Expired Subscription Cleanup Agent.

二,引用文档:What Immediate_sync means in Transactional Replication

sp_addpublication parameter: [ @immediate_sync=] 'immediate_synchronization'

Immediate_sync feature instructs Replication to maintain Snapshot BCP files and distributed transactions in the Distribution database should a new subscriber be created (or reinit) within the Retention period. By default, this information is purged as soon as existing subscribers receive the transactions. By keeping the Snapshot and transactions for hours or days, new subscribers can 1) Use old snapshot files, and 2) apply all pending changes since the snapshot. New Subscribers (or reinit) would not need to have a "fresh" snapshot generated.

IF TRUE (keep commands CACHED in Distribution database)

If true, the synchronization files are created or re-created each time the Snapshot Agent runs. Subscribers are able to get the synchronization files immediately if the Snapshot Agent has completed before the subscription is created. New subscriptions get the newest synchronization files generated by the most recent execution of the Snapshot Agent. Subscribers would then receive any "pending" transactions from the Distribution database.

If the publication has the property @immediate_sync set to "true" after the Snapshot Agent is created, transactions on the distribution database are maintained only to support the existing subscribers. In other words, at the time of the Snapshot generation completes all subscriptions to be initialized must be known. If a new subscriber is added, or marked for re-initialization after the Snapshot is Generated another snapshot is required.

If true, The Distribution Cleanup Agent will not purge the Distribution database or the Snapshot folder until the Publication Retention Period. This may result in unexpected distribution database growth.

IF FALSE (clean up CACHED commands as soon as Replicated)

If false, the synchronization files are created only if there are new subscriptions. Subscribers cannot receive the synchronization files until the Snapshot Agents are started and completed. With immediate_sync was set to "false", if you then mark ALL subscriptions for re-initialization, they can all apply the same Snapshot.


属性 会创 增长 重要 优点 前提 参数 多个 文件 文档 时候 是由 条件 缺点 脚本 控制 推荐 更新 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 网络安全的十大金句 服务器带内管理作用 维护网络安全要坚持 软件开发项目技术沟通 美创科技网络安全产业链图谱 梦幻转区后多久能转回原来服务器 如何查看数据库默认的字符集 中英文全文数据库是什么 服务器连接后怎么安装 信息安全和网络安全有什么联系 云主机软件开发注意事项 计算机网络技术月工资最高是多少 打印机服务器 扫描 服务器100m带宽能带多大 广州职友集网络技术 济南浪潮数据库开发工程师 假期网络安全注意事项 全国网络安全竞赛题库 微交易软件开发点位盘 服务器主板风扇底座怎么拆 网络安全薪水一般多少在县城 长春青网络技术有限公司招聘 万里开源数据库华为 三级数据库技术各题分值 吉林市网络安全公司 网络安全是指网络 定制物联网大数据平台软件开发 重庆联通dns服务器云空间 台州云软件开发项目 南京的网络技术有限公司
0