Skip to content

Commit 5cbd9a6

Browse files
authored
Merge pull request #3536 from ReeceGoding/Branch-QSNotReadWrite
sp_Blitz: Added check for Query Store not being in READ_WRITE state and check for it not being in desired state.
2 parents c6acc2d + b7342f3 commit 5cbd9a6

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

Documentation/sp_Blitz_Checks_by_Priority.md

Lines changed: 4 additions & 2 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: 262.
10-
If you want to add a new one, start at 263.
9+
CURRENT HIGH CHECKID: 264.
10+
If you want to add a new one, start at 265.
1111

1212
| Priority | FindingsGroup | Finding | URL | CheckID |
1313
|----------|-----------------------------|---------------------------------------------------------|------------------------------------------------------------------------|----------|
@@ -248,6 +248,8 @@ If you want to add a new one, start at 263.
248248
| 200 | Performance | Old Compatibility Level | https://www.BrentOzar.com/go/compatlevel | 62 |
249249
| 200 | Performance | Query Store Disabled | https://www.BrentOzar.com/go/querystore | 163 |
250250
| 200 | Performance | Query Store Wait Stats Disabled | https://www.sqlskills.com/blogs/erin/query-store-settings/ | 262 |
251+
| 200 | Performance | Query Store Effectively Disabled | https://learn.microsoft.com/en-us/sql/relational-databases/performance/best-practice-with-the-query-store#Verify | 263 |
252+
| 200 | Performance | Undesired Query Store State | https://learn.microsoft.com/en-us/sql/relational-databases/performance/best-practice-with-the-query-store#Verify | 264 |
251253
| 200 | Performance | Snapshot Backups Occurring | https://www.BrentOzar.com/go/snaps | 178 |
252254
| 200 | Performance | User-Created Statistics In Place | https://www.BrentOzar.com/go/userstats | 122 |
253255
| 200 | Performance | SSAS/SSIS/SSRS Installed | https://www.BrentOzar.com/go/services | 224 |

sp_Blitz.sql

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6787,7 +6787,69 @@ IF @ProductVersionMajor >= 10
67876787
(''The new SQL Server 2017 Query Store feature for tracking wait stats has not been enabled on this database. It is very useful for tracking wait stats at a query level.'')
67886788
FROM [?].sys.database_query_store_options
67896789
WHERE desired_state <> 0
6790-
AND wait_stats_capture_mode = 0
6790+
AND wait_stats_capture_mode = 0
6791+
OPTION (RECOMPILE)';
6792+
END;
6793+
6794+
IF NOT EXISTS ( SELECT 1
6795+
FROM #SkipChecks
6796+
WHERE DatabaseName IS NULL AND CheckID = 263 )
6797+
AND EXISTS(SELECT * FROM sys.all_objects WHERE name = 'database_query_store_options')
6798+
BEGIN
6799+
6800+
IF @Debug IN (1, 2) RAISERROR('Running CheckId [%d].', 0, 1, 263) WITH NOWAIT;
6801+
6802+
EXEC dbo.sp_MSforeachdb 'USE [?];
6803+
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
6804+
INSERT INTO #BlitzResults
6805+
(CheckID,
6806+
DatabaseName,
6807+
Priority,
6808+
FindingsGroup,
6809+
Finding,
6810+
URL,
6811+
Details)
6812+
SELECT TOP 1 263,
6813+
N''?'',
6814+
200,
6815+
''Performance'',
6816+
''Query Store Effectively Disabled'',
6817+
''https://learn.microsoft.com/en-us/sql/relational-databases/performance/best-practice-with-the-query-store#Verify'',
6818+
(''Query Store is not in a state where it is writing, so it is effectively disabled. Check your Query Store settings.'')
6819+
FROM [?].sys.database_query_store_options
6820+
WHERE desired_state <> 0
6821+
AND actual_state <> 2
6822+
OPTION (RECOMPILE)';
6823+
END;
6824+
6825+
IF NOT EXISTS ( SELECT 1
6826+
FROM #SkipChecks
6827+
WHERE DatabaseName IS NULL AND CheckID = 264 )
6828+
AND EXISTS(SELECT * FROM sys.all_objects WHERE name = 'database_query_store_options')
6829+
BEGIN
6830+
6831+
IF @Debug IN (1, 2) RAISERROR('Running CheckId [%d].', 0, 1, 264) WITH NOWAIT;
6832+
6833+
EXEC dbo.sp_MSforeachdb 'USE [?];
6834+
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
6835+
INSERT INTO #BlitzResults
6836+
(CheckID,
6837+
DatabaseName,
6838+
Priority,
6839+
FindingsGroup,
6840+
Finding,
6841+
URL,
6842+
Details)
6843+
SELECT TOP 1 264,
6844+
N''?'',
6845+
200,
6846+
''Performance'',
6847+
''Undesired Query Store State'',
6848+
''https://learn.microsoft.com/en-us/sql/relational-databases/performance/best-practice-with-the-query-store#Verify'',
6849+
(''You have asked for Query Store to be in '' + desired_state_desc + '' mode, but it is in '' + actual_state_desc + '' mode.'')
6850+
FROM [?].sys.database_query_store_options
6851+
WHERE desired_state <> 0
6852+
AND desired_state <> actual_state
67916853
OPTION (RECOMPILE)';
67926854
END;
67936855

@@ -8419,7 +8481,7 @@ IF @ProductVersionMajor >= 10
84198481
WHEN [T].[TraceFlag] = '3226' THEN '3226 enabled globally, which keeps the event log clean by not reporting successful backups.'
84208482
WHEN [T].[TraceFlag] = '3505' THEN '3505 enabled globally, which disables Checkpoints. This is usually a very bad idea.'
84218483
WHEN [T].[TraceFlag] = '4199' THEN '4199 enabled globally, which enables non-default Query Optimizer fixes, changing query plans from the default behaviors.'
8422-
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-flused Query Store data.'
8484+
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.'
84238485
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?'
84248486
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?'
84258487
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.'

0 commit comments

Comments
 (0)