傳回成功的 SQL 資料庫 資料庫連接,以及連接失敗、死結和節流事件。 您可以使用這項資訊追蹤 SQL 資料庫 的資料庫活動或進行疑難排解。
適用於:Azure SQL Database. |
sys.event_log 檢視包含以下資料行。
資料行名稱 |
資料類型 |
描述 |
|---|---|---|
database_name |
sysname |
資料庫的名稱。 如果連接失敗且使用者未指定資料庫名稱,則這個資料行會是空白。 |
start_time |
datetime2 |
彙總間隔開始的 UTC 日期和時間。 對於彙總的事件,這個時間永遠是 5 分鐘的倍數。 例如: '2011-09-28 16:00:00' |
end_time |
datetime2 |
彙總間隔結束的 UTC 日期和時間。 對於彙總的事件,End_time 永遠比同一資料列中對應的 start_time 多出剛好 5 分鐘。 對於未彙總的事件,start_time 和 end_time 等於事件的實際 UTC 日期和時間。 |
event_category |
nvarchar(64) |
產生這個事件的高階元件。 如需可能值的清單,請參閱<Event Types>。 |
event_type |
nvarchar(64) |
事件的類型。 如需可能值的清單,請參閱<Event Types>。 |
event_subtype |
int |
所發生事件的子類型。 如需可能值的清單,請參閱<Event Types>。 |
event_subtype_desc |
nvarchar(64) |
事件子類型的描述。 如需可能值的清單,請參閱<Event Types>。 |
severity |
int |
錯誤的嚴重性。 可能的值為: 0 = 資訊 |
event_count |
int |
在指定的時間間隔內 (start_time 和 end_time),這個事件對於指定的資料庫發生的次數。 |
description |
nvarchar(max) |
事件的詳細描述。 如需可能值的清單,請參閱<Event Types>。 |
additional_data |
XML |
對於 Deadlock 事件,這個資料行會包含死結圖表。 對於其他事件類型,這個資料行為 NULL。 |
事件類型
這個檢視中每個資料列所記錄的事件是以類別目錄 (event_category)、事件類型 (event_type) 和子類型 (event_subtype) 識別。 下表列出這個檢視中所收集事件的類型。
對於 connectivity 類別目錄中的事件,sys.database_connection_stats 檢視中會提供摘要資訊。
注意
這個檢視不包括所有可能發生的 SQL 資料庫 資料庫事件,只包括這裡列出的事件。其他類別目錄、事件類型和子類型會在未來的 SQL 資料庫 版本中加入。
event_category |
event_type |
event_subtype |
event_subtype_desc |
severity |
description |
|---|---|---|---|---|---|
connectivity |
connection_successful |
0 |
connection_successful |
0 |
已成功連接資料庫。 |
connectivity |
connection_failed |
0 |
invalid_login_name |
2 |
登入名稱在這個版本的 SQL Server 中無效。 |
connectivity |
connection_failed |
1 |
windows_auth_not_supported |
2 |
這個版本的 SQL Server 不支援 Windows 登入。 |
connectivity |
connection_failed |
2 |
attach_db_not_supported |
2 |
使用者要求附加不支援的資料庫檔案。 |
connectivity |
connection_failed |
3 |
change_password_not_supported |
2 |
不支援使用者要求變更使用者登入的密碼。 |
connectivity |
connection_failed |
4 |
login_failed_for_user |
2 |
使用者登入失敗。 |
connectivity |
connection_failed |
5 |
login_disabled |
2 |
登入已停用。 |
connectivity |
connection_failed |
6 |
failed_to_open_db |
2 |
資料庫無法開啟。 可能原因是資料庫不存在,或缺少開啟資料庫的驗證。 |
connectivity |
connection_failed |
7 |
blocked_by_firewall |
2 |
不允許用戶端 IP 位址存取伺服器。 |
connectivity |
connection_failed |
8 |
client_close |
2 |
用戶端可能在建立連接時逾時。 嘗試建立連接時發生逾時。 |
connectivity |
connection_failed |
9 |
reconfiguration |
2 |
連接失敗,因為資料庫當時正在進行重新組態。 |
connectivity |
connection_terminated |
0 |
idle_connection_timeout |
2 |
連接已閒置超過系統定義的臨界值。 |
connectivity |
connection_terminated |
1 |
reconfiguration |
2 |
由於資料庫重新設定,已終止工作階段。 |
connectivity |
throttling |
<原因代碼> |
reason_code |
2 |
要求已節流。 節流原因代碼:<原因代碼>。 如需詳細資訊,請參閱<引擎節流>。 |
connectivity |
throttling_long_transaction |
40549 |
long_transaction |
2 |
工作階段已終止,因為您有長時間執行的交易。 請嘗試縮短您的交易。 如需詳細資訊,請參閱<資源限制>。 |
connectivity |
throttling_long_transaction |
40550 |
excessive_lock_usage |
2 |
已終止工作階段,因為它取得太多鎖定。 請嘗試在單一交易中讀取或修改較少的資料列。 如需詳細資訊,請參閱<資源限制>。 |
connectivity |
throttling_long_transaction |
40551 |
excessive_tempdb_usage |
2 |
已終止工作階段,因為它過度使用 TEMPDB。 請嘗試修改查詢,減少使用暫存資料表空間。 如需詳細資訊,請參閱<資源限制>。 |
connectivity |
throttling_long_transaction |
40552 |
excessive_log_space_usage |
2 |
已終止工作階段,因為它過度使用交易記錄檔空間。 請嘗試在單一交易中修改較少的資料列。 如需詳細資訊,請參閱<資源限制>。 |
connectivity |
throttling_long_transaction |
40553 |
excessive_memory_usage |
2 |
已終止工作階段,因為它過度使用記憶體。 請嘗試修改查詢以處理較少的資料列。 如需詳細資訊,請參閱<資源限制>。 |
engine |
deadlock |
0 |
deadlock |
2 |
發生死結。 |
Permissions
具有 master 資料庫存取權限的使用者擁有這個檢視的唯讀存取權限。
範例
以下查詢會傳回 2011 年 9 月 25 日中午到 2011 年 9 月 28 日中午 (UTC) 之間發生的所有事件。 根據預設,查詢結果會依 start_time 排序 (遞增順序)。
select * from sys.event_log where start_time>='2011-09-25:12:00:00' and end_time<='2011-09-28 12:00:00';
以下查詢會傳回 Database1 資料庫的所有死結事件。
select * from sys.event_log where event_type='deadlock' and database_name='Database1';
以下查詢會傳回 2011 年 9 月 25 日上午 10:00 到 11:00 (UTC) 之間在發生的 SQL 工作者執行緒事件上發生的硬節流。
select * from sys.event_log where event_type='throttling' and event_subtype=4194307 and start_time>='2011-09-25 10:00:00' and end_time<='2011-09-25 11:00:00';
備註
事件彙總
這個檢視的事件資訊會在 5 分鐘間隔內收集和彙總。 event_count 資料行代表在給定時間間隔內,特定資料庫發生特殊 event_type 和 event_subtype 的次數。
注意
某些事件不會彙總,像是死結。對於這些事件,event_count 將會是 1,而 start_time 和 end_time 將等於事件發生時實際的 UTC 日期和時間。
例如,如果使用者因為登入名稱無效,而在連接到 Database1 資料庫時於 2012 年 2 月 5 日 11:00 到 11:05 (UTC) 之間失敗七次,這項資訊會在這個檢視的單一資料列中提供:
database_name |
start_time |
end_time |
event_category |
event_type |
event_subtype |
event_subtype_desc |
severity |
event_count |
description |
additional_data |
|---|---|---|---|---|---|---|---|---|---|---|
Database1 |
2012-02-05 11:00:00 |
2012-02-05 11:05:00 |
connectivity |
connection_failed |
4 |
login_failed_for_user |
2 |
7 |
Login failed for user. |
NULL |
間隔的 start_time 和 end_time
彙總間隔所納入的事件,包括了在該間隔的 start_time「當時」或「之後」直到 end_time「之前」發生的事件。 例如,正巧發生在 2012-10-30 19:25:00.0000000 的事件只會納入到以下所示的第二段間隔:
start_time end_time
2012-10-30 19:20:00.0000000 2012-10-30 19:25:00.0000000
2012-10-30 19:25:00.0000000 2012-10-30 19:30:00.0000000
資料更新
這個檢視中的資料會累積一段時間。 通常資料會在彙總間隔開始的 1 小時內累積,但是最長可能需要 24 小時,所有資料才會出現在檢視中。 在這段期間,單一資料列內的資訊會定期更新。
資料保留
根據邏輯伺服器的資料庫數目以及每個資料庫所產生的唯一事件數目而定,這個檢視表中的資料最長會保留 30 天或以下。 若要保留這項資訊更長的時間,請將資料複製到另一個資料庫。 在您製作檢視的初始副本之後,檢視中的資料列可能會隨資料累積而更新。 為了讓資料副本保持最新狀態,請定期執行資料列的資料表掃描,查看現有資料列的事件計數是否增加,並且識別新資料列 (您可以使用開始和結束時間識別唯一資料列),然後用這些變更來更新您的資料副本。
不包括錯誤
這個檢視可能不會包括所有連接和錯誤資訊:
這個檢視不包括所有可能發生的 SQL 資料庫 資料庫錯誤,只包括本主題中Event Types指定的錯誤。
如果在 SQL 資料庫 資料中心內發生機器故障,則事件資料表中可能會遺漏邏輯伺服器的少量資料。
如果已透過 DoSGuard 封鎖 IP 位址,則來自該 IP 位址的連接嘗試事件就無法收集,也不會出現在這個檢視中。