Skip to content

Commit a7359ec

Browse files
authored
Merge pull request #3553 from ReeceGoding/dev
sp_Blitz: Added check for unusual Query Store configuration and Query Store Trace Flags
2 parents 3446b69 + 29f11bc commit a7359ec

2 files changed

Lines changed: 89 additions & 5 deletions

File tree

Documentation/sp_Blitz_Checks_by_Priority.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Before adding a new check, make sure to add a Github issue for it first, and hav
66

77
If you want to change anything about a check - the priority, finding, URL, or ID - open a Github issue first. The relevant scripts have to be updated too.
88

9-
CURRENT HIGH CHECKID: 264.
10-
If you want to add a new one, start at 265.
9+
CURRENT HIGH CHECKID: 265.
10+
If you want to add a new one, start at 266.
1111

1212
| Priority | FindingsGroup | Finding | URL | CheckID |
1313
|----------|-----------------------------|---------------------------------------------------------|------------------------------------------------------------------------|----------|
@@ -153,7 +153,7 @@ If you want to add a new one, start at 265.
153153
| 200 | Informational | Tables in the Master Database | https://www.BrentOzar.com/go/mastuser | 27 |
154154
| 200 | Informational | Tables in the Model Database | https://www.BrentOzar.com/go/model | 29 |
155155
| 200 | Informational | Tables in the MSDB Database | https://www.BrentOzar.com/go/msdbuser | 28 |
156-
| 200 | Informational | TraceFlag On | https://www.BrentOzar.com/go/traceflags/ | 74 |
156+
| 200 | Informational | TraceFlag On / Recommended Trace Flag Off | https://www.BrentOzar.com/go/traceflags/ | 74 |
157157
| 200 | Licensing | Enterprise Edition Features In Use | https://www.BrentOzar.com/go/ee | 33 |
158158
| 200 | Licensing | Non-Production License | https://www.BrentOzar.com/go/licensing | 173 |
159159
| 200 | Monitoring | Agent Jobs Without Failure Emails | https://www.BrentOzar.com/go/alerts | 94 |
@@ -250,6 +250,7 @@ If you want to add a new one, start at 265.
250250
| 200 | Performance | Query Store Wait Stats Disabled | https://www.sqlskills.com/blogs/erin/query-store-settings/ | 262 |
251251
| 200 | Performance | Query Store Effectively Disabled | https://learn.microsoft.com/en-us/sql/relational-databases/performance/best-practice-with-the-query-store#Verify | 263 |
252252
| 200 | Performance | Undesired Query Store State | https://learn.microsoft.com/en-us/sql/relational-databases/performance/best-practice-with-the-query-store#Verify | 264 |
253+
| 200 | Performance | Query Store Unusually Configured | https://www.sqlskills.com/blogs/erin/query-store-best-practices/ | 265 |
253254
| 200 | Performance | Snapshot Backups Occurring | https://www.BrentOzar.com/go/snaps | 178 |
254255
| 200 | Performance | User-Created Statistics In Place | https://www.BrentOzar.com/go/userstats | 122 |
255256
| 200 | Performance | SSAS/SSIS/SSRS Installed | https://www.BrentOzar.com/go/services | 224 |

sp_Blitz.sql

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6861,6 +6861,41 @@ IF @ProductVersionMajor >= 10
68616861
AND desired_state <> actual_state
68626862
OPTION (RECOMPILE)';
68636863
END;
6864+
6865+
IF NOT EXISTS ( SELECT 1
6866+
FROM #SkipChecks
6867+
WHERE DatabaseName IS NULL AND CheckID = 265 )
6868+
AND EXISTS(SELECT * FROM sys.all_objects WHERE name = 'database_query_store_options')
6869+
BEGIN
6870+
IF @Debug IN (1, 2) RAISERROR('Running CheckId [%d].', 0, 1, 265) WITH NOWAIT;
6871+
6872+
EXEC dbo.sp_MSforeachdb 'USE [?];
6873+
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
6874+
INSERT INTO #BlitzResults
6875+
(CheckID,
6876+
DatabaseName,
6877+
Priority,
6878+
FindingsGroup,
6879+
Finding,
6880+
URL,
6881+
Details)
6882+
SELECT TOP 1 265,
6883+
N''?'',
6884+
200,
6885+
''Performance'',
6886+
''Query Store Unusually Configured'',
6887+
''https://www.sqlskills.com/blogs/erin/query-store-best-practices/'',
6888+
(''The '' + query_capture_mode_desc + '' query capture mode '' +
6889+
CASE query_capture_mode_desc
6890+
WHEN ''ALL'' THEN ''captures more data than you will probably use. If your workload is heavily ad-hoc, then it can also cause Query Store to capture so much that it turns itself off.''
6891+
WHEN ''NONE'' THEN ''stops Query Store capturing data for new queries.''
6892+
WHEN ''CUSTOM'' THEN ''suggests that somebody has gone out of their way to only capture exactly what they want.''
6893+
ELSE ''is not documented.'' END)
6894+
FROM [?].sys.database_query_store_options
6895+
WHERE desired_state <> 0 /* No point in checking this if Query Store is off. */
6896+
AND query_capture_mode_desc <> ''AUTO''
6897+
OPTION (RECOMPILE)';
6898+
END;
68646899

68656900
IF @ProductVersionMajor = 13 AND @ProductVersionMinor < 2149 --2016 CU1 has the fix in it
68666901
AND NOT EXISTS ( SELECT 1
@@ -8490,11 +8525,11 @@ IF @ProductVersionMajor >= 10
84908525
WHEN [T].[TraceFlag] = '3226' THEN '3226 enabled globally, which keeps the event log clean by not reporting successful backups.'
84918526
WHEN [T].[TraceFlag] = '3505' THEN '3505 enabled globally, which disables Checkpoints. This is usually a very bad idea.'
84928527
WHEN [T].[TraceFlag] = '4199' THEN '4199 enabled globally, which enables non-default Query Optimizer fixes, changing query plans from the default behaviors.'
8493-
WHEN [T].[TraceFlag] = '7745' AND @ProductVersionMajor > 12 AND @QueryStoreInUse = 1 THEN '7745 enabled globally, which makes shutdowns/failovers quicker by not waiting for Query Store to flush to disk. This good idea loses you the non-flushed Query Store data.'
8528+
WHEN [T].[TraceFlag] = '7745' AND @QueryStoreInUse = 1 THEN '7745 enabled globally, which makes shutdowns/failovers quicker by not waiting for Query Store to flush to disk. This good idea loses you the non-flushed Query Store data.'
84948529
WHEN [T].[TraceFlag] = '7745' AND @ProductVersionMajor > 12 THEN '7745 enabled globally, which is for Query Store. None of your databases have Query Store enabled, so why do you have this turned on?'
84958530
WHEN [T].[TraceFlag] = '7745' AND @ProductVersionMajor <= 12 THEN '7745 enabled globally, which is for Query Store. Query Store does not exist on your SQL Server version, so why do you have this turned on?'
84968531
WHEN [T].[TraceFlag] = '7752' AND @ProductVersionMajor > 14 THEN '7752 enabled globally, which is for Query Store. However, it has no effect in your SQL Server version. Consider turning it off.'
8497-
WHEN [T].[TraceFlag] = '7752' AND @ProductVersionMajor > 12 AND @QueryStoreInUse = 1 THEN '7752 enabled globally, which stops queries needing to wait on Query Store loading up after database recovery.'
8532+
WHEN [T].[TraceFlag] = '7752' AND @QueryStoreInUse = 1 THEN '7752 enabled globally, which stops queries needing to wait on Query Store loading up after database recovery.'
84988533
WHEN [T].[TraceFlag] = '7752' AND @ProductVersionMajor > 12 THEN '7752 enabled globally, which is for Query Store. None of your databases have Query Store enabled, so why do you have this turned on?'
84998534
WHEN [T].[TraceFlag] = '7752' AND @ProductVersionMajor <= 12 THEN '7752 enabled globally, which is for Query Store. Query Store does not exist on your SQL Server version, so why do you have this turned on?'
85008535
WHEN [T].[TraceFlag] = '8048' THEN '8048 enabled globally, which tries to reduce CMEMTHREAD waits on servers with a lot of logical processors.'
@@ -8504,6 +8539,54 @@ IF @ProductVersionMajor >= 10
85048539
ELSE [T].[TraceFlag] + ' is enabled globally.' END
85058540
AS Details
85068541
FROM #TraceStatus T;
8542+
8543+
8544+
IF NOT EXISTS ( SELECT 1
8545+
FROM #TraceStatus T
8546+
WHERE [T].[TraceFlag] = '7745' )
8547+
AND @QueryStoreInUse = 1
8548+
8549+
BEGIN
8550+
INSERT INTO #BlitzResults
8551+
( CheckID ,
8552+
Priority ,
8553+
FindingsGroup ,
8554+
Finding ,
8555+
URL ,
8556+
Details
8557+
)
8558+
SELECT 74 AS CheckID ,
8559+
200 AS Priority ,
8560+
'Informational' AS FindingsGroup ,
8561+
'Recommended Trace Flag Off' AS Finding ,
8562+
'https://www.sqlskills.com/blogs/erin/query-store-trace-flags/' AS URL ,
8563+
'Trace Flag 7745 not enabled globally. It makes shutdowns/failovers quicker by not waiting for Query Store to flush to disk. It is recommended, but it loses you the non-flushed Query Store data.' AS Details
8564+
FROM #TraceStatus T
8565+
END;
8566+
8567+
IF NOT EXISTS ( SELECT 1
8568+
FROM #TraceStatus T
8569+
WHERE [T].[TraceFlag] = '7752' )
8570+
AND @ProductVersionMajor < 15
8571+
AND @QueryStoreInUse = 1
8572+
8573+
BEGIN
8574+
INSERT INTO #BlitzResults
8575+
( CheckID ,
8576+
Priority ,
8577+
FindingsGroup ,
8578+
Finding ,
8579+
URL ,
8580+
Details
8581+
)
8582+
SELECT 74 AS CheckID ,
8583+
200 AS Priority ,
8584+
'Informational' AS FindingsGroup ,
8585+
'Recommended Trace Flag Off' AS Finding ,
8586+
'https://www.sqlskills.com/blogs/erin/query-store-trace-flags/' AS URL ,
8587+
'Trace Flag 7752 not enabled globally. It stops queries needing to wait on Query Store loading up after database recovery. It is so recommended that it is enabled by default as of SQL Server 2019.' AS Details
8588+
FROM #TraceStatus T
8589+
END;
85078590
END;
85088591

85098592
/* High CMEMTHREAD waits that could need trace flag 8048.

0 commit comments

Comments
 (0)