上周做了一個case,客戶無法為SQL Server instance配置remote distributor。 下面分享一下排查問題的過程,希望對您排查類似的問題所有幫助。
客戶的環境中的SQL Server均為sql server 2012 RTM.
Distributor server: SQL108W2K8R22
Publisher: SQL108W2K8R21
Subscriber: SQL108W2K8R23
SQL108W2K8R23為SQL108W2K8R21的訂閱服務器,模式為push.
現在要為SQL108W2K8R23創建發布,將SQL108W2K8R22添加為分發服務器時出錯。
配置時會出現下面的錯誤:
Error 21670只是一般性的登錄錯誤:Connection to server [%s] failed.沒什么價值
于是嘗試手工添加:exec sp_adddistributor @distributor = N'SQL108W2K8R22', @passWord = N'StrongPassword'
得到下面的錯誤:
Msg 18483, Level 14, State 1, Line 1
Could not connect to server 'SQL108W2K8R22' because 'distributor_admin' is not defined as a remote login at the server. Verify that you have specified the correct login name.
搜索了錯誤信息,得到下面這篇 KBhttp://support.microsoft.com/kb/818334
按照KB上進行檢查,發現這三臺SQL SERVER的@@servername和hostname都是匹配的,這篇KB沒有起到效果。
確認在添加前,distributor SQL108W2K8R22已經將SQL108W2K8R23添加為發布服務器。在distributor里找到了名稱為SQL108W2K8R23的linked server,也可以在sys.servers查看到相應的記錄
在distributor中的sys.link_logins中也包含distributor_admin相應的記錄。
雖然 SQL108W2K8R23添加remote distributor失敗,但仍然創建名為出[repl_distributor]的linked server。
于是在distributor和SQL108W2K8R23上同時抓取trace,看看添加remote distributor(sp_adddistributor)時究竟發生了什么。
在SQL108W2K8R23的trace中,發現SQL108W2K8R23通過linked server repl_distributor向distributor 提交一個查詢,用于比對distributor 上SQL 版本。
EXEC @retcode = repl_distributor.master.sys.sp_executesql N'select @dist_ver = @@microsoftversion', N'@dist_ver bigint output', @dist_ver output
這個語句是添加distributor操作中的最后一個語句。
查看distributor上的trace,發現distributor上沒有接收到任何語句,只有之前提到的報錯信息看起來linked server可以工作,成功地將語句發送到了target server(distributor),可能是linked server有些信息沒有傳遞給distributor或者是distributor缺失了一些metadata。但檢查了linked server的屬性,沒有發現異常。但如果是metadata丟失的話,那么刪掉重建應該是不錯的選擇:
于是嘗試將SQL108W2K8R23從distributor的publisher list中刪除,并再次添加. 但在刪除的時候出現如下錯誤:于是手工執行了一把,得到了同樣的錯誤:
Msg 20584, Level 16, State 1, Procedure sp_MSrepl_check_server, Line 67
Cannot drop server 'SQL108W2K8R21' because it is used as a Subscriber to remote Publisher 'SQL108W2K8R23' in replication.
在sp_dropdistpublisher內部,主要會調用兩個存儲過程:sys.sp_dropremotelogin@publisher,'distributor_admin','distributor_admin'
sys.sp_dropserver @publisher, 'droplogins'
sp_dropremotelogin的作用如下:
Removes a remote login mapped to a local login used to execute remote stored procedures against the local server running SQL Server
而sp_dropserver內部調用了sp_MSrepl_check_server,檢查(distribution.dbo. MSsubscriber_info)將要刪除的publisher是否同時也是一個訂閱。如果是,就拋出異常,然后退出。
不幸的是,sp_dropremotelogin和sp_dropserver是單獨執行的,并不在一個事務里。所以雖然最終執行失敗,但sp_dropremotelogin造成的影響卻沒有回滾。
將distribution.dbo. MSsubscriber_info里的相關記錄刪除。
然后將publisher刪除后重建,之后添加distributor的操作就成功了J
擴展:
1)
sp_dropremotelogin:Removes a remote login mapped to a local login used to execute remote stored procedures against the local server running SQL Server
sp_addremotelogin:Adds a new remote login ID on the local server. This enables remote servers to connect and execute remote procedure calls.
MSsubscriber_info :it contains one row for each Publisher/Subscriber pair that is being pushed subscriptions from the local Distributor. This table is stored in the distribution database.
這些存儲過程和表都是sql server 2000時代的產物,用于linked server相關操作。在2005里就已經depreciated。
2)后來分析了內部的調用邏輯,實際上只需要在distributor執行sp_addremotelogin就可以解決這個問題,沒有必要重建. 如果您以后遇到了下面這個錯誤,可以嘗試在distributor中執行sp_addremotelogin。
Could not connect to server 'SQL108W2K8R22' because 'distributor_admin' is not defined as a remote login at the server. Verify that you have specified the correct login name.
3)如果在移除publisher時遇到下面的錯誤,可以將distribution.. MSsubscriber_info的相關記錄刪除,然后再次嘗試。
Cannotdropserver'server1'becauseitisusedasaSubscribertoremotePublisher'serve2'inreplication.
4)您在SQL SERVER 2014版本的distributor中不會遇到第三個問題,這并因為不是sp_addDistributor或sp_dropdistpublisher在2014中有了邏輯上變更,而是在添加訂閱的時候,不會在向distribution.. MSsubscriber_info插入記錄。這樣sp_MSrepl_check_server就不會拋出異常了。
新聞熱點
疑難解答