내가 사용하는 소수의 쿼리가 있습니다. 일반적인 개념은 정보가있는 테이블이며 catalog.operation_messages
120 (오류) 유형의 이벤트에 관심이 있다는 것입니다.
빌드하려는 쿼리의 강도에 따라 다음 두 파생 테이블도 관심이있을 수 있습니다.
--- http://technet.microsoft.com/en-us/library/ff877994.aspx
-- This query translates the message_type from SSISDB.catalog.operation_messages
-- into useful text
SELECT
D.message_type
, D.message_desc
FROM
(
VALUES
(-1,'Unknown')
, (120,'Error')
, (110,'Warning')
, (70,'Information')
, (10,'Pre-validate')
, (20,'Post-validate')
, (30,'Pre-execute')
, (40,'Post-execute')
, (60,'Progress')
, (50,'StatusChange')
, (100,'QueryCancel')
, (130,'TaskFailed')
, (90,'Diagnostic')
, (200,'Custom')
, (140,'DiagnosticEx Whenever an Execute Package task executes a child package, it logs this event. The event message consists of the parameter values passed to child packages. The value of the message column for DiagnosticEx is XML text.')
, (400,'NonDiagnostic')
, (80,'VariableValueChanged')
) D (message_type, message_desc);
-- Where was the error message generated?
SELECT
D.message_source_type
, D.message_source_desc
FROM
(
VALUES
(10,'Entry APIs, such as T-SQL and CLR Stored procedures')
, (20,'External process used to run package (ISServerExec.exe)')
, (30,'Package-level objects')
, (40,'Control Flow tasks')
, (50,'Control Flow containers')
, (60,'Data Flow task')
) D (message_source_type, message_source_desc);
이런 쿼리를 사용하여 오류에 대한 정보를 찾습니다. 어쩌면 나는 오류가 무엇인지 신경 쓰지 않을 것입니다 (질의 1). 다른 경우에는 실패한 모든 작업의 모든 활동을 알고 싶습니다 (질의 2). 일반적으로, 나는 게으르고 마지막 실패한 작업 (질의 3 및주의 사항)에 대한 모든 정보를보고 싶습니다.
-- http://msdn.microsoft.com/en-us/library/ff877994.aspx
-- Find all error messages
SELECT
OM.operation_message_id
, OM.operation_id
, OM.message_time
, OM.message_type
, OM.message_source_type
, OM.message
, OM.extended_info_id
FROM
catalog.operation_messages AS OM
WHERE
OM.message_type = 120;
-- Generate all the messages associated to failing operations
SELECT
OM.operation_message_id
, OM.operation_id
, OM.message_time
, OM.message_type
, OM.message_source_type
, OM.message
, OM.extended_info_id
FROM
catalog.operation_messages AS OM
INNER JOIN
(
-- Find failing operations
SELECT DISTINCT
OM.operation_id
FROM
catalog.operation_messages AS OM
WHERE
OM.message_type = 120
) D
ON D.operation_id = OM.operation_id;
-- Find all messages associated to the last failing run
SELECT
OM.operation_message_id
, OM.operation_id
, OM.message_time
, OM.message_type
, OM.message_source_type
, OM.message
, OM.extended_info_id
FROM
catalog.operation_messages AS OM
WHERE
OM.operation_id =
(
-- Find the last failing operation
-- lazy assumption that biggest operation
-- id is last. Could be incorrect if a long
-- running process fails after a quick process
-- has also failed
SELECT
MAX(OM.operation_id)
FROM
catalog.operation_messages AS OM
WHERE
OM.message_type = 120
);
어쩌면 나는 게으르고 실패한 경우 팀이 수행 한 것처럼이 정보를 찾아보고 싶지 않습니다. 요청시 실행되는 SQL 에이전트 작업이 있고 오류 발생시 해당 작업을 실행하도록 SSIS 패키지를 실행하는 작업이 있습니다.
DECLARE
@profile_name sysname = 'SQLAdmins'
, @recipients varchar(max) = 'billinkc@kfc.com'
, @copy_recipients varchar(max) = NULL
, @blind_copy_recipients varchar(max) = NULL
, @subject nvarchar(255) = 'failed package test'
, @body nvarchar(max) = 'Stuff has failed, fix please'
, @body_format varchar(20) = NULL
, @importance varchar(6) = 'NORMAL'
, @sensitivity varchar(12) = 'NORMAL'
, @file_attachments nvarchar(max) = NULL
, @query nvarchar(max) = N'
SELECT
O.object_name AS FailingPackageName
, O.object_id
, O.caller_name
, O.server_name
, O.operation_id
, OM.message_time
, EM.message_desc
, D.message_source_desc
, OM.message
FROM
SSISDB.catalog.operation_messages AS OM
INNER JOIN
SSISDB.catalog.operations AS O
ON O.operation_id = OM.operation_id
INNER JOIN
(
VALUES
(-1,''Unknown'')
, (120,''Error'')
, (110,''Warning'')
, (70,''Information'')
, (10,''Pre-validate'')
, (20,''Post-validate'')
, (30,''Pre-execute'')
, (40,''Post-execute'')
, (60,''Progress'')
, (50,''StatusChange'')
, (100,''QueryCancel'')
, (130,''TaskFailed'')
, (90,''Diagnostic'')
, (200,''Custom'')
, (140,''DiagnosticEx Whenever an Execute Package task executes a child package, it logs this event. The event message consists of the parameter values passed to child packages. The value of the message column for DiagnosticEx is XML text.'')
, (400,''NonDiagnostic'')
, (80,''VariableValueChanged'')
) EM (message_type, message_desc)
ON EM.message_type = OM.message_type
INNER JOIN
(
VALUES
(10,''Entry APIs, such as T-SQL and CLR Stored procedures'')
, (20,''External process used to run package (ISServerExec.exe)'')
, (30,''Package-level objects'')
, (40,''Control Flow tasks'')
, (50,''Control Flow containers'')
, (60,''Data Flow task'')
) D (message_source_type, message_source_desc)
ON D.message_source_type = OM.message_source_type
WHERE
OM.operation_id =
(
SELECT
MAX(OM.operation_id)
FROM
SSISDB.catalog.operation_messages AS OM
WHERE
OM.message_type = 120
)
AND OM.message_type IN (120, 130);
'
, @execute_query_database sysname = NULL
, @attach_query_result_as_file bit = 0
, @query_attachment_filename nvarchar(260) = NULL
, @query_result_header bit = 1
, @query_result_width int = 256
, @query_result_separator char(1) = char(13)
, @exclude_query_output bit = 0
, @append_query_error bit = 0
, @query_no_truncate bit = 0
, @query_result_no_padding bit = 0
, @mailitem_id int = NULL
, @from_address varchar(max) = NULL
, @reply_to varchar(max) = NULL;
-- Send email about the failure
EXECUTE msdb.dbo.sp_send_dbmail
@profile_name
, @recipients
, @copy_recipients
, @blind_copy_recipients
, @subject
, @body
, @body_format
, @importance
, @sensitivity
, @file_attachments
, @query
, @execute_query_database
, @attach_query_result_as_file
, @query_attachment_filename
, @query_result_header
, @query_result_width
, @query_result_separator
, @exclude_query_output
, @append_query_error
, @query_no_truncate
, @query_result_no_padding
, @mailitem_id OUTPUT
, @from_address
, @reply_to;
원하는대로 조정
MSG.message_type IN (120, 130)