방법: 트랜잭션 복제에 대한 대기 시간 측정 및 연결 유효성 검사(복제 Transact-SQL 프로그래밍)

트랜잭션 복제의 경우 서버가 연결되어 있는지를 확인하고 대기 시간을 측정할 수 있어야 합니다. 대기 시간은 게시자에서 변경된 내용이 구독자에 전파되기까지 경과되는 시간입니다. 자세한 내용은 모니터링(복제)을 참조하십시오. 이 정보는 복제 저장 프로시저를 사용하여 프로그래밍 방식으로 가져올 수 있습니다.

[!참고]

추적 프로그램 토큰 정보는 배포 데이터베이스의 기록 보존 기간에 의해 제어되는 다른 기록 데이터와 같은 시간 동안 유지됩니다. 보존 기간을 변경하려면 sp_changedistributiondb(Transact-SQL)를 사용하여 history_retention 속성 값을 변경합니다.

트랜잭션 게시에 추적 프로그램 토큰을 게시하려면

  1. (옵션) 게시 데이터베이스의 게시자에서 sp_helppublication(Transact-SQL)을 실행합니다. 해당 게시가 있는지 그리고 상태가 활성 상태인지 확인합니다.

  2. (옵션) 게시 데이터베이스의 게시자에서 sp_helpsubscription(Transact-SQL)을 실행합니다. 해당 구독이 있는지 그리고 상태가 활성 상태인지 확인합니다.

  3. 게시 데이터베이스의 게시자에서 sp_posttracertoken(Transact-SQL)을 실행하고 @publication을 지정합니다. @tracer_token_id 출력 매개 변수의 값을 확인합니다.

트랜잭션 복제에 대한 대기 시간을 확인하고 연결 유효성을 검사하려면

  1. 이전 절차를 따라 게시에 추적 프로그램 토큰을 게시합니다.

  2. 게시 데이터베이스의 게시자에서 sp_helptracertokens(Transact-SQL)를 실행하고 @publication을 지정합니다. 그러면 해당 게시에 게시된 모든 추적 프로그램 토큰의 목록이 반환됩니다. 결과 집합에서 원하는 tracer_id를 확인합니다.

  3. 게시 데이터베이스의 게시자에서 sp_helptracertokenhistory(Transact-SQL)를 실행하고 @publication을 지정하고 @tracer_id에 대해 2단계에서 얻은 추적 프로그램 토큰 ID를 지정합니다. 그러면 선택한 추적 프로그램 토큰에 대한 대기 시간 정보가 반환됩니다.

추적 프로그램 토큰을 제거하려면

  1. 게시 데이터베이스의 게시자에서 sp_helptracertokens(Transact-SQL)를 실행하고 @publication을 지정합니다. 그러면 해당 게시에 게시된 모든 추적 프로그램 토큰의 목록이 반환됩니다. 결과 집합에서 삭제할 추적 프로그램 토큰의 tracer_id를 확인합니다.

  2. 게시 데이터베이스의 게시자에서 sp_deletetracertokenhistory(Transact-SQL)를 실행하고 @publication을 지정하고 @tracer_id에 대해 2단계에서 얻은 삭제할 추적 프로그램 토큰 ID를 지정합니다.

이 예제에서는 추적 프로그램 토큰 레코드를 게시하고 게시된 추적 프로그램 토큰의 반환된 ID를 사용하여 대기 시간 정보를 봅니다.

DECLARE @publication AS sysname;
DECLARE @tokenID AS int;
SET @publication = N'AdvWorksProductTran'; 

USE [AdventureWorks]

-- Insert a new tracer token in the publication database.
EXEC sys.sp_posttracertoken 
  @publication = @publication,
  @tracer_token_id = @tokenID OUTPUT;
SELECT 'The ID of the new tracer token is ''' + 
    CONVERT(varchar,@tokenID) + '''.'
GO

-- Wait 10 seconds for the token to make it to the Subscriber.
WAITFOR DELAY '00:00:10';
GO

-- Get latency information for the last inserted token.
DECLARE @publication AS sysname;
DECLARE @tokenID AS int;
SET @publication = N'AdvWorksProductTran'; 

CREATE TABLE #tokens (tracer_id int, publisher_commit datetime)

-- Return tracer token information to a temp table.
INSERT #tokens (tracer_id, publisher_commit)
EXEC sys.sp_helptracertokens @publication = @publication;
SET @tokenID = (SELECT TOP 1 tracer_id FROM #tokens
ORDER BY publisher_commit DESC)
DROP TABLE #tokens

-- Get history for the tracer token.
EXEC sys.sp_helptracertokenhistory 
  @publication = @publication, 
  @tracer_id = @tokenID;
GO