SQL Server维护计划历史记录检查状态



如果维护计划仍在运行,我需要监控维护计划,我找到了一个旧帖子(感谢Don SQL Server维护计划历史记录检查成功或失败(来查询日志并获得作业结果,但这只会在完成后给出结果:

SELECT
    mp.name AS [MTX Plan Name],
    msp.subplan_name AS [Sub Plan Name],    
    mpl.start_time AS [JobStart],
    mpl.end_time AS [JobEnd],
    mpl.succeeded AS [JobSucceeded]
FROM
    msdb.dbo.sysmaintplan_plans mp
    INNER JOIN msdb.dbo.sysmaintplan_subplans msp ON mp.id = msp.plan_id
    INNER JOIN msdb.dbo.sysmaintplan_log mpl ON msp.subplan_id = mpl.subplan_id
        AND mpl.task_detail_id = -- Get the most recent run for this database
            (SELECT TOP 1 ld.task_detail_id 
            FROM msdb.dbo.sysmaintplan_logdetail ld
            WHERE ld.command LIKE ('%['+db_name()+']%')
            ORDER BY ld.start_time DESC)

此查询将为您提供与维护计划相关的活动/正在运行的作业。无论有什么,都意味着它现在正在运行

SELECT sj.name
   , sja.*
FROM msdb.dbo.sysjobactivity AS sja
INNER JOIN msdb.dbo.sysjobs AS sj ON sja.job_id = sj.job_id
WHERE sja.start_execution_date IS NOT NULL
   AND sja.stop_execution_date IS NULL
   AND sja.job_id IN (SELECT job_id FROM msdb.dbo.sysmaintplan_subplans)

如果您需要集成到PRTG 的帮助,请告诉我

相关内容

  • 没有找到相关文章

最新更新