sqlserver复制延迟报”应用复制的命令时在订阅服务器上找不到该行“

时间:2016-06-02 13:25:20   收藏:0   阅读:1053

最近遇到“应用复制的命令时在订阅服务器上找不到该行”问题,报错如下:

技术分享

官方给出的建议是重新同步和初始化订阅,当然,这是一种选择,但是对于动辄上百G的生产库,这种方法会消耗大量的资源和时间。可以通过定位出错数据,选择跳过,等从库追平主库后,修复错误数据方式,达到最终主从数据一致。

解决思路

1. 找到分发任务的事务序列号

sp_helpsubscriptionerrors [ @publisher = ]‘publisher
, [ @publisher_db = ]‘publisher_db 
, [ @publication = ]‘publication 
, [ @subscriber = ]‘subscriber 
, [ @subscriber_db = ]‘subscriber_db

参数对应值可以通过下面查询获取:

select * from MSsubscriber_info

获取publisher_db和publication

select * from MSpublications

在订阅服务器上执行,获取事务序列号

sp_setsubscriptionxactseqno [ @publisher= ]‘publisher, 
[ @publisher_db= ]‘publisher_db, 
[ @publication= ]‘publication, 
[ @xact_seqno= ] xact_seqno

示例:

技术分享

 

技术分享

 

2. 查看出错命令

获取事务序列号之后,查看事务号对应的具体命令:

sp_browsereplcmds [ [ @xact_seqno_start = ] xact_seqno_start ]
    [ , [ @xact_seqno_end = ] xact_seqno_end ] 
    [ , [ @originator_id = ] originator_id ]
    [ , [ @publisher_database_id = ] publisher_database_id ]
    [ , [ @article_id = ] article_id ]
    [ , [ @command_id= ] command_id ]
    [ , [ @agent_id = ] agent_id ]
[ , [ @compatibility_level = ] compatibility_level ]

前两个参数是开始事务号和结束事务号,输入这两参数即可

技术分享

command 默认的命名规则是sp_MS+operation+_schemaName+tableName

技术分享

 

通过示例知道该操作表示对T_CarPakingRecord表进行update操作,最后的表示的是主键。

3. 补救措施

根据上面分析的命令结果,将完整数据插入到从库中(这里是补救缺失行错误,如果是插入重复则直接删除即可)

如果认为数据一致性不重要,则可以直接跳过,不推荐这样。跳过错误的命令:

sp_setsubscriptionxactseqno [ @publisher = ] 发布服务器主机名
, [ @publisher_db = ] 发布数据库
, [ @publication = ] 发布名称
, [ @xact_seqno = ] 跳过的事务号

 

 

select*from MSpublications

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!