当前位置:Gxlcms > 数据库问题 > SQL Server同步复制问题排查方法

SQL Server同步复制问题排查方法

时间:2021-07-01 10:21:17 帮助过:16人阅读

应用复制的命令时在订阅服务器上找不到该行

技术分享图片

解决方法:用系统存储过程sp_browsereplcmds返回分发数据库中存储的可读版本复制命令的结果集,并将其用作诊断工具。?此存储过程在分发服务器上对分发数据库执行

  1. <strong>sp_browsereplcmds</strong> [ [ <strong>@xact_seqno_start = </strong>] <strong>‘</strong><em>xact_seqno_start</em><strong>‘ </strong>]
  2. [ <strong>, </strong>[ <strong>@xact_seqno_end = </strong>] <strong>‘</strong><em>xact_seqno_end</em><strong>‘ </strong>]
  3. [ <strong>, </strong>[ <strong>@originator_id = </strong>] <strong>‘</strong><em>originator_id</em><strong>‘ </strong>]
  4. [ <strong>, </strong>[ <strong>@publisher_database_id = </strong>] <strong>‘</strong><em>publisher_database_id</em><strong>‘ </strong>]
  5. [ <strong>, </strong>[ <strong>@article_id </strong>= ] <strong>‘</strong><em>article_id</em><strong>‘ </strong>]
  6. [ <strong>, </strong>[ <strong>@command_id= </strong>] <em>command_id </em>]
  7. [ <strong>,</strong> [ <strong>@agent_id</strong> = ] <em>agent_id</em> ]
  8. [ <strong>,</strong> [ <strong>@compatibility_level</strong> = ] <em>compatibility_level</em> ]
排查方法:在分发服务器—分发DB(distribution)

  1. Use [distribution]
  2. go
  3. --查询1:通常事务序列号,查到command_id=1的执行语句
  4. EXEC sp_browsereplcmds @xact_seqno_start=‘0x00044ED500008F3E00AB00000000‘,@xact_seqno_end=‘0x00044ED500008F3E00AB00000000‘
  5. --查询2:查看同步对象表(在以上结果集中找到article_id/publication_id栏位值)
  6. select *From MSarticles where article_id=344
  7. --查询3:同步命令太多时,查看可指定@command_id[如图1](必须可传@publisher_database_id[查询2])
  8. EXEC sp_browsereplcmds
  9. @xact_seqno_start=‘0x00044ED500008F3E00AB00000000‘
  10. ,@xact_seqno_end=‘0x00044ED500008F3E00AB00000000‘
  11. ,@publisher_database_id=4
  12. ,@command_id=1
  13. --


--第1个语句会出现以下两种情况(a/b)

--a、更新时找不到该行

{CALL?[dbo].[sp_MSupd_dbo表名]?(.....)}

--b、删除时找不到该行

{CALL?[dbo].[sp_MSdel_dbo表名]?(......}

了解同步存储过程:

技术分享图片

订阅端同步接口格式如下:

  1. --新增调用存储过程格式:((订阅客户端新增时同步存储不会抛出错误码))
  2. create procedure [dbo].[sp_MSins_dboTableName]
  3. @c1 tinyint,
  4. @c2 nvarchar(50),
  5. @c3 time,
  6. @c4 time
  7. as
  8. begin
  9. insert into [dbo].[TableName](
  10. [ID],
  11. [Name],
  12. [StartTime],
  13. [EndTime]
  14. ) values (
  15. @c1,
  16. @c2,
  17. @c3,
  18. @c4
  19. )
  20. end
  21. GO
  22. --更新调用存储过程格式:(订阅客户端修改数据时没有找到记录更新时;错误码:20598)
  23. create procedure [dbo].[sp_MSupd_dboTableName]
  24. @c1 tinyint = NULL,
  25. @c2 nvarchar(50) = NULL,
  26. @c3 time = NULL,
  27. @c4 time = NULL,
  28. @pkc1 tinyint = NULL,
  29. @bitmap binary(1)
  30. as
  31. begin
  32. update [dbo].[TableName] set
  33. [Name] = case substring(@bitmap,1,1) & 2 when 2 then @c2 else [Name] end,
  34. [StartTime] = case substring(@bitmap,1,1) & 4 when 4 then @c3 else [StartTime] end,
  35. [EndTime] = case substring(@bitmap,1,1) & 8 when 8 then @c4 else [EndTime] end
  36. where [ID] = @pkc1
  37. if @@rowcount = 0
  38. if @@microsoftversion>0x07320000
  39. exec sp_MSreplraiserror 20598
  40. end
  41. GO
  42. --删除调用存储过程格式:(订阅客户端删除数据时没有找到记录更新时;错误码:20598)
  43. create procedure [dbo].[sp_MSdel_dboTableName]
  44. @pkc1 tinyint
  45. as
  46. begin
  47. delete [dbo].[TableName]
  48. where [ID] = @pkc1
  49. if @@rowcount = 0
  50. if @@microsoftversion>0x07320000
  51. exec sp_MSreplraiserror 20598
  52. end
  53. 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   表名   

人气教程排行