分享方式:


sp_helptracertokens (Transact-SQL)

適用於:SQL ServerAzure SQL 受控執行個體

針對插入發行集以判斷延遲的每個追蹤標記,各傳回一個數據列。 這個預存程式會在發行集資料庫的發行者端或散發資料庫的散發者端執行。

Transact-SQL 語法慣例

語法

sp_helptracertokens
    [ @publication = ] N'publication'
    [ , [ @publisher = ] N'publisher' ]
    [ , [ @publisher_db = ] N'publisher_db' ]
[ ; ]

引數

[ @publication = ] N'publication'

插入追蹤標記的發行集名稱。 @publication為 sysname,沒有預設值。

[ @publisher = ] N'publisher'

發行者的名稱。 @publisher為 sysname,預設值為 NULL

@publisher應該只針對非 SQL Server 發行者指定。

[ @publisher_db = ] N'publisher_db'

發行集資料庫的名稱。 @publisher_db為 sysname,預設值為 NULL如果在發行者端執行預存程式,則會忽略@publisher_db

結果集

資料行名稱 資料類型 描述
tracer_id int 識別追蹤令牌記錄。
publisher_commit datetime 發行集資料庫中發行者端認可令牌記錄的日期和時間。

傳回碼值

0 (成功) 或 1 (失敗)。

備註

sp_helptracertokens 用於事務複製。

sp_helptracertokens用來在執行sp_helptracertokenhistory取得追蹤令牌標識碼。

範例

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

USE [AdventureWorks2022]

-- 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

權限

只有系統管理員固定伺服器角色的成員、發行集資料庫中db_owner固定資料庫角色,db_owner散發資料庫中的固定資料庫或 replmonitor 角色可以執行 sp_helptracertokenhistory