Replication-view undistributed commands and estimated time required

Source: Internet
Author: User

When there is a replication delay, we can use the replication monitor to view the undistributed commands and estimated time required for each subscription, such:

You can use the following script to implement it:

-- View the commands and estimated time passed to the subscription -- execute 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. publisher,. publisher_db,. 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''' +. publisher + ''', @ publisher_db = n''' +. publisher_db + ''', @ publication = n''' +. publication + ''', @ subscriber = n''' + C. name + ''', @ subscriber_db = n''' + B. subscriber_db + ''', @ subscription_type = '+ Cast (B. subscription_type as varchar) as scripttxtinto # tmpsubscribersfrom DBO. revoke 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. publication_id = B. publication_id join sys. servers C (nolock) on B. subscriber_id = C. server_idwhere. 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 )--, pendingtransfercount bigint --, estimatedprocesstime bigint --) -- Create Table # tmpsinglependingresult -- (-- pendingtransfercount bigint --, estimatedprocesstime bigint --) -- ===================================================== ===========-- use a cursor to traverse declare @ publisher nvarchar (200 );; declare @ publisher_db nvarchar (200); declare @ publication nvarchar (200); declare @ subscriber nvarchar (200); declare @ subscriber_db nvarchar (200 ); declare @ brief nvarchar (200); declare @ scripttxt nvarchar (max); declare mycursor cursor forselect publisher, publisher_db, publication, subscriber, comment, subscription_type, comment # tmpsubscribers; open publish next from mycursor into @ publisher, @ publisher_db, @ publication, @ subscriber, @ subscriber_db, @ subscription_type, @ scripttxt; while @ fetch_status = 0 beginselect @ 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-view undistributed commands and estimated time required

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.