Skip to content

Commit 85f320f

Browse files
Reduce first-run lookback from 3-7 days to 1 hour for all collectors (#335) (#340)
All 8 collectors with first-run backfill logic now look back 1 hour instead of 3-7 days (or unlimited). The aggressive lookback was a development convenience that becomes catastrophic on large environments — particularly query_store_collector with XML plan decompression on multi-GB Query Store databases, causing timeout→rollback→retry loops. Changed collectors: - 08_collect_query_stats: all DMV data → 1 hour - 09_collect_query_store: 3 days → 1 hour - 10_collect_procedure_stats: all DMV data → 1 hour - 18_collect_cpu_utilization_stats: 7 days → 1 hour - 22_collect_blocked_processes: 3 days → 1 hour - 24_collect_deadlock_xml: 3 days → 1 hour - 28_collect_system_health_wrapper: 3 days → 1 hour - 29_collect_default_trace: all available → 1 hour Clean install verified on sql2016 with zero errors. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c206575 commit 85f320f

8 files changed

Lines changed: 23 additions & 23 deletions

install/08_collect_query_stats.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@ BEGIN
107107
END;
108108

109109
/*
110-
First run detection - collect all queries if this is the first execution
110+
First run detection - collect last 1 hour of queries if this is the first execution
111111
*/
112112
IF NOT EXISTS (SELECT 1/0 FROM collect.query_stats)
113113
AND NOT EXISTS (SELECT 1/0 FROM config.collection_log WHERE collector_name = N'query_stats_collector')
114114
BEGIN
115-
SET @cutoff_time = CONVERT(datetime2(7), '19000101');
115+
SET @cutoff_time = DATEADD(HOUR, -1, SYSDATETIME());
116116

117117
IF @debug = 1
118118
BEGIN
119-
RAISERROR(N'First run detected - collecting all queries from sys.dm_exec_query_stats', 0, 1) WITH NOWAIT;
119+
RAISERROR(N'First run detected - collecting last 1 hour of query stats', 0, 1) WITH NOWAIT;
120120
END;
121121
END;
122122
ELSE

install/09_collect_query_store.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,16 @@ BEGIN
145145
END;
146146

147147
/*
148-
First run detection - collect 3 days of history if this is the first execution
148+
First run detection - collect last 1 hour of history if this is the first execution
149149
*/
150150
IF NOT EXISTS (SELECT 1/0 FROM collect.query_store_data)
151151
AND NOT EXISTS (SELECT 1/0 FROM config.collection_log WHERE collector_name = N'query_store_collector')
152152
BEGIN
153-
SET @cutoff_time = TODATETIMEOFFSET(DATEADD(DAY, -3, SYSUTCDATETIME()), 0);
153+
SET @cutoff_time = TODATETIMEOFFSET(DATEADD(HOUR, -1, SYSUTCDATETIME()), 0);
154154

155155
IF @debug = 1
156156
BEGIN
157-
RAISERROR(N'First run detected - collecting last 3 days of Query Store data', 0, 1) WITH NOWAIT;
157+
RAISERROR(N'First run detected - collecting last 1 hour of Query Store data', 0, 1) WITH NOWAIT;
158158
END;
159159
END;
160160
ELSE

install/10_collect_procedure_stats.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@ BEGIN
107107
END;
108108

109109
/*
110-
First run detection - collect all procedures if this is the first execution
110+
First run detection - collect last 1 hour of procedures if this is the first execution
111111
*/
112112
IF NOT EXISTS (SELECT 1/0 FROM collect.procedure_stats)
113113
AND NOT EXISTS (SELECT 1/0 FROM config.collection_log WHERE collector_name = N'procedure_stats_collector')
114114
BEGIN
115-
SET @cutoff_time = CONVERT(datetime2(7), '19000101');
115+
SET @cutoff_time = DATEADD(HOUR, -1, SYSDATETIME());
116116

117117
IF @debug = 1
118118
BEGIN
119-
RAISERROR(N'First run detected - collecting all procedures from sys.dm_exec_procedure_stats', 0, 1) WITH NOWAIT;
119+
RAISERROR(N'First run detected - collecting last 1 hour of procedure stats', 0, 1) WITH NOWAIT;
120120
END;
121121
END;
122122
ELSE

install/18_collect_cpu_utilization_stats.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ BEGIN
112112
/*
113113
Collect CPU utilization data from ring buffers
114114
Only collects samples newer than the most recent sample we have
115-
On first run (NULL max_sample_time), looks back 7 days to populate initial data
115+
On first run (NULL max_sample_time), looks back 1 hour to populate initial data
116116
Avoids duplicate collection of same ring buffer events
117117
*/
118118
INSERT INTO
@@ -156,7 +156,7 @@ BEGIN
156156
SECOND,
157157
-((@current_ms_ticks - t.timestamp) / 1000),
158158
@start_time
159-
) > ISNULL(@max_sample_time, DATEADD(DAY, -7, @start_time))
159+
) > ISNULL(@max_sample_time, DATEADD(HOUR, -1, @start_time))
160160
ORDER BY
161161
t.timestamp DESC
162162
OPTION(RECOMPILE);

