首页 > 代码库 > Replication--查看未分发命令和预估所需时间
Replication--查看未分发命令和预估所需时间
当复制有延迟时,我们可以使用复制监视器来查看各订阅的未分发命令书和预估所需时间,如下图:
用以下的脚本可以帮我们来实现:
--查看为传递到订阅的命令和预估时间--在分发服务器执行 IF(OBJECT_ID(‘tempdb..#tmpSubscribers‘) IS NOT NULL)BEGINDROP TABLE #tmpSubscribersENDGO--IF(OBJECT_ID(‘tempdb..#tmpPendingResult‘) IS NOT NULL)--BEGIN--DROP TABLE #tmpPendingResult--END--GO--IF(OBJECT_ID(‘tempdb..#tmpSinglePendingResult‘) IS NOT NULL)--BEGIN--DROP TABLE #tmpSinglePendingResult--ENDGOUSE distribution GOSELECT a.publisher,a.publisher_db,a.publication,c.name as subscriber,b.subscriber_db as subscriber_db,CAST(b.subscription_type AS VARCHAR) as subscription_type,‘EXEC distribution.sys.sp_replmonitorsubscriptionpendingcmds @publisher = N‘‘‘ + a.publisher + ‘‘‘, @publisher_db = N‘‘‘ + a.publisher_db + ‘‘‘, @publication = N‘‘‘ + a.publication + ‘‘‘, @subscriber = N‘‘‘ + c.name + ‘‘‘, @subscriber_db = N‘‘‘ + b.subscriber_db + ‘‘‘, @subscription_type =‘ + CAST(b.subscription_type AS VARCHAR) AS ScriptTxtINTO #tmpSubscribersFROM dbo.MSreplication_monitordata a ( NOLOCK ) JOIN ( SELECT publication_id , subscriber_id , subscriber_db , subscription_type FROM MSsubscriptions (NOLOCK) GROUP BY publication_id , subscriber_id , subscriber_db , subscription_type ) b ON a.publication_id = b.publication_id JOIN sys.servers c ( NOLOCK ) ON b.subscriber_id = c.server_idWHERE a.agent_type = 1--====================================================--CREATE TABLE #tmpPendingResult--(--publisher NVARCHAR(200)--,publisher_db NVARCHAR(200)--,publication NVARCHAR(200)--,subscriber NVARCHAR(200)--,subscriber_db NVARCHAR(200)--,subscription_type NVARCHAR(200)--,pendingcmdcount BIGINT--,estimatedprocesstime BIGINT--)--CREATE TABLE #tmpSinglePendingResult--(--pendingcmdcount BIGINT--,estimatedprocesstime BIGINT--)--==================================================--使用游标遍历DECLARE @publisher NVARCHAR(200);;DECLARE @publisher_db NVARCHAR(200);DECLARE @publication NVARCHAR(200);DECLARE @subscriber NVARCHAR(200);;DECLARE @subscriber_db NVARCHAR(200);DECLARE @subscription_type NVARCHAR(200);DECLARE @ScriptTxt NVARCHAR(MAX);DECLARE MyCursor CURSOR FORSELECT publisher,publisher_db ,publication,subscriber,subscriber_db,subscription_type,ScriptTxtFROM #tmpSubscribers;OPEN MyCursorFETCH NEXT FROM MyCursor INTO @publisher,@publisher_db ,@publication,@subscriber,@subscriber_db,@subscription_type,@ScriptTxt;WHILE @@FETCH_STATUS = 0BEGINSELECT @publisher AS publisher,@publisher_db AS publisher_db,@publication AS publication,@subscriber AS subscriber,@subscriber_db AS subscriber_db,@subscription_type AS subscription_type,@ScriptTxt;EXEC(@ScriptTxt)FETCH NEXT FROM MyCursor INTO @publisher,@publisher_db ,@publication,@subscriber,@subscriber_db,@subscription_type,@ScriptTxt;ENDCLOSE MyCursorDEALLOCATE MyCursor
Replication--查看未分发命令和预估所需时间
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。