From a7ed15f7ed1456cbd5cc7b3ee578e8b12d536284 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Fri, 27 Feb 2026 05:42:32 -0500 Subject: [PATCH] Reduce first-run lookback from 3-7 days to 1 hour for all collectors (#335) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- install/08_collect_query_stats.sql | 6 +++--- install/09_collect_query_store.sql | 6 +++--- install/10_collect_procedure_stats.sql | 6 +++--- install/18_collect_cpu_utilization_stats.sql | 4 ++-- install/22_collect_blocked_processes.sql | 6 +++--- install/24_collect_deadlock_xml.sql | 6 +++--- install/28_collect_system_health_wrapper.sql | 6 +++--- install/29_collect_default_trace.sql | 6 +++--- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/install/08_collect_query_stats.sql b/install/08_collect_query_stats.sql index df0163c..6d2cb2b 100644 --- a/install/08_collect_query_stats.sql +++ b/install/08_collect_query_stats.sql @@ -107,16 +107,16 @@ BEGIN END; /* - First run detection - collect all queries if this is the first execution + First run detection - collect last 1 hour of queries if this is the first execution */ IF NOT EXISTS (SELECT 1/0 FROM collect.query_stats) AND NOT EXISTS (SELECT 1/0 FROM config.collection_log WHERE collector_name = N'query_stats_collector') BEGIN - SET @cutoff_time = CONVERT(datetime2(7), '19000101'); + SET @cutoff_time = DATEADD(HOUR, -1, SYSDATETIME()); IF @debug = 1 BEGIN - RAISERROR(N'First run detected - collecting all queries from sys.dm_exec_query_stats', 0, 1) WITH NOWAIT; + RAISERROR(N'First run detected - collecting last 1 hour of query stats', 0, 1) WITH NOWAIT; END; END; ELSE diff --git a/install/09_collect_query_store.sql b/install/09_collect_query_store.sql index f8a13b2..a1cac83 100644 --- a/install/09_collect_query_store.sql +++ b/install/09_collect_query_store.sql @@ -145,16 +145,16 @@ BEGIN END; /* - First run detection - collect 3 days of history if this is the first execution + First run detection - collect last 1 hour of history if this is the first execution */ IF NOT EXISTS (SELECT 1/0 FROM collect.query_store_data) AND NOT EXISTS (SELECT 1/0 FROM config.collection_log WHERE collector_name = N'query_store_collector') BEGIN - SET @cutoff_time = TODATETIMEOFFSET(DATEADD(DAY, -3, SYSUTCDATETIME()), 0); + SET @cutoff_time = TODATETIMEOFFSET(DATEADD(HOUR, -1, SYSUTCDATETIME()), 0); IF @debug = 1 BEGIN - RAISERROR(N'First run detected - collecting last 3 days of Query Store data', 0, 1) WITH NOWAIT; + RAISERROR(N'First run detected - collecting last 1 hour of Query Store data', 0, 1) WITH NOWAIT; END; END; ELSE diff --git a/install/10_collect_procedure_stats.sql b/install/10_collect_procedure_stats.sql index e2dd106..d2b95d7 100644 --- a/install/10_collect_procedure_stats.sql +++ b/install/10_collect_procedure_stats.sql @@ -107,16 +107,16 @@ BEGIN END; /* - First run detection - collect all procedures if this is the first execution + First run detection - collect last 1 hour of procedures if this is the first execution */ IF NOT EXISTS (SELECT 1/0 FROM collect.procedure_stats) AND NOT EXISTS (SELECT 1/0 FROM config.collection_log WHERE collector_name = N'procedure_stats_collector') BEGIN - SET @cutoff_time = CONVERT(datetime2(7), '19000101'); + SET @cutoff_time = DATEADD(HOUR, -1, SYSDATETIME()); IF @debug = 1 BEGIN - RAISERROR(N'First run detected - collecting all procedures from sys.dm_exec_procedure_stats', 0, 1) WITH NOWAIT; + RAISERROR(N'First run detected - collecting last 1 hour of procedure stats', 0, 1) WITH NOWAIT; END; END; ELSE diff --git a/install/18_collect_cpu_utilization_stats.sql b/install/18_collect_cpu_utilization_stats.sql index 536ceca..6849a13 100644 --- a/install/18_collect_cpu_utilization_stats.sql +++ b/install/18_collect_cpu_utilization_stats.sql @@ -112,7 +112,7 @@ BEGIN /* Collect CPU utilization data from ring buffers Only collects samples newer than the most recent sample we have - On first run (NULL max_sample_time), looks back 7 days to populate initial data + On first run (NULL max_sample_time), looks back 1 hour to populate initial data Avoids duplicate collection of same ring buffer events */ INSERT INTO @@ -156,7 +156,7 @@ BEGIN SECOND, -((@current_ms_ticks - t.timestamp) / 1000), @start_time - ) > ISNULL(@max_sample_time, DATEADD(DAY, -7, @start_time)) + ) > ISNULL(@max_sample_time, DATEADD(HOUR, -1, @start_time)) ORDER BY t.timestamp DESC OPTION(RECOMPILE); diff --git a/install/22_collect_blocked_processes.sql b/install/22_collect_blocked_processes.sql index 5032ad3..33e0e62 100644 --- a/install/22_collect_blocked_processes.sql +++ b/install/22_collect_blocked_processes.sql @@ -140,17 +140,17 @@ BEGIN END; /* - First run detection - collect 3 days of history if this is the first execution + First run detection - collect last 1 hour of history if this is the first execution */ IF NOT EXISTS (SELECT 1/0 FROM collect.blocked_process_xml) AND NOT EXISTS (SELECT 1/0 FROM config.collection_log WHERE collector_name = N'blocked_process_xml_collector') BEGIN - SET @minutes_back = 4320; /*3 days*/ + SET @minutes_back = 60; /*1 hour*/ SET @cutoff_time = DATEADD(MINUTE, -@minutes_back, SYSUTCDATETIME()); IF @debug = 1 BEGIN - RAISERROR(N'First run detected - collecting last 3 days of blocked process events', 0, 1) WITH NOWAIT; + RAISERROR(N'First run detected - collecting last 1 hour of blocked process events', 0, 1) WITH NOWAIT; END; END; diff --git a/install/24_collect_deadlock_xml.sql b/install/24_collect_deadlock_xml.sql index 6bf8f87..6314e7f 100644 --- a/install/24_collect_deadlock_xml.sql +++ b/install/24_collect_deadlock_xml.sql @@ -101,17 +101,17 @@ BEGIN END; /* - First run detection - collect 3 days of history if this is the first execution + First run detection - collect last 1 hour of history if this is the first execution */ IF NOT EXISTS (SELECT 1/0 FROM collect.deadlock_xml) AND NOT EXISTS (SELECT 1/0 FROM config.collection_log WHERE collector_name = N'deadlock_xml_collector') BEGIN - SET @minutes_back = 4320; /*3 days*/ + SET @minutes_back = 60; /*1 hour*/ SET @cutoff_time = DATEADD(MINUTE, -@minutes_back, SYSUTCDATETIME()); IF @debug = 1 BEGIN - RAISERROR(N'First run detected - collecting last 3 days of deadlock events', 0, 1) WITH NOWAIT; + RAISERROR(N'First run detected - collecting last 1 hour of deadlock events', 0, 1) WITH NOWAIT; END; END; diff --git a/install/28_collect_system_health_wrapper.sql b/install/28_collect_system_health_wrapper.sql index 1c2b7fc..2a96f3d 100644 --- a/install/28_collect_system_health_wrapper.sql +++ b/install/28_collect_system_health_wrapper.sql @@ -101,16 +101,16 @@ BEGIN END; /* - First run detection - collect 3 days of history if this is the first execution + First run detection - collect last 1 hour of history if this is the first execution */ IF NOT EXISTS (SELECT 1/0 FROM config.collection_log WHERE collector_name = N'system_health_collector') BEGIN - SET @hours_back = 72; /*3 days*/ + SET @hours_back = 1; /*1 hour*/ SET @start_date = DATEADD(HOUR, -@hours_back, SYSDATETIMEOFFSET()); IF @debug = 1 BEGIN - RAISERROR(N'First run detected - collecting last 3 days of system health data', 0, 1) WITH NOWAIT; + RAISERROR(N'First run detected - collecting last 1 hour of system health data', 0, 1) WITH NOWAIT; END; END; diff --git a/install/29_collect_default_trace.sql b/install/29_collect_default_trace.sql index 9760fab..917466d 100644 --- a/install/29_collect_default_trace.sql +++ b/install/29_collect_default_trace.sql @@ -110,17 +110,17 @@ BEGIN END; /* - First run detection - collect all available trace data if this is the first execution + First run detection - collect last 1 hour of trace data if this is the first execution Ignore CONFIG_CHANGE entries when checking for first run (those are just from enabling the trace) */ IF NOT EXISTS (SELECT 1/0 FROM collect.default_trace_events) AND NOT EXISTS (SELECT 1/0 FROM config.collection_log WHERE collector_name = N'default_trace_collector' AND collection_status = N'SUCCESS') BEGIN - SET @cutoff_time = CONVERT(datetime2(7), '19000101'); + SET @cutoff_time = DATEADD(HOUR, -1, SYSDATETIME()); IF @debug = 1 BEGIN - RAISERROR(N'First run detected - collecting all available default trace events', 0, 1) WITH NOWAIT; + RAISERROR(N'First run detected - collecting last 1 hour of default trace events', 0, 1) WITH NOWAIT; END; END;