-
Notifications
You must be signed in to change notification settings - Fork 681
/
DBRecoveryProgress.sql
116 lines (113 loc) · 3.17 KB
/
DBRecoveryProgress.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
Original link: https://www.sqlservercentral.com/blogs/database-recovery-monitoring-with-xe
Source link: https://github.com/ktaranov/sqlserver-kit/blob/master/Extended_Events/DBRecoveryProgress.sql
Author: Jason Brimhall
*/
USE master;
GO
-- Create the Event Session
IF EXISTS
(
SELECT
*
FROM sys.server_event_sessions
WHERE name = 'DBRecoveryProgress'
)
DROP EVENT SESSION DBRecoveryProgress ON SERVER;
GO
CREATE EVENT SESSION DBRecoveryProgress
ON SERVER
ADD EVENT sqlserver.database_recovery_progress_report
(ACTION
(
/* yes this may be overkill on the actions - it is for discovery*/
sqlserver.database_id
, sqlserver.session_id
, sqlserver.database_name
, sqlserver.tsql_stack
, package0.event_sequence
, sqlserver.sql_text
, sqlserver.nt_username
, sqlserver.username
, sqlserver.session_nt_username
, sqlserver.client_app_name
, sqlserver.context_info
, sqlserver.client_connection_id
, sqlserver.query_hash
, sqlserver.query_plan_hash
, package0.callstack
)
)
, ADD EVENT sqlserver.database_recovery_trace
(ACTION
(
sqlserver.database_id
, sqlserver.session_id
, sqlserver.database_name
, sqlserver.tsql_stack
, package0.event_sequence
, sqlserver.sql_text
, sqlserver.nt_username
, sqlserver.username
, sqlserver.session_nt_username
, sqlserver.client_app_name
, sqlserver.context_info
, sqlserver.client_connection_id
, sqlserver.query_hash
, sqlserver.query_plan_hash
, package0.callstack
)
)
, ADD EVENT sqlserver.database_recovery_times
(ACTION
(
sqlserver.database_id
, sqlserver.session_id
, sqlserver.database_name
, sqlserver.tsql_stack
, package0.event_sequence
, sqlserver.sql_text
, sqlserver.nt_username
, sqlserver.username
, sqlserver.session_nt_username
, sqlserver.client_app_name
, sqlserver.context_info
, sqlserver.client_connection_id
, sqlserver.query_hash
, sqlserver.query_plan_hash
, package0.callstack
)
)
, ADD EVENT sqlserver.database_recovery_lsn_report
(ACTION
(
sqlserver.database_id
, sqlserver.session_id
, sqlserver.database_name
, sqlserver.tsql_stack
, package0.event_sequence
, sqlserver.sql_text
, sqlserver.nt_username
, sqlserver.username
, sqlserver.session_nt_username
, sqlserver.client_app_name
, sqlserver.context_info
, sqlserver.client_connection_id
, sqlserver.query_hash
, sqlserver.query_plan_hash
, package0.callstack
)
)
ADD TARGET package0.event_file
(SET filename = 'c:\Windows\Temp\DatabaseXEDBRecoveryProgress.xel', max_file_size = 5, max_rollover_files = 4)
WITH
(
MAX_MEMORY = 4MB
, EVENT_RETENTION_MODE = ALLOW_SINGLE_EVENT_LOSS
, TRACK_CAUSALITY = ON
, MAX_DISPATCH_LATENCY = 5 SECONDS
, STARTUP_STATE = ON
);
GO
ALTER EVENT SESSION DBRecoveryProgress ON SERVER STATE = START;
GO