摘要:你知道數倉是如何應運而生的嗎?你瞭解數倉未來的發展趨勢嗎?想知道國內數倉專家的看法嗎? 導語 數據倉庫的發展一直是備受關註的議題,隨著近年來技術的不斷演進,數倉也在更新迭代。 你知道數倉是如何應運而生的嗎?你瞭解數倉未來的發展趨勢嗎?想知道國內數倉專家的看法嗎? 今天我們邀請到了華為雲數據倉庫 ...
1.1代碼檢查從昨天到現在,SQL代理Job有沒有運行失敗的,會把運行失敗的Job名字,步驟,運行時間,錯誤等級,錯誤原因羅列出來,方便查看。
----1.1 Check Job Fail List From Last Day To Now
SELECT j.[name],
h.step_id,
h.step_name,
h.run_date,
h.run_time,
h.sql_severity,
h.message,
h.server
FROM msdb.dbo.sysjobhistory h
INNER JOIN msdb.dbo.sysjobs j
ON h.job_id = j.job_id
INNER JOIN msdb.dbo.sysjobsteps s
ON j.job_id = s.job_id
AND h.step_id = s.step_id
WHERE h.run_status = 0 -- Failure
AND h.run_date > CONVERT(int,CONVERT(varchar(10), DATEADD(DAY, -1, GETDATE()), 112))
ORDER BY h.instance_id DESC;
1.2 檢查兩天內,運行時間超過30分鐘的Job,並按執行時間長短排序,時間2天和運行時間30分鐘,都是可以調整的,可以調整為自己需要的檢查範圍。代碼會把執行Job的名稱,運行時間,平均執行時間列出來。看是否有突然變化的運行情況。
----1.2 Check Jobs With Long Duration:30minutes(can modify to other value) From Last 2 Day To Now
SELECT sj.name
, sja.start_execution_date,DATEDIFF (minute ,sja.start_execution_date,sja.stop_execution_date ) AS ExecutedMin,ja.AvgRuntimeOnSucceed/60 as AvgRuntimeOnSucceedMin
FROM msdb.dbo.sysjobactivity AS sja
INNER JOIN msdb.dbo.sysjobs AS sj ON sja.job_id = sj.job_id INNER
join
(
SELECT job_id,
AVG
((run_duration/10000 * 3600) + ((run_duration%10000)/100*60) + (run_duration%10000)%100)
+
NULLIF(0,STDEV
((run_duration/10000 * 3600) + ((run_duration%10000)/100*60) + (run_duration%10000)%100)) AS 'AvgRuntimeOnSucceed'
FROM msdb.dbo.sysjobhistory
WHERE step_id = 0 AND run_status = 1
GROUP BY job_id) ja
ON sj.job_id = ja.job_id
WHERE sja.start_execution_date IS NOT NULL --作業有開始
AND sja.stop_execution_date IS not NULL --作業結束
AND sja.start_execution_date>DATEADD(DAY,-2,GETDATE()) --作業2天內開始
and DATEDIFF (minute ,sja.start_execution_date,sja.stop_execution_date )>30
order by ExecutedMin desc
1.3 檢查資料庫錯誤日誌,預設讀取的是當前log,篩選的是Error開頭的錯誤日誌,可以根據需要篩選其他關鍵字。
----1.3 Check SQL Error Log
DROP TABLE IF EXISTS #errorLog; -- this is new syntax in SQL 2016 and later
CREATE TABLE #errorLog (LogDate DATETIME, ProcessInfo VARCHAR(64), [Text] VARCHAR(MAX));
INSERT INTO #errorLog
EXEC sp_readerrorlog