Fanr

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

描述:

最近在测试版测试了复制+镜像,之后做镜像切换,以前做 就只有一个数据库使用复制+镜像,而且线上也是如此应用并没有大问题

场景:

有3个服务器 A,B,C。

A为primary,B为secondary,C为订阅,

分发 A中有2个数据库 test1,test2,为test1,test2订阅到C

问题:

当test1切换到B,复制正常,然后删除test1发布的订阅,

在发布服务器也就是B上执行:

use [test1] exec sp_dropsubscription @publication = N'test1', @subscriber = N'C', @destination_db = N'test1', @article = N'all' GO

然后test2在C的订阅就是 镜像监视中丢失,所有的待分发数据全部不分发,但是 订阅数据库的timestamp还是一样运行,

经测试如果 订阅不是同一台,那么就不会受影响

--20210604

订阅被丢失是因为[dbo].[MSsubscriptions]被删了,通过跟踪profiler,发现系统调用了2个存储过程:

exec "distribution"."dbo"."sp_MSdrop_subscription";1 N'IZ0T6I5SXUC6M4Z',N'test1_2016',N'IZQ4J5LFKTS49PZ',1,N'test1_2016',N'test1_2016' 

go

exec "distribution"."dbo"."sp_MSdrop_subscriber_info";1 @publisher=N'IZ0T6I5SXUC6M4Z',@subscriber=N'IZQ4J5LFKTS49PZ'

go

 

通过阅读代码发现sp_MSdrop_subscription并没有什么问题,有问题的是sp_MSdrop_subscriber_info,

这个过程里面有段代码如下:

if exists (select * from msdb..MSdistpublishers where 
            lower(name) = lower(@publisher) and
            thirdparty_flag = 0)
        begin
            -- This is needed for 6.5 upgrade.
            -- Remove subscription entries for this publisher and subscriber pair
            -- Get dist publisher ID
            exec sys.sp_MSvalidate_distpublisher @publisher, @publisher_id OUTPUT
            delete dbo.MSsubscriptions where subscriber_id = @srvid and 
                publisher_id = @publisher_id
        end

这才导致dbo.MSsubscriptions,同一个publisher,同一个subscriber的订阅会丢失

posted on 2021-06-03 16:11  Fanr_Zh  阅读(109)  评论(0编辑  收藏  举报