时间:2021-07-01 10:21:17 帮助过:16人阅读
解决方法:用系统存储过程sp_browsereplcmds(返回分发数据库中存储的可读版本复制命令的结果集,并将其用作诊断工具。?此存储过程在分发服务器上对分发数据库执行)
排查方法:在分发服务器—分发DB(distribution)
- <strong>sp_browsereplcmds</strong> [ [ <strong>@xact_seqno_start = </strong>] <strong>‘</strong><em>xact_seqno_start</em><strong>‘ </strong>]
- [ <strong>, </strong>[ <strong>@xact_seqno_end = </strong>] <strong>‘</strong><em>xact_seqno_end</em><strong>‘ </strong>]
- [ <strong>, </strong>[ <strong>@originator_id = </strong>] <strong>‘</strong><em>originator_id</em><strong>‘ </strong>]
- [ <strong>, </strong>[ <strong>@publisher_database_id = </strong>] <strong>‘</strong><em>publisher_database_id</em><strong>‘ </strong>]
- [ <strong>, </strong>[ <strong>@article_id </strong>= ] <strong>‘</strong><em>article_id</em><strong>‘ </strong>]
- [ <strong>, </strong>[ <strong>@command_id= </strong>] <em>command_id </em>]
- [ <strong>,</strong> [ <strong>@agent_id</strong> = ] <em>agent_id</em> ]
- [ <strong>,</strong> [ <strong>@compatibility_level</strong> = ] <em>compatibility_level</em> ]
- Use [distribution]
- go
- --查询1:通常事务序列号,查到command_id=1的执行语句
- EXEC sp_browsereplcmds @xact_seqno_start=‘0x00044ED500008F3E00AB00000000‘,@xact_seqno_end=‘0x00044ED500008F3E00AB00000000‘
- --查询2:查看同步对象表(在以上结果集中找到article_id/publication_id栏位值)
- select *From MSarticles where article_id=344
- --查询3:同步命令太多时,查看可指定@command_id[如图1](必须可传@publisher_database_id[查询2])
- EXEC sp_browsereplcmds
- @xact_seqno_start=‘0x00044ED500008F3E00AB00000000‘
- ,@xact_seqno_end=‘0x00044ED500008F3E00AB00000000‘
- ,@publisher_database_id=4
- ,@command_id=1
- --
--第1个语句会出现以下两种情况(a/b)
--a、更新时找不到该行
{CALL?[dbo].[sp_MSupd_dbo表名]?(.....)}
--b、删除时找不到该行
{CALL?[dbo].[sp_MSdel_dbo表名]?(......}
了解同步存储过程:
订阅端同步接口格式如下:
- --新增调用存储过程格式:((订阅客户端新增时同步存储不会抛出错误码))
- create procedure [dbo].[sp_MSins_dboTableName]
- @c1 tinyint,
- @c2 nvarchar(50),
- @c3 time,
- @c4 time
- as
- begin
- insert into [dbo].[TableName](
- [ID],
- [Name],
- [StartTime],
- [EndTime]
- ) values (
- @c1,
- @c2,
- @c3,
- @c4
- )
- end
- GO
- --更新调用存储过程格式:(订阅客户端修改数据时没有找到记录更新时;错误码:20598)
- create procedure [dbo].[sp_MSupd_dboTableName]
- @c1 tinyint = NULL,
- @c2 nvarchar(50) = NULL,
- @c3 time = NULL,
- @c4 time = NULL,
- @pkc1 tinyint = NULL,
- @bitmap binary(1)
- as
- begin
- update [dbo].[TableName] set
- [Name] = case substring(@bitmap,1,1) & 2 when 2 then @c2 else [Name] end,
- [StartTime] = case substring(@bitmap,1,1) & 4 when 4 then @c3 else [StartTime] end,
- [EndTime] = case substring(@bitmap,1,1) & 8 when 8 then @c4 else [EndTime] end
- where [ID] = @pkc1
- if @@rowcount = 0
- if @@microsoftversion>0x07320000
- exec sp_MSreplraiserror 20598
- end
- GO
- --删除调用存储过程格式:(订阅客户端删除数据时没有找到记录更新时;错误码:20598)
- create procedure [dbo].[sp_MSdel_dboTableName]
- @pkc1 tinyint
- as
- begin
- delete [dbo].[TableName]
- where [ID] = @pkc1
- if @@rowcount = 0
- if @@microsoftversion>0x07320000
- exec sp_MSreplraiserror 20598
- end
- GO
解决方法1:(a、更新、b、删除):在订阅端把缺少的数据行新增(根据以上出错ID加一条记录)或用导入导出方法(SQL语句同步指定以上ID).(原因:订阅端缺少数据行造成删除或更新找不到数据行而出错),
不推荐以下方法(解决方法2、解决方法3)
解决方法2:改同步存储过程接口把抛出错码判断去掉,会造成数据不同步,如果取消最好只取消删除时调用的存储过程(如:sp_MSdel_dboTableName)
解决方法3:使用发布代理的SkipErrors参数来忽略跳过错误20598(会造成数据不同步,不能有效查找原因,需要对比环境数据(如表:记录数))如下图:
--c、新增时出错
{CALL?[dbo].[sp_MSins_dbo表]?
解决方法4:(c、新增时出错):新增时出错,解决方法根据提示可能是标识值或主健ID已在(删除订阅端该行数据)或表结构不值造成的
SQL Server同步复制问题排查方法
标签:tiny val ica update 参数 调用 排查 mds 表名