有没有办法在不使用令牌的情况下监控事务复制延迟?

时间:2014-09-28 19:40:27

标签: sql-server sql-server-2005 replication database-replication

当我在复制的出版物上出现延迟时,我会尝试添加令牌并观看它。 有没有办法在不使用令牌的情况下排除复制延迟? 这是SQL Server 2005 - 事务复制。

2 个答案:

答案 0 :(得分:1)

您可以使用并复制日期时间列并使用发布服务器上每X分钟的当前时间戳更新它,从而推出自己的解决方案。然后,在订阅服务器上,您可以每隔X分钟运行一个作业,并将日期时间列值与当前时间进行比较,并在差异大于X分钟时发出警报。

答案 1 :(得分: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