install/22_collect_blocked_processes.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,17 @@ BEGIN
140140
END;
141141

142142
/*
143-
First run detection - collect 3 days of history if this is the first execution
143+
First run detection - collect last 1 hour of history if this is the first execution
144144
*/
145145
IF NOT EXISTS (SELECT 1/0 FROM collect.blocked_process_xml)
146146
AND NOT EXISTS (SELECT 1/0 FROM config.collection_log WHERE collector_name = N'blocked_process_xml_collector')
147147
BEGIN
148-
SET @minutes_back = 4320; /*3 days*/
148+
SET @minutes_back = 60; /*1 hour*/
149149
SET @cutoff_time = DATEADD(MINUTE, -@minutes_back, SYSUTCDATETIME());
150150

151151
IF @debug = 1
152152
BEGIN
153-
RAISERROR(N'First run detected - collecting last 3 days of blocked process events', 0, 1) WITH NOWAIT;
153+
RAISERROR(N'First run detected - collecting last 1 hour of blocked process events', 0, 1) WITH NOWAIT;
154154
END;
155155
END;
156156

install/24_collect_deadlock_xml.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ BEGIN
101101
END;
102102

103103
/*
104-
First run detection - collect 3 days of history if this is the first execution
104+
First run detection - collect last 1 hour of history if this is the first execution
105105
*/
106106
IF NOT EXISTS (SELECT 1/0 FROM collect.deadlock_xml)
107107
AND NOT EXISTS (SELECT 1/0 FROM config.collection_log WHERE collector_name = N'deadlock_xml_collector')
108108
BEGIN
109-
SET @minutes_back = 4320; /*3 days*/
109+
SET @minutes_back = 60; /*1 hour*/
110110
SET @cutoff_time = DATEADD(MINUTE, -@minutes_back, SYSUTCDATETIME());
111111

112112
IF @debug = 1
113113
BEGIN
114-
RAISERROR(N'First run detected - collecting last 3 days of deadlock events', 0, 1) WITH NOWAIT;
114+
RAISERROR(N'First run detected - collecting last 1 hour of deadlock events', 0, 1) WITH NOWAIT;
115115
END;
116116
END;
117117

install/28_collect_system_health_wrapper.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ BEGIN
101101
END;
102102

103103
/*
104-
First run detection - collect 3 days of history if this is the first execution
104+
First run detection - collect last 1 hour of history if this is the first execution
105105
*/
106106
IF NOT EXISTS (SELECT 1/0 FROM config.collection_log WHERE collector_name = N'system_health_collector')
107107
BEGIN
108-
SET @hours_back = 72; /*3 days*/
108+
SET @hours_back = 1; /*1 hour*/
109109
SET @start_date = DATEADD(HOUR, -@hours_back, SYSDATETIMEOFFSET());
110110

111111
IF @debug = 1
112112
BEGIN
113-
RAISERROR(N'First run detected - collecting last 3 days of system health data', 0, 1) WITH NOWAIT;
113+
RAISERROR(N'First run detected - collecting last 1 hour of system health data', 0, 1) WITH NOWAIT;
114114
END;
115115
END;
116116

install/29_collect_default_trace.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@ BEGIN
110110
END;
111111

112112
/*
113-
First run detection - collect all available trace data if this is the first execution
113+
First run detection - collect last 1 hour of trace data if this is the first execution
114114
Ignore CONFIG_CHANGE entries when checking for first run (those are just from enabling the trace)
115115
*/
116116
IF NOT EXISTS (SELECT 1/0 FROM collect.default_trace_events)
117117
AND NOT EXISTS (SELECT 1/0 FROM config.collection_log WHERE collector_name = N'default_trace_collector' AND collection_status = N'SUCCESS')
118118
BEGIN
119-
SET @cutoff_time = CONVERT(datetime2(7), '19000101');
119+
SET @cutoff_time = DATEADD(HOUR, -1, SYSDATETIME());
120120

121121
IF @debug = 1
122122
BEGIN
123-
RAISERROR(N'First run detected - collecting all available default trace events', 0, 1) WITH NOWAIT;
123+
RAISERROR(N'First run detected - collecting last 1 hour of default trace events', 0, 1) WITH NOWAIT;
124124
END;
125125
END;
126126

0 commit comments

Comments
 (0)