如何监控 SQL Server 中计划作业的状态
执行计划作业的存储过程时,监控进度至关重要这些工作,以确保其及时完成和成功。本文将指导您完成确定 SQL Server 中计划作业状态的步骤:
尚未启动的计划作业列表
SELECT name, schedule_next_run FROM sysjobs_view WHERE next_run_date > GETDATE()
正在运行的作业列表
SELECT job.name, job_id, activity.run_requested_date FROM msdb.dbo.sysjobs_view job JOIN msdb.dbo.sysjobactivity activity ON job.job_id = activity.job_id WHERE DATEADD(HOUR, -1, GETDATE()) < activity.run_requested_date AND activity.run_status <> 2
作业完成状态
SELECT job.name, job.job_id, job.originating_server, activity.run_requested_date, DATEDIFF( SECOND, activity.run_requested_date, GETDATE() ) as Elapsed FROM msdb.dbo.sysjobs_view job JOIN msdb.dbo.sysjobactivity activity ON job.job_id = activity.job_id JOIN msdb.dbo.syssessions sess ON sess.session_id = activity.session_id JOIN ( SELECT MAX( agent_start_date ) AS max_agent_start_date FROM msdb.dbo.syssessions ) sess_max ON sess.agent_start_date = sess_max.max_agent_start_date WHERE run_requested_date IS NOT NULL AND stop_execution_date IS NULL
以上是如何跟踪 SQL Server 中计划作业的状态?的详细内容。更多信息请关注PHP中文网其他相关文章!