我们使用事务和推送复制。每天晚上,在数据导入之后,将使用以下命令初始化2个复制目标。
USE [dbImport]
-- Execute at the Publisher to reinitialize the push subscription.
EXEC sp_reinitsubscription
@subscriber = N'Target2',
@destination_db = N'dbImport',
@publication = N'dbImportPub';
GO
-- Start the Distribution Agent.
USE msdb
EXEC sp_start_job @job_name = 'Source1-dbImport-dbImport-Pub-Target2-35'
GO下一步等待15分钟,因为这种重新初始化通常需要10分钟,我们增加了更多的时间,以更安全的一面。有时,重新初始化需要稍长一点15分钟,因此在下一步目标上创建的索引是不正确的。
我无法检查是否停止分发作业,因为在事务复制中,它从不停止。
如何等待target2上重新初始化(所有脚本和数据的初始推送)结束(然后添加索引“准时”)?
斯特凡
发布于 2015-11-03 07:21:20
由于我不喜欢“不需要”的工作,并且希望以一种简单的方式处理事情,所以我创建了另一个解决方案。
以下代码在复制初始化并在具有与postfix "-59“关联作业名的订阅服务器上启动后的作业步骤中使用。
WHILE 0 = (SELECT COUNT(1) FROM distribution.dbo.MSdistribution_history
-- search for suffix of the SQL-job, here '59'
WHERE (agent_id = 59)
-- the following text appears in the table once the snapshot-transfer is complete
AND (comments LIKE N'%The snapshot in subfolder% was transfered in % milliseconds%')
-- here I search for the last start time of our import job
AND (time > (SELECT ja.start_execution_date
FROM msdb.dbo.sysjobactivity ja
LEFT JOIN msdb.dbo.sysjobhistory jh ON ja.job_history_id = jh.instance_id
JOIN msdb.dbo.sysjobs j ON ja.job_id = j.job_id
WHERE ja.session_id = (SELECT TOP 1 session_id FROM msdb.dbo.syssessions ORDER BY agent_start_date DESC)
AND start_execution_date is not null
AND j.name = 'data import production')))
BEGIN
WAITFOR DELAY '00:00:10';
END也许您同意这种解决方案更容易在许多作业中集成,并保持sql作业目录的清晰和整洁。
https://dba.stackexchange.com/questions/112504
复制相似问题