1

當我在複製的出版物上有延遲時,我會添加一個令牌並觀察它。 有沒有任何方法可以在不使用標記的情況下解決複製延遲問題? 這是SQL Server 2005-事務複製。有沒有辦法在不使用令牌的情況下監視事務複製延遲?

+0

爲什麼不張貼標誌上sp_post_tracertoken定期?然後,您可以查看複製監視器中所有令牌的進度,並知道哪一個最後一次傳送,需要多長時間才能到達,等等。 – 2014-09-29 01:16:36

回答

0

我發現這個鏈接約checking replication latency using T-SQL 並創建了我的環境中的過程,它的工作非常好。

這裏是過程的代碼,在評論中,我是如何利用它的。

USE [MY_PUBLICATION_DATABASE] 
-- this procedure is to be created inside the publication database 
GO 
Create Procedure dbo.dba_replicationLatencyGet_sp 

     /* Declare Parameters */ 
      @publicationToTest sysname  = N'yourPublicationName' 
     , @replicationDelay varchar(10) = N'00:00:30' 
     , @iterations  int   = 5 
     , @iterationDelay varchar(10) = N'00:00:30' 
     , @deleteTokens  bit   = 1 
     , @deleteTempTable bit   = 1 
As 
/********************************************************************************* 
    Name:  dba_replicationLatencyGet_sp 

    Author:  Michelle F. Ufford 

    Purpose: Retrieves the amount of replication latency in seconds 

    Notes:  Default settings will run 1 test every minute for 5 minutes. 

       @publicationToTest = change the default to your publication 

       @replicationDelay = how long to wait for the token to replicate; 
        probably should not set to anything less than 10 (in seconds) 

       @iterations = how many tokens you want to test 

       @iterationDelay = how long to wait between sending test tokens 
        (in seconds) 

       @deleteTokens = whether you want to retain tokens when done 

       @deleteTempTable = whether or not to retain the temporary table 
        when done. Data stored to ##tokenResults; set @deleteTempTable 
        flag to 0 if you do not want to delete when done. 

    Called by: DBA 
    ---------------------------------------------------------------------------- 

    Marcelo Miorelli 
    01-Oct-2014 wednesday 
    I found this wonderful procedure at this site: 
    http://sqlfool.com/2008/11/checking-replication-latency-with-t-sql/ 

    I have tested it 
    Server: SQLWEBLON1.DEV.BODEN.LOCAL 
    DB: AUAccount 

    I had to create the procedure in the Publisher database, and run it from there. 

     Exec dbo.dba_replicationLatencyGet_sp 
      @publicationToTest = N'AUAccount' 
     , @replicationDelay  = N'00:00:05' 
     , @iterations   = 1 
     , @iterationDelay  = N'00:00:05' 
     , @deleteTokens   = 1 
     , @deleteTempTable  = 1; 

    "La observación y la percepción son dos cosas separadas; 
    el ojo que observa es más fuerte, el ojo que percibe es más débil. " 
    "el libro de los 5 anillos" 
    Mushashi 

    ---------------------------------------------------------------------------- 
    Date  Initials Description 
    ---------------------------------------------------------------------------- 
    2008-11-20 MFU  Initial Release 
********************************************************************************* 
    Exec dbo.dba_replicationLatencyGet_sp 
      @publicationToTest = N'yourPublicationName' 
     , @replicationDelay  = N'00:00:05' 
     , @iterations   = 1 
     , @iterationDelay  = N'00:00:05' 
     , @deleteTokens   = 1 
     , @deleteTempTable  = 1; 
*********************************************************************************/ 

Set NoCount On; 
Set XACT_Abort On; 

Begin 

    /* Declare Variables */ 
    Declare @currentIteration int 
      , @tokenID   bigint 
      , @currentDateTime smalldatetime; 

    If Object_ID('tempdb.dbo.##tokenResults') Is Null 
    Begin 
     Create Table ##tokenResults 
         (iteration   int    Null 
         , tracer_id   int    Null 
         , distributor_latency int    Null 
         , subscriber   varchar(1000) Null 
         , subscriber_db  varchar(1000) Null 
         , subscriber_latency int    Null 
         , overall_latency  int    Null); 
    End; 

    /* Initialize our variables */ 
    Select @currentIteration = 0 
     , @currentDateTime = GetDate(); 

    While @currentIteration < @iterations 
    Begin 

     /* Insert a new tracer token in the publication database */ 
     Execute sys.sp_postTracerToken 
      @publication = @publicationToTest, 
      @tracer_token_id = @tokenID OutPut; 

     /* Give a few seconds to allow the record to reach the subscriber */ 
     WaitFor Delay @replicationDelay; 

     /* Store our results in a temp table for retrieval later */ 
     Insert Into ##tokenResults 
     (
      distributor_latency 
      , subscriber 
      , subscriber_db 
      , subscriber_latency 
      , overall_latency 
     ) 
     Execute sys.sp_helpTracerTokenHistory @publicationToTest, @tokenID; 

     /* Assign the iteration and token id to the results for easier investigation */ 
     Update ##tokenResults 
     Set iteration = @currentIteration + 1 
      , tracer_id = @tokenID 
     Where iteration Is Null; 

     /* Wait for the specified time period before creating another token */ 
     WaitFor Delay @iterationDelay; 

     /* Avoid endless looping... :) */ 
     Set @currentIteration = @currentIteration + 1; 

    End; 

    Select * From ##tokenResults; 

    If @deleteTempTable = 1 
    Begin 
     Drop Table ##tokenResults; 
    End; 

    If @deleteTokens = 1 
    Begin 
     Execute sp_deleteTracerTokenHistory @publication = @publicationToTest, @cutoff_date = @currentDateTime; 
    End; 

    Set NoCount Off; 
    Return 0; 
End 
Go 
1

您可以通過使用和複製日期時間列並使用發佈服務器上每X分鐘的當前時間戳更新它來推出自己的解決方案。然後,在訂閱服務器上,您可以每X分鐘運行一次作業,並將日期時間列值與當前時間進行比較,並在差異大於X分鐘時發出警報。

+0

+1因爲它非常合乎邏輯 – 2014-10-01 15:54:44

相關問題