새소식

반응형
Database/MSSQL Server

쿼리를 이용한 JOB 스케줄러 상세보기

  • -
반응형

이번에 모니터링 시스템을 만들면서 이것 저것 수집하다 보니, 쿼리를 이용한 Job 스케줄러의 상세정보를 보기 힘들다는 사실을 알았습니다.

그래서, 영문자료를 토대로 한글화하여, 쿼리를 만들었습니다.

 

결과는 다음과 같은 형태로 나타납니다.

 

제가 필요한 정보만 약간 변형하여, 하였으므로, 필요에 따라서 바뀌시면 좋을 것 같습니다.

 

SELECT [jobs].name as [jobname]
    , description
    , CASE  convert(nvarchar(3),[sSCH].[enabled])
        WHEN 1 THEN 'Y'
        WHEN 0 THEN 'N'
      END AS [IsEnabled]
    , CASE 
        WHEN convert(nvarchar(3),[freq_type],3= 64 THEN 'SQL Server 시작 시 마다'
        WHEN convert(nvarchar(3),[freq_type],3= 128 THEN '서버가 유휴 할때마다'
        WHEN convert(nvarchar(3),[freq_type],3) IN (4,8,16,32) THEN '되풀이'
        WHEN convert(nvarchar(3),[freq_type],3)  = 1 THEN '한번만'
      END [ScheduleType]
    , CASE convert(nvarchar(3),[freq_type],3
        WHEN 1 THEN '1번'
        WHEN 4 THEN '매일'
        WHEN 8 THEN '매주'
        WHEN 16 THEN '매월'
        WHEN 32 THEN '매월'
        WHEN 64 THEN 'SQL Server 시작 시 마다'
        WHEN 128 THEN '서버가 유휴 할때마다'
      END [Occurrence]
    , CASE convert(nvarchar(3),[freq_type],3
        WHEN 4 THEN '실행주기 : ' + CAST([freq_interval] AS VARCHAR(3)) + ' 일(s)'
        WHEN 8 THEN '실행주기 : ' + CAST([freq_recurrence_factor] AS VARCHAR(3)) 
                    + ' 주(s) 매주'
                    + CASE WHEN [freq_interval] & 1 = 1 THEN '일' ELSE '' END
                    + CASE WHEN [freq_interval] & 2 = 2 THEN ', 월' ELSE '' END
                    + CASE WHEN [freq_interval] & 4 = 4 THEN ', 화' ELSE '' END
                    + CASE WHEN [freq_interval] & 8 = 8 THEN ', 수' ELSE '' END
                    + CASE WHEN [freq_interval] & 16 = 16 THEN ', 목' ELSE '' END
                    + CASE WHEN [freq_interval] & 32 = 32 THEN ', 금' ELSE '' END
                    + CASE WHEN [freq_interval] & 64 = 64 THEN ', 토' ELSE '' END
        WHEN 16 THEN '하루 한번 ' + CAST([freq_interval] AS VARCHAR(3)) 
                     + ' 모든 '
                     + CAST([freq_recurrence_factor] AS VARCHAR(3)) + ' 월(S)'
        WHEN 32 THEN '발생 '
                     + CASE [freq_relative_interval]
                        WHEN 1 THEN '첫째'
                        WHEN 2 THEN '둘째'
                        WHEN 4 THEN '셋째'
                        WHEN 8 THEN '넷째'
                        WHEN 16 THEN '마지막'
                       END
                     + ' ' 
                     + CASE [freq_interval]
                        WHEN 1 THEN '일'
                        WHEN 2 THEN '월'
                        WHEN 3 THEN '화'
                        WHEN 4 THEN '수'
                        WHEN 5 THEN '목'
                        WHEN 6 THEN '금'
                        WHEN 7 THEN '토'
                        WHEN 8 THEN '일'
                        WHEN 9 THEN '평일'
                        WHEN 10 THEN '주말'
                       END
                     + ' 모든 ' + CAST([freq_recurrence_factor] AS VARCHAR(3)) 
                     + ' 월(s)'
      END AS [Recurrence]
    , CASE convert(nvarchar(3),[freq_subday_type],3)  
        WHEN 1 THEN '매일 한번 ' 
              + STUFF(
                 STUFF(RIGHT('000000' + CAST([active_start_time] AS VARCHAR(6)), 6)
                                , 30':')
                            , 60':')
        WHEN 2 THEN '주기적 발생 ' 
                    + CAST([freq_subday_interval] AS VARCHAR(3)) + ' 초(s) 간격 ' 
                    + STUFF(
                   STUFF(RIGHT('000000' + CAST([active_start_time] AS VARCHAR(6)), 6)
                                , 30':')
                            , 60':')
                    + ' & ' 
                    + STUFF(
                    STUFF(RIGHT('000000' + CAST([active_end_time] AS VARCHAR(6)), 6)
                                , 30':')
                            , 60':')
        WHEN 4 THEN '주기적 발생 ' 
                    + CAST([freq_subday_interval] AS VARCHAR(3)) + ' 분(s) 간격 ' 
                    + STUFF(
                   STUFF(RIGHT('000000' + CAST([active_start_time] AS VARCHAR(6)), 6)
                                , 30':')
                            , 60':')
                    + ' & ' 
                    + STUFF(
                    STUFF(RIGHT('000000' + CAST([active_end_time] AS VARCHAR(6)), 6)
                                , 30':')
                            , 60':')
        WHEN 8 THEN '주기적 발생 ' 
                    + CAST([freq_subday_interval] AS VARCHAR(3)) + ' 시간(s) 간격 ' 
                    + STUFF(
                    STUFF(RIGHT('000000' + CAST([active_start_time] AS VARCHAR(6)), 6)
                                , 30':')
                            , 60':')
                    + ' & ' 
                    + STUFF(
                    STUFF(RIGHT('000000' + CAST([active_end_time] AS VARCHAR(6)), 6)
                                , 30':')
                            , 60':')
      END [Frequency]
    , [sSCH].[date_created] AS [ScheduleCreatedOn]
    , [sSCH].[date_modified] AS [ScheduleLastModifiedOn]
FROM [msdb].[dbo].[sysjobschedules] as [sJOBSCH] with(nolock)
    LEFT OUTER JOIN [msdb].[dbo].[sysschedules] AS [sSCH] with(nolock) ON [sJOBSCH].[schedule_id] = [sSCH].[schedule_id]
    LEFT OUTER JOIN msdb.dbo.sysjobs as [jobs] WITH(NOLOCK) ON [sJOBSCH].job_id=jobs.job_id
ORDER BY jobname
Colored by Color Scripter
 
cs
반응형
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.