How do you monitor and troubleshoot SQL Server Agent job performance and failures across an entire server with many scheduled jobs?
Short answer
You can query the msdb system database's job history tables directly, such as sysjobhistory, to build custom reports showing job success rates, average duration, and failure trends over time, which is especially useful on a server with many jobs where manually checking each one…
Advertisement
AModel answer
You can query the msdb system database's job history tables directly, such as sysjobhistory, to build custom reports showing job success rates, average duration, and failure trends over time, which is especially useful on a server with many jobs where manually checking each one individually through the graphical interface would be impractical.
SELECT j.name, h.run_date, h.run_status, h.run_duration
FROM msdb.dbo.sysjobs j
JOIN msdb.dbo.sysjobhistory h ON j.job_id = h.job_id
WHERE h.step_id = 0
ORDER BY h.run_date DESC;Real-world example
A database administrator managing dozens of scheduled jobs across several servers builds a custom monitoring report querying sysjobhistory directly, quickly spotting jobs with declining success rates that need investigation.
Likely follow-ups
- What does a step_id of 0 represent in the sysjobhistory table?
- How do you consolidate job monitoring across multiple SQL Server instances?
Related topics