sp_posttracertoken (Transact-SQL)
适用于:SQL Server
此过程将跟踪令牌发布到发布服务器上的事务日志,并开始跟踪滞后时间统计信息的过程。 如果将跟踪令牌写入了事务日志,则当日志读取器代理选中该令牌,以及分发代理应用该令牌时,均会记录信息。 此存储过程在发布服务器上对发布数据库执行。 有关详细信息,请参阅 为事务复制测量滞后时间和验证连接。
语法
sp_posttracertoken [ @publication = ] 'publication'
[ , [ @tracer_token_id = ] tracer_token_id OUTPUT
[ , [ @publisher = ] 'publisher'
参数
[ @publication = ] 'publication'
要测量延迟的发布的名称。 publication 为 sysname,无默认值。
[ @tracer_token_id = ] _tracer_token_id OUTPUT
插入的跟踪令牌的 ID。 tracer_token_id默认值为 NULL,它是 OUTPUT 参数。 此值可用于执行sp_helptracertokenhistory(Transact-SQL)或sp_deletetracertokenhistory(Transact-SQL),而无需先执行sp_helptracertokens(Transact-SQL)。
[ @publisher = ] 'publisher'
指定非Microsoft SQL Server 发布服务器。 publisher 为 sysname,默认值为 NULL,不应为 SQL Server 发布服务器指定。
返回代码值
0 (成功) 或 1 (失败)
注解
sp_posttracertoken用于事务复制。
示例
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
权限
只有 sysadmin 固定服务器角色的成员或db_owner固定数据库角色的成员才能执行sp_posttracertoken。