Agent History5:Job Activity Monitor 查看Job History的代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Agent History5:Job Activity Monitor 查看Job History的代码相关的知识,希望对你有一定的参考价值。
可以使用这两个SP快速查看Job执行的状态,而不用打开Monitory。
1,查看Job 执行结果
exec [msdb].[dbo].[sp_help_job]
msdb中该dbo.sp_help_job的参数如下:
ALTER PROCEDURE [dbo].[sp_help_job] -- Individual job parameters @job_id UNIQUEIDENTIFIER = NULL, -- If provided should NOT also provide job_name @job_name sysname = NULL, -- If provided should NOT also provide job_id @job_aspect VARCHAR(9) = NULL, -- JOB, STEPS, SCHEDULES, TARGETS or ALL -- Job set parameters @job_type VARCHAR(12) = NULL, -- LOCAL or MULTI-SERVER @owner_login_name sysname = NULL, @subsystem NVARCHAR(40) = NULL, @category_name sysname = NULL, @enabled TINYINT = NULL, @execution_status INT = NULL, -- 1 = Executing, 2 = Waiting For Thread, 3 = Between Retries, 4 = Idle, 5 = Suspended, 6 = [obsolete], 7 = PerformingCompletionActions @date_comparator CHAR(1) = NULL, -- >, < or = @date_created DATETIME = NULL, @date_last_modified DATETIME = NULL, @description NVARCHAR(512) = NULL -- We do a LIKE on this so it can include wildcards AS
2,查看Job Step
declare @tmp_sp_help_jobhistory table ( instance_id int null, job_id uniqueidentifier null, job_name sysname null, step_id int null, step_name sysname null, sql_message_id int null, sql_severity int null, message nvarchar(4000) null, run_status int null, run_date int null, run_time int null, run_duration int null, operator_emailed sysname null, operator_netsent sysname null, operator_paged sysname null, retries_attempted int null, server sysname null ) insert into @tmp_sp_help_jobhistory exec msdb.dbo.sp_help_jobhistory @job_id = ‘af5eb80e-ef1e-4f2c-adb3-a45bfc2c3f57‘, @mode=‘FULL‘ SELECT tshj.instance_id AS [InstanceID], tshj.sql_message_id AS [SqlMessageID], tshj.message AS [Message], tshj.step_id AS [StepID], tshj.step_name AS [StepName], tshj.sql_severity AS [SqlSeverity], tshj.job_id AS [JobID], tshj.job_name AS [JobName], tshj.run_status AS [RunStatus], CASE tshj.run_date WHEN 0 THEN NULL ELSE convert(datetime, stuff(stuff(cast(tshj.run_date as nchar(8)), 7, 0, ‘-‘), 5, 0, ‘-‘) + N‘ ‘ + stuff(stuff(substring(cast(1000000 + tshj.run_time as nchar(7)), 2, 6), 5, 0, ‘:‘), 3, 0, ‘:‘), 120) END AS [RunDate], tshj.run_duration AS [RunDuration], tshj.operator_emailed AS [OperatorEmailed], tshj.operator_netsent AS [OperatorNetsent], tshj.operator_paged AS [OperatorPaged], tshj.retries_attempted AS [RetriesAttempted], tshj.server AS [Server], getdate() as [CurrentDate] FROM @tmp_sp_help_jobhistory as tshj ORDER BY [InstanceID] ASC
msdb中 dbo.sp_help_jobhistory的参数如下:
ALTER PROCEDURE [dbo].[sp_help_jobhistory] @job_id UNIQUEIDENTIFIER = NULL, @job_name sysname = NULL, @step_id INT = NULL, @sql_message_id INT = NULL, @sql_severity INT = NULL, @start_run_date INT = NULL, -- YYYYMMDD @end_run_date INT = NULL, -- YYYYMMDD @start_run_time INT = NULL, -- HHMMSS @end_run_time INT = NULL, -- HHMMSS @minimum_run_duration INT = NULL, -- HHMMSS @run_status INT = NULL, -- SQLAGENT_EXEC_X code @minimum_retries INT = NULL, @oldest_first INT = 0, -- Or 1 @server sysname = NULL, @mode VARCHAR(7) = ‘SUMMARY‘ -- Or ‘FULL‘ or ‘SEM‘
以上是关于Agent History5:Job Activity Monitor 查看Job History的代码的主要内容,如果未能解决你的问题,请参考以下文章
开源分布式Job系统,调度与业务分离-HttpJob.Agent组件介绍以及如何使用
SQLServer · BUG分析 · Agent 链接泄露分析(转载)
How to automatic process SSAS cube using SQL Server agent job
SQL Agent Job 报“Access to the remote server is denied because the current security context is