Skip to content

Commit a2ea69b

Browse files
authored
Merge pull request #3726 from yoni-yad2/exclude-rds-objects-from-checks
Exclude RDS objects and rdsadmin DB from sp_Blitz checks
2 parents 56ac912 + 1f5cf04 commit a2ea69b

File tree

1 file changed

+52
-23
lines changed

1 file changed

+52
-23
lines changed

sp_Blitz.sql

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,7 @@ AS
570570
SELECT
571571
DB_NAME(d.database_id)
572572
FROM sys.databases AS d
573-
WHERE (DB_NAME(d.database_id) LIKE 'rdsadmin%'
574-
OR LOWER(d.name) IN ('dbatools', 'dbadmin', 'dbmaintenance'))
573+
WHERE LOWER(d.name) IN ('dbatools', 'dbadmin', 'dbmaintenance', 'rdsadmin')
575574
OPTION(RECOMPILE);
576575

577576
/*Skip checks for database where we don't have read permissions*/
@@ -2047,7 +2046,9 @@ AS
20472046
''Performance'' AS FindingsGroup,
20482047
''Server Triggers Enabled'' AS Finding,
20492048
''https://www.brentozar.com/go/logontriggers/'' AS URL,
2050-
(''Server Trigger ['' + [name] ++ ''] is enabled. Make sure you understand what that trigger is doing - the less work it does, the better.'') AS Details FROM sys.server_triggers WHERE is_disabled = 0 AND is_ms_shipped = 0 OPTION (RECOMPILE);';
2049+
(''Server Trigger ['' + [name] ++ ''] is enabled. Make sure you understand what that trigger is doing - the less work it does, the better.'') AS Details
2050+
FROM sys.server_triggers
2051+
WHERE is_disabled = 0 AND is_ms_shipped = 0 AND name NOT LIKE ''rds^_%'' ESCAPE ''^'' OPTION (RECOMPILE);';
20512052

20522053
IF @Debug = 2 AND @StringToExecute IS NOT NULL PRINT @StringToExecute;
20532054
IF @Debug = 2 AND @StringToExecute IS NULL PRINT '@StringToExecute has gone NULL, for some reason.';
@@ -2706,7 +2707,8 @@ AS
27062707
+ '. Tables in the master database may not be restored in the event of a disaster.' ) AS Details
27072708
FROM master.sys.tables
27082709
WHERE is_ms_shipped = 0
2709-
AND name NOT IN ('CommandLog','SqlServerVersions','$ndo$srvproperty');
2710+
AND name NOT IN ('CommandLog','SqlServerVersions','$ndo$srvproperty')
2711+
AND name NOT LIKE 'rds^_%' ESCAPE '^';
27102712
/* That last one is the Dynamics NAV licensing table: https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/issues/2426 */
27112713
END;
27122714

@@ -4883,12 +4885,12 @@ AS
48834885
SET @StringToExecute = 'INSERT INTO #BlitzResults (CheckID, DatabaseName, Priority, FindingsGroup, Finding, URL, Details)
48844886
SELECT ' + CAST(@CurrentCheckID AS NVARCHAR(200)) + ', d.[name], ' + CAST(@CurrentPriority AS NVARCHAR(200)) + ', ''Non-Default Database Config'', ''' + @CurrentFinding + ''',''' + @CurrentURL + ''',''' + COALESCE(@CurrentDetails, 'This database setting is not the default.') + '''
48854887
FROM sys.databases d
4886-
WHERE d.database_id > 4 AND d.state = 0 AND (d.[' + @CurrentName + '] NOT IN (0, 60) OR d.[' + @CurrentName + '] IS NULL) OPTION (RECOMPILE);';
4888+
WHERE d.database_id > 4 AND DB_NAME(d.database_id) != ''rdsadmin'' AND d.state = 0 AND (d.[' + @CurrentName + '] NOT IN (0, 60) OR d.[' + @CurrentName + '] IS NULL) OPTION (RECOMPILE);';
48874889
ELSE
48884890
SET @StringToExecute = 'INSERT INTO #BlitzResults (CheckID, DatabaseName, Priority, FindingsGroup, Finding, URL, Details)
48894891
SELECT ' + CAST(@CurrentCheckID AS NVARCHAR(200)) + ', d.[name], ' + CAST(@CurrentPriority AS NVARCHAR(200)) + ', ''Non-Default Database Config'', ''' + @CurrentFinding + ''',''' + @CurrentURL + ''',''' + COALESCE(@CurrentDetails, 'This database setting is not the default.') + '''
48904892
FROM sys.databases d
4891-
WHERE d.database_id > 4 AND d.state = 0 AND (d.[' + @CurrentName + '] <> ' + @CurrentDefaultValue + ' OR d.[' + @CurrentName + '] IS NULL) OPTION (RECOMPILE);';
4893+
WHERE d.database_id > 4 AND DB_NAME(d.database_id) != ''rdsadmin'' AND d.state = 0 AND (d.[' + @CurrentName + '] <> ' + @CurrentDefaultValue + ' OR d.[' + @CurrentName + '] IS NULL) OPTION (RECOMPILE);';
48924894

48934895
IF @Debug = 2 AND @StringToExecute IS NOT NULL PRINT @StringToExecute;
48944896
IF @Debug = 2 AND @StringToExecute IS NULL PRINT '@StringToExecute has gone NULL, for some reason.';
@@ -6873,7 +6875,7 @@ IF @ProductVersionMajor >= 10
68736875
''https://www.brentozar.com/go/querystore'',
68746876
(''The new SQL Server 2016 Query Store feature has not been enabled on this database.'')
68756877
FROM [?].sys.database_query_store_options WHERE desired_state = 0
6876-
AND N''?'' NOT IN (''master'', ''model'', ''msdb'', ''tempdb'', ''DWConfiguration'', ''DWDiagnostics'', ''DWQueue'', ''ReportServer'', ''ReportServerTempDB'') OPTION (RECOMPILE)';
6878+
AND ''?'' NOT IN (''master'', ''model'', ''msdb'', ''rdsadmin'', ''tempdb'', ''DWConfiguration'', ''DWDiagnostics'', ''DWQueue'', ''ReportServer'', ''ReportServerTempDB'') OPTION (RECOMPILE)';
68776879
END;
68786880

68796881
IF NOT EXISTS ( SELECT 1
@@ -6905,6 +6907,7 @@ IF @ProductVersionMajor >= 10
69056907
FROM [?].sys.database_query_store_options
69066908
WHERE desired_state <> 0
69076909
AND wait_stats_capture_mode = 0
6910+
AND ''?'' != ''rdsadmin''
69086911
OPTION (RECOMPILE)';
69096912
END;
69106913

@@ -6936,6 +6939,7 @@ IF @ProductVersionMajor >= 10
69366939
FROM [?].sys.database_query_store_options
69376940
WHERE desired_state <> 0
69386941
AND actual_state <> 2
6942+
AND ''?'' != ''rdsadmin''
69396943
OPTION (RECOMPILE)';
69406944
END;
69416945

@@ -6967,6 +6971,7 @@ IF @ProductVersionMajor >= 10
69676971
FROM [?].sys.database_query_store_options
69686972
WHERE desired_state <> 0
69696973
AND desired_state <> actual_state
6974+
AND ''?'' != ''rdsadmin''
69706975
OPTION (RECOMPILE)';
69716976
END;
69726977

@@ -7002,6 +7007,7 @@ IF @ProductVersionMajor >= 10
70027007
FROM [?].sys.database_query_store_options
70037008
WHERE desired_state <> 0 /* No point in checking this if Query Store is off. */
70047009
AND query_capture_mode_desc <> ''AUTO''
7010+
AND ''?'' != ''rdsadmin''
70057011
OPTION (RECOMPILE)';
70067012
END;
70077013

@@ -7032,7 +7038,9 @@ IF @ProductVersionMajor >= 10
70327038
''https://www.brentozar.com/go/cleanup'',
70337039
(''SQL 2016 RTM has a bug involving dumps that happen every time Query Store cleanup jobs run. This is fixed in CU1 and later: https://sqlserverupdates.com/sql-server-2016-updates/'')
70347040
FROM sys.databases AS d
7035-
WHERE d.is_query_store_on = 1 OPTION (RECOMPILE);';
7041+
WHERE d.is_query_store_on = 1
7042+
AND d.name != ''rdsadmin''
7043+
OPTION (RECOMPILE);';
70367044

70377045
IF @Debug = 2 AND @StringToExecute IS NOT NULL PRINT @StringToExecute;
70387046
IF @Debug = 2 AND @StringToExecute IS NULL PRINT '@StringToExecute has gone NULL, for some reason.';
@@ -7068,7 +7076,7 @@ IF @ProductVersionMajor >= 10
70687076
FROM [?].sys.database_query_store_options dqso
70697077
join master.sys.databases D on D.name = N''?''
70707078
WHERE ((dqso.actual_state = 0 AND D.is_query_store_on = 1) OR (dqso.actual_state <> 0 AND D.is_query_store_on = 0))
7071-
AND N''?'' NOT IN (''master'', ''model'', ''msdb'', ''tempdb'', ''DWConfiguration'', ''DWDiagnostics'', ''DWQueue'', ''ReportServer'', ''ReportServerTempDB'') OPTION (RECOMPILE)';
7079+
AND ''?'' NOT IN (''master'', ''model'', ''msdb'', ''rdsadmin'', ''tempdb'', ''DWConfiguration'', ''DWDiagnostics'', ''DWQueue'', ''ReportServer'', ''ReportServerTempDB'') OPTION (RECOMPILE)';
70727080
END;
70737081

70747082
IF NOT EXISTS ( SELECT 1
@@ -7096,7 +7104,7 @@ IF @ProductVersionMajor >= 10
70967104
''https://www.brentozar.com/go/manylogs'',
70977105
(''The ['' + DB_NAME() + ''] database has multiple log files on the '' + LEFT(physical_name, 1) + '' drive. This is not a performance booster because log file access is sequential, not parallel.'')
70987106
FROM [?].sys.database_files WHERE type_desc = ''LOG''
7099-
AND N''?'' <> ''[tempdb]''
7107+
AND ''?'' NOT IN (''rdsadmin'',''tempdb'')
71007108
GROUP BY LEFT(physical_name, 1)
71017109
HAVING COUNT(*) > 1
71027110
AND SUM(size) < 268435456 OPTION (RECOMPILE);';
@@ -7128,6 +7136,7 @@ IF @ProductVersionMajor >= 10
71287136
(''The ['' + DB_NAME() + ''] database has multiple data files in one filegroup, but they are not all set up to grow in identical amounts. This can lead to uneven file activity inside the filegroup.'')
71297137
FROM [?].sys.database_files
71307138
WHERE type_desc = ''ROWS''
7139+
AND ''?'' != ''rdsadmin''
71317140
GROUP BY data_space_id
71327141
HAVING COUNT(DISTINCT growth) > 1 OR COUNT(DISTINCT is_percent_growth) > 1 OPTION (RECOMPILE);';
71337142
END;
@@ -7156,7 +7165,9 @@ IF @ProductVersionMajor >= 10
71567165
''https://www.brentozar.com/go/percentgrowth'' AS URL,
71577166
''The ['' + DB_NAME() + ''] database file '' + f.physical_name + '' has grown to '' + CONVERT(NVARCHAR(20), CONVERT(NUMERIC(38, 2), (f.size / 128.) / 1024.)) + '' GB, and is using percent filegrowth settings. This can lead to slow performance during growths if Instant File Initialization is not enabled.''
71587167
FROM [?].sys.database_files f
7159-
WHERE is_percent_growth = 1 and size > 128000 OPTION (RECOMPILE);';
7168+
WHERE is_percent_growth = 1 and size > 128000
7169+
AND ''?'' != ''rdsadmin''
7170+
OPTION (RECOMPILE);';
71607171
END;
71617172

71627173
/* addition by Henrik Staun Poulsen, Stovi Software */
@@ -7184,7 +7195,9 @@ IF @ProductVersionMajor >= 10
71847195
''https://www.brentozar.com/go/percentgrowth'' AS URL,
71857196
''The ['' + DB_NAME() + ''] database file '' + f.physical_name + '' is using 1MB filegrowth settings, but it has grown to '' + CAST((CAST(f.size AS BIGINT) * 8 / 1000000) AS NVARCHAR(10)) + '' GB. Time to up the growth amount.''
71867197
FROM [?].sys.database_files f
7187-
WHERE is_percent_growth = 0 and growth=128 and size > 128000 OPTION (RECOMPILE);';
7198+
WHERE is_percent_growth = 0 and growth=128 and size > 128000
7199+
AND ''?'' != ''rdsadmin''
7200+
OPTION (RECOMPILE);';
71887201
END;
71897202

71907203
IF NOT EXISTS ( SELECT 1
@@ -7214,7 +7227,9 @@ IF @ProductVersionMajor >= 10
72147227
''Enterprise Edition Features In Use'',
72157228
''https://www.brentozar.com/go/ee'',
72167229
(''The ['' + DB_NAME() + ''] database is using '' + feature_name + ''. If this database is restored onto a Standard Edition server, the restore will fail on versions prior to 2016 SP1.'')
7217-
FROM [?].sys.dm_db_persisted_sku_features OPTION (RECOMPILE);';
7230+
FROM [?].sys.dm_db_persisted_sku_features
7231+
WHERE ''?'' != ''rdsadmin''
7232+
OPTION (RECOMPILE);';
72187233
END;
72197234
END;
72207235

@@ -7272,8 +7287,9 @@ IF @ProductVersionMajor >= 10
72727287
''https://www.brentozar.com/go/repl'',
72737288
(''['' + DB_NAME() + ''] has MSreplication_objects tables in it, indicating it is a replication subscriber.'')
72747289
FROM [?].sys.tables
7275-
WHERE name = ''dbo.MSreplication_objects'' AND ''?'' <> ''master'' OPTION (RECOMPILE)';
7276-
7290+
WHERE name = ''dbo.MSreplication_objects''
7291+
AND ''?'' NOT IN (''master'', ''rdsadmin'')
7292+
OPTION (RECOMPILE)';
72777293
END;
72787294

72797295
IF NOT EXISTS ( SELECT 1
@@ -7301,7 +7317,9 @@ IF @ProductVersionMajor >= 10
73017317
''https://www.brentozar.com/go/trig'',
73027318
(''The ['' + DB_NAME() + ''] database has '' + CAST(SUM(1) AS NVARCHAR(50)) + '' triggers.'')
73037319
FROM [?].sys.triggers t INNER JOIN [?].sys.objects o ON t.parent_id = o.object_id
7304-
INNER JOIN [?].sys.schemas s ON o.schema_id = s.schema_id WHERE t.is_ms_shipped = 0 AND DB_NAME() != ''ReportServer''
7320+
INNER JOIN [?].sys.schemas s ON o.schema_id = s.schema_id
7321+
WHERE t.is_ms_shipped = 0
7322+
AND ''?'' NOT IN (''rdsadmin'', ''ReportServer'')
73057323
HAVING SUM(1) > 0 OPTION (RECOMPILE)';
73067324
END;
73077325

@@ -7331,7 +7349,9 @@ IF @ProductVersionMajor >= 10
73317349
''Plan Guides Failing'',
73327350
''https://www.brentozar.com/go/misguided'',
73337351
(''The ['' + DB_NAME() + ''] database has plan guides that are no longer valid, so the queries involved may be failing silently.'')
7334-
FROM [?].sys.plan_guides g CROSS APPLY fn_validate_plan_guide(g.plan_guide_id) OPTION (RECOMPILE)';
7352+
FROM [?].sys.plan_guides g CROSS APPLY fn_validate_plan_guide(g.plan_guide_id)
7353+
WHERE ''?'' != ''rdsadmin''
7354+
OPTION (RECOMPILE)';
73357355
END;
73367356

73377357
IF NOT EXISTS ( SELECT 1
@@ -7359,7 +7379,9 @@ IF @ProductVersionMajor >= 10
73597379
''https://www.brentozar.com/go/hypo'',
73607380
(''The index ['' + DB_NAME() + ''].['' + s.name + ''].['' + o.name + ''].['' + i.name + ''] is a leftover hypothetical index from the Index Tuning Wizard or Database Tuning Advisor. This index is not actually helping performance and should be removed.'')
73617381
from [?].sys.indexes i INNER JOIN [?].sys.objects o ON i.object_id = o.object_id INNER JOIN [?].sys.schemas s ON o.schema_id = s.schema_id
7362-
WHERE i.is_hypothetical = 1 OPTION (RECOMPILE);';
7382+
WHERE i.is_hypothetical = 1
7383+
AND ''?'' != ''rdsadmin''
7384+
OPTION (RECOMPILE);';
73637385
END;
73647386

73657387
IF NOT EXISTS ( SELECT 1
@@ -7415,7 +7437,9 @@ IF @ProductVersionMajor >= 10
74157437
''https://www.brentozar.com/go/trust'',
74167438
(''The ['' + DB_NAME() + ''] database has foreign keys that were probably disabled, data was changed, and then the key was enabled again. Simply enabling the key is not enough for the optimizer to use this key - we have to alter the table using the WITH CHECK CHECK CONSTRAINT parameter.'')
74177439
from [?].sys.foreign_keys i INNER JOIN [?].sys.objects o ON i.parent_object_id = o.object_id INNER JOIN [?].sys.schemas s ON o.schema_id = s.schema_id
7418-
WHERE i.is_not_trusted = 1 AND i.is_not_for_replication = 0 AND i.is_disabled = 0 AND N''?'' NOT IN (''master'', ''model'', ''msdb'', ''ReportServer'', ''ReportServerTempDB'') OPTION (RECOMPILE);';
7440+
WHERE i.is_not_trusted = 1 AND i.is_not_for_replication = 0 AND i.is_disabled = 0 AND ''?''
7441+
NOT IN (''master'', ''model'', ''msdb'', ''rdsadmin'', ''ReportServer'', ''ReportServerTempDB'')
7442+
OPTION (RECOMPILE);';
74197443
END;
74207444

74217445
IF NOT EXISTS ( SELECT 1
@@ -7904,8 +7928,10 @@ EXEC dbo.sp_MSforeachdb 'USE [?]; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITT
79047928
INNER JOIN #DatabaseScopedConfigurationDefaults def1 ON dsc.configuration_id = def1.configuration_id
79057929
LEFT OUTER JOIN #DatabaseScopedConfigurationDefaults def ON dsc.configuration_id = def.configuration_id AND (cast(dsc.value as nvarchar(100)) = cast(def.default_value as nvarchar(100)) OR dsc.value IS NULL) AND (dsc.value_for_secondary = def.default_value_for_secondary OR dsc.value_for_secondary IS NULL)
79067930
LEFT OUTER JOIN #SkipChecks sk ON (sk.CheckID IS NULL OR def.CheckID = sk.CheckID) AND (sk.DatabaseName IS NULL OR sk.DatabaseName = DB_NAME())
7907-
WHERE def.configuration_id IS NULL AND sk.CheckID IS NULL ORDER BY 1
7908-
OPTION (RECOMPILE);';
7931+
WHERE def.configuration_id IS NULL AND sk.CheckID IS NULL
7932+
AND ''?'' != ''rdsadmin''
7933+
ORDER BY 1
7934+
OPTION (RECOMPILE);';
79097935
END;
79107936

79117937
/* Check 218 - Show me the dodgy SET Options */
@@ -7942,6 +7968,7 @@ EXEC dbo.sp_MSforeachdb 'USE [?]; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITT
79427968
OR sm.uses_quoted_identifier <> 1
79437969
)
79447970
AND o.is_ms_shipped = 0
7971+
AND ''?'' != ''rdsadmin''
79457972
HAVING COUNT(1) > 0;';
79467973
END; --of Check 218.
79477974

@@ -7973,7 +8000,9 @@ EXEC dbo.sp_MSforeachdb 'USE [?]; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITT
79738000
+ CAST(iro.sql_text AS NVARCHAR(1000)) AS Details
79748001
FROM sys.index_resumable_operations iro
79758002
JOIN sys.objects o ON iro.[object_id] = o.[object_id]
7976-
WHERE iro.state <> 0;';
8003+
WHERE iro.state <> 0
8004+
AND ''?'' != ''rdsadmin''
8005+
;';
79778006
END; --of Check 225.
79788007

79798008
--/* Check 220 - Statistics Without Histograms */
@@ -8007,7 +8036,7 @@ EXEC dbo.sp_MSforeachdb 'USE [?]; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITT
80078036
-- WHERE o.is_ms_shipped = 0 AND o.type_desc = ''USER_TABLE''
80088037
-- AND h.object_id IS NULL
80098038
-- AND 0 < (SELECT SUM(row_count) FROM sys.dm_db_partition_stats ps WHERE ps.object_id = o.object_id)
8010-
-- AND ''?'' NOT IN (''master'', ''model'', ''msdb'', ''tempdb'')
8039+
-- AND ''?'' NOT IN (''master'', ''model'', ''msdb'', ''rdsadmin'', ''tempdb'')
80118040
-- HAVING COUNT(DISTINCT o.object_id) > 0;';
80128041
--END; --of Check 220.
80138042

0 commit comments

Comments
 (0)