About Me

Barking, Essex, United Kingdom
MCITP DBA ,MCITP BI & Oracle OCP 11G

Tuesday, February 17, 2015

Monitor the Agent jobs

EXEC msdb.dbo.sp_help_job @Job_name = 'Purge_master'

On the Current_Execution_Status , the below value indicates the status.

1 = Executing.
2 = Waiting for thread.
3 = Between retries.
4 = Idle.
5 = Suspended.
7 = Performing completion actions.

On the last_run_outcome  it defines Outcome of the job the last time it ran and the values are listed below.
0 = Failed
1 = Succeeded
3 = Canceled

5 = Unknown

SELECT
    SJ.NAME AS [Job Name]
    ,RUN_STATUS AS [Run Status]
    ,MAX(msdb.DBO.AGENT_DATETIME(RUN_DATE, RUN_TIME)) AS [Last Time Job Ran On]
       into #jobstatus
FROM
msdb.dbo.SYSJOBS SJ
 LEFT OUTER JOIN msdb.dbo.SYSJOBHISTORY JH
 ON SJ.job_id = JH.job_id
 WHERE JH.step_id = 0
            AND jh.run_status = 1 and SJ.NAME ='IndexOptimize - USER_DATABASES' and RUN_STATUS=1
                GROUP BY SJ.name, JH.run_status
                    ORDER BY [Last Time Job Ran On] DESC


No comments:

Post a Comment