[DBA] 新增警示系統(嚴重錯誤回報、Log爆滿回報)

Hits: 554

今天上udemy的課,學到了新增警示系統,現學現賣,用在自己公司的系統上來試試。

新增警示系統

SQL server運行時,定義了26個錯誤的嚴重性層級,代碼是0-2,個別意義如下

嚴重性 說明
0-9 資訊類訊息,非錯誤
10 資訊類訊息以傳回狀態,或回報不嚴重的錯誤
11-16 使用者造成的錯誤
17-19 使用者無法修正的軟體錯誤
20 目前的處理發生嚴重錯誤
21 資料庫處理序發生嚴重錯誤
22-23 嚴重錯誤:資料表完整性受到質疑
24 嚴重錯誤:硬體錯誤
25 嚴重錯誤

T-SQL

EXEC msdb.dbo.sp_add_alert @name=N'錯誤嚴重性警告_17',  --自行命名"警示名稱"
  @message_id=0, 
  @severity=17, 
  @enabled=1, 
  @delay_between_responses=0, 
  @include_event_description_in=1;
GO
EXEC msdb.dbo.sp_add_notification @alert_name=N'錯誤嚴重性警告_17', @operator_name=N'operator', @notification_method = 1 --當發生錯誤時,寄給operator(需先在database mail設定好)
GO

SSMS

  • file

file

file

Log爆滿回報

T-SQL

USE [msdb]
GO
EXEC msdb.dbo.sp_add_alert @name=N'Log爆滿', --自行命名
        @enabled=1, 
        @delay_between_responses=43200,  --秒
        @include_event_description_in=1, 
        @notification_message=N'[注意] Log檔大小已超過1.5T',  --自訂訊息
        @performance_condition=N'Databases|Log File(s) Size (KB)|DB_NAME|>|1500000000', --自訂DB名稱、log大小
        @job_id=N'00000000-0000-0000-0000-000000000000'
GO
EXEC msdb.dbo.sp_add_notification @alert_name=N'Log爆滿', @operator_name=N'operator', @notification_method = 1 --寄信給operator
GO

SSMS

設定ldf大小警示,若超過1.5T,則發出通知
file

設定多久寄一次通知信,不然當超過設定的閾值時,每隔幾秒就會寄一次信,這邊設定為半天發一次
file

同場加映刪除ldf檔案的方法

About the Author

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

You may also like these