如何監控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中文網其他相關文章!