We have been asked to report on the health of our SQL jobs. I am having trouble understanding the run_status
column in dbo.sysjobhistory
. The MSDB page for sysjobhistory gives this description:
Status of the job execution:
- 0 = Failed
- 1 = Succeeded
- 2 = Retry
- 3 = Canceled
What events cause each status code?
Here is what I have done to attempt to produce each status code. I was able to reproduce...
- 0 (Failed) by writing SQL that throws an error.
- For example, step 1 is
SELECT SELECT
- For example, step 1 is
- 1 (Succeeded) by writing SQL that succeeds.
- For example, step 1 is
SELECT 1
- For example, step 1 is
- 3 (Cancelled) by stopping a job while it was running
- 4 (In progress) by querying sysjobshistory while a job was running
I know a way produce 0's, 1's, 3's, and 4's, but I don't know all of the ways to produce them, and I have no idea how to cause a 2.
The health of our jobs is binary. We are either healthy or not healthy, because the end user does not want to see anything more granular than that on their dashboard. That is why I am asking this question - I have to interpret the status codes and run durations and draw a single, binary conclusion about the health of the SQL jobs. The problem is that MSDN doesn't explain what the status codes mean, or more importantly, what events might cause them.
For example, if a user cancels a job (resulting in a run_status of 3), we might decide that we don't care and just report that we are healthy. However, if a job gets cancelled because of some other event, we might care about that.