Skip to content

Commit 864d05a

Browse files
authored
Exclude checks for RDS objects and rdsadmin DB
See: #3712
1 parent 1b2a980 commit 864d05a

File tree

1 file changed

+62
-27
lines changed

1 file changed

+62
-27
lines changed

sp_Blitz.sql

Lines changed: 62 additions & 27 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.';
@@ -6776,7 +6778,12 @@ IF @ProductVersionMajor >= 10
67766778

67776779
IF @Debug IN (1, 2) RAISERROR('Running CheckId [%d].', 0, 1, 99) WITH NOWAIT;
67786780

6779-
EXEC dbo.sp_MSforeachdb 'USE [?]; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; IF EXISTS (SELECT * FROM sys.tables WITH (NOLOCK) WHERE name = ''sysmergepublications'' ) IF EXISTS ( SELECT * FROM sysmergepublications WITH (NOLOCK) WHERE retention = 0) INSERT INTO #BlitzResults (CheckID, DatabaseName, Priority, FindingsGroup, Finding, URL, Details) SELECT DISTINCT 99, DB_NAME(), 110, ''Performance'', ''Infinite merge replication metadata retention period'', ''https://www.brentozar.com/go/merge'', (''The ['' + DB_NAME() + ''] database has merge replication metadata retention period set to infinite - this can be the case of significant performance issues.'')';
6781+
EXEC dbo.sp_MSforeachdb 'USE [?];
6782+
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
6783+
IF EXISTS (SELECT * FROM sys.tables WITH (NOLOCK) WHERE name = ''sysmergepublications'' )
6784+
IF EXISTS ( SELECT * FROM sysmergepublications WITH (NOLOCK) WHERE retention = 0)
6785+
INSERT INTO #BlitzResults (CheckID, DatabaseName, Priority, FindingsGroup, Finding, URL, Details)
6786+
SELECT DISTINCT 99, DB_NAME(), 110, ''Performance'', ''Infinite merge replication metadata retention period'', ''https://www.brentozar.com/go/merge'', (''The ['' + DB_NAME() + ''] database has merge replication metadata retention period set to infinite - this can be the case of significant performance issues.'')';
67806787
END;
67816788
/*
67826789
Note that by using sp_MSforeachdb, we're running the query in all
@@ -6813,7 +6820,7 @@ IF @ProductVersionMajor >= 10
68136820
''https://www.brentozar.com/go/querystore'',
68146821
(''The new SQL Server 2016 Query Store feature has not been enabled on this database.'')
68156822
FROM [?].sys.database_query_store_options WHERE desired_state = 0
6816-
AND N''?'' NOT IN (''master'', ''model'', ''msdb'', ''tempdb'', ''DWConfiguration'', ''DWDiagnostics'', ''DWQueue'', ''ReportServer'', ''ReportServerTempDB'') OPTION (RECOMPILE)';
6823+
AND ''?'' NOT IN (''master'', ''model'', ''msdb'', ''rdsadmin'', ''tempdb'', ''DWConfiguration'', ''DWDiagnostics'', ''DWQueue'', ''ReportServer'', ''ReportServerTempDB'') OPTION (RECOMPILE)';
68176824
END;
68186825

68196826
IF NOT EXISTS ( SELECT 1
@@ -6845,6 +6852,7 @@ IF @ProductVersionMajor >= 10
68456852
FROM [?].sys.database_query_store_options
68466853
WHERE desired_state <> 0
68476854
AND wait_stats_capture_mode = 0
6855+
AND ''?'' != ''rdsadmin''
68486856
OPTION (RECOMPILE)';
68496857
END;
68506858

@@ -6876,6 +6884,7 @@ IF @ProductVersionMajor >= 10
68766884
FROM [?].sys.database_query_store_options
68776885
WHERE desired_state <> 0
68786886
AND actual_state <> 2
6887+
AND ''?'' != ''rdsadmin''
68796888
OPTION (RECOMPILE)';
68806889
END;
68816890

@@ -6907,6 +6916,7 @@ IF @ProductVersionMajor >= 10
69076916
FROM [?].sys.database_query_store_options
69086917
WHERE desired_state <> 0
69096918
AND desired_state <> actual_state
6919+
AND ''?'' != ''rdsadmin''
69106920
OPTION (RECOMPILE)';
69116921
END;
69126922

@@ -6942,6 +6952,7 @@ IF @ProductVersionMajor >= 10
69426952
FROM [?].sys.database_query_store_options
69436953
WHERE desired_state <> 0 /* No point in checking this if Query Store is off. */
69446954
AND query_capture_mode_desc <> ''AUTO''
6955+
AND ''?'' != ''rdsadmin''
69456956
OPTION (RECOMPILE)';
69466957
END;
69476958

@@ -6972,7 +6983,9 @@ IF @ProductVersionMajor >= 10
69726983
''https://www.brentozar.com/go/cleanup'',
69736984
(''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/'')
69746985
FROM sys.databases AS d
6975-
WHERE d.is_query_store_on = 1 OPTION (RECOMPILE);';
6986+
WHERE d.is_query_store_on = 1
6987+
AND d.name != ''rdsadmin''
6988+
OPTION (RECOMPILE);';
69766989

69776990
IF @Debug = 2 AND @StringToExecute IS NOT NULL PRINT @StringToExecute;
69786991
IF @Debug = 2 AND @StringToExecute IS NULL PRINT '@StringToExecute has gone NULL, for some reason.';
@@ -7008,7 +7021,7 @@ IF @ProductVersionMajor >= 10
70087021
FROM [?].sys.database_query_store_options dqso
70097022
join master.sys.databases D on D.name = N''?''
70107023
WHERE ((dqso.actual_state = 0 AND D.is_query_store_on = 1) OR (dqso.actual_state <> 0 AND D.is_query_store_on = 0))
7011-
AND N''?'' NOT IN (''master'', ''model'', ''msdb'', ''tempdb'', ''DWConfiguration'', ''DWDiagnostics'', ''DWQueue'', ''ReportServer'', ''ReportServerTempDB'') OPTION (RECOMPILE)';
7024+
AND ''?'' NOT IN (''master'', ''model'', ''msdb'', ''rdsadmin'', ''tempdb'', ''DWConfiguration'', ''DWDiagnostics'', ''DWQueue'', ''ReportServer'', ''ReportServerTempDB'') OPTION (RECOMPILE)';
70127025
END;
70137026

70147027
IF NOT EXISTS ( SELECT 1
@@ -7035,11 +7048,12 @@ IF @ProductVersionMajor >= 10
70357048
''Multiple Log Files on One Drive'',
70367049
''https://www.brentozar.com/go/manylogs'',
70377050
(''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.'')
7038-
FROM [?].sys.database_files WHERE type_desc = ''LOG''
7039-
AND N''?'' <> ''[tempdb]''
7051+
FROM [?].sys.database_files
7052+
WHERE type_desc = ''LOG''
7053+
AND ''?'' NOT IN (''rdsadmin'',''tempdb'')
70407054
GROUP BY LEFT(physical_name, 1)
7041-
HAVING COUNT(*) > 1
7042-
AND SUM(size) < 268435456 OPTION (RECOMPILE);';
7055+
HAVING COUNT(*) > 1 AND SUM(size) < 268435456
7056+
OPTION (RECOMPILE);';
70437057
END;
70447058

70457059
IF NOT EXISTS ( SELECT 1
@@ -7068,6 +7082,7 @@ IF @ProductVersionMajor >= 10
70687082
(''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.'')
70697083
FROM [?].sys.database_files
70707084
WHERE type_desc = ''ROWS''
7085+
AND ''?'' != ''rdsadmin''
70717086
GROUP BY data_space_id
70727087
HAVING COUNT(DISTINCT growth) > 1 OR COUNT(DISTINCT is_percent_growth) > 1 OPTION (RECOMPILE);';
70737088
END;
@@ -7096,7 +7111,9 @@ IF @ProductVersionMajor >= 10
70967111
''https://www.brentozar.com/go/percentgrowth'' AS URL,
70977112
''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.''
70987113
FROM [?].sys.database_files f
7099-
WHERE is_percent_growth = 1 and size > 128000 OPTION (RECOMPILE);';
7114+
WHERE is_percent_growth = 1 and size > 128000
7115+
AND ''?'' != ''rdsadmin''
7116+
OPTION (RECOMPILE);';
71007117
END;
71017118

71027119
/* addition by Henrik Staun Poulsen, Stovi Software */
@@ -7124,7 +7141,9 @@ IF @ProductVersionMajor >= 10
71247141
''https://www.brentozar.com/go/percentgrowth'' AS URL,
71257142
''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.''
71267143
FROM [?].sys.database_files f
7127-
WHERE is_percent_growth = 0 and growth=128 and size > 128000 OPTION (RECOMPILE);';
7144+
WHERE is_percent_growth = 0 and growth=128 and size > 128000
7145+
AND ''?'' != ''rdsadmin''
7146+
OPTION (RECOMPILE);';
71287147
END;
71297148

71307149
IF NOT EXISTS ( SELECT 1
@@ -7154,7 +7173,9 @@ IF @ProductVersionMajor >= 10
71547173
''Enterprise Edition Features In Use'',
71557174
''https://www.brentozar.com/go/ee'',
71567175
(''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.'')
7157-
FROM [?].sys.dm_db_persisted_sku_features OPTION (RECOMPILE);';
7176+
FROM [?].sys.dm_db_persisted_sku_features
7177+
WHERE ''?'' != ''rdsadmin''
7178+
OPTION (RECOMPILE);';
71587179
END;
71597180
END;
71607181

@@ -7212,8 +7233,9 @@ IF @ProductVersionMajor >= 10
72127233
''https://www.brentozar.com/go/repl'',
72137234
(''['' + DB_NAME() + ''] has MSreplication_objects tables in it, indicating it is a replication subscriber.'')
72147235
FROM [?].sys.tables
7215-
WHERE name = ''dbo.MSreplication_objects'' AND ''?'' <> ''master'' OPTION (RECOMPILE)';
7216-
7236+
WHERE name = ''dbo.MSreplication_objects''
7237+
AND ''?'' NOT IN (''master'', ''rdsadmin'')
7238+
OPTION (RECOMPILE)';
72177239
END;
72187240

72197241
IF NOT EXISTS ( SELECT 1
@@ -7241,7 +7263,9 @@ IF @ProductVersionMajor >= 10
72417263
''https://www.brentozar.com/go/trig'',
72427264
(''The ['' + DB_NAME() + ''] database has '' + CAST(SUM(1) AS NVARCHAR(50)) + '' triggers.'')
72437265
FROM [?].sys.triggers t INNER JOIN [?].sys.objects o ON t.parent_id = o.object_id
7244-
INNER JOIN [?].sys.schemas s ON o.schema_id = s.schema_id WHERE t.is_ms_shipped = 0 AND DB_NAME() != ''ReportServer''
7266+
INNER JOIN [?].sys.schemas s ON o.schema_id = s.schema_id
7267+
WHERE t.is_ms_shipped = 0
7268+
AND ''?'' NOT IN (''rdsadmin'', ''ReportServer'')
72457269
HAVING SUM(1) > 0 OPTION (RECOMPILE)';
72467270
END;
72477271

@@ -7271,7 +7295,9 @@ IF @ProductVersionMajor >= 10
72717295
''Plan Guides Failing'',
72727296
''https://www.brentozar.com/go/misguided'',
72737297
(''The ['' + DB_NAME() + ''] database has plan guides that are no longer valid, so the queries involved may be failing silently.'')
7274-
FROM [?].sys.plan_guides g CROSS APPLY fn_validate_plan_guide(g.plan_guide_id) OPTION (RECOMPILE)';
7298+
FROM [?].sys.plan_guides g CROSS APPLY fn_validate_plan_guide(g.plan_guide_id)
7299+
WHERE ''?'' != ''rdsadmin''
7300+
OPTION (RECOMPILE)';
72757301
END;
72767302

72777303
IF NOT EXISTS ( SELECT 1
@@ -7299,7 +7325,9 @@ IF @ProductVersionMajor >= 10
72997325
''https://www.brentozar.com/go/hypo'',
73007326
(''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.'')
73017327
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
7302-
WHERE i.is_hypothetical = 1 OPTION (RECOMPILE);';
7328+
WHERE i.is_hypothetical = 1
7329+
AND ''?'' != ''rdsadmin''
7330+
OPTION (RECOMPILE);';
73037331
END;
73047332

73057333
IF NOT EXISTS ( SELECT 1
@@ -7355,7 +7383,9 @@ IF @ProductVersionMajor >= 10
73557383
''https://www.brentozar.com/go/trust'',
73567384
(''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.'')
73577385
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
7358-
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);';
7386+
WHERE i.is_not_trusted = 1 AND i.is_not_for_replication = 0 AND i.is_disabled = 0 AND ''?''
7387+
NOT IN (''master'', ''model'', ''msdb'', ''rdsadmin'', ''ReportServer'', ''ReportServerTempDB'')
7388+
OPTION (RECOMPILE);';
73597389
END;
73607390

73617391
IF NOT EXISTS ( SELECT 1
@@ -7844,8 +7874,10 @@ EXEC dbo.sp_MSforeachdb 'USE [?]; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITT
78447874
INNER JOIN #DatabaseScopedConfigurationDefaults def1 ON dsc.configuration_id = def1.configuration_id
78457875
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)
78467876
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())
7847-
WHERE def.configuration_id IS NULL AND sk.CheckID IS NULL ORDER BY 1
7848-
OPTION (RECOMPILE);';
7877+
WHERE def.configuration_id IS NULL AND sk.CheckID IS NULL
7878+
AND ''?'' != ''rdsadmin''
7879+
ORDER BY 1
7880+
OPTION (RECOMPILE);';
78497881
END;
78507882

78517883
/* Check 218 - Show me the dodgy SET Options */
@@ -7882,6 +7914,7 @@ EXEC dbo.sp_MSforeachdb 'USE [?]; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITT
78827914
OR sm.uses_quoted_identifier <> 1
78837915
)
78847916
AND o.is_ms_shipped = 0
7917+
AND ''?'' != ''rdsadmin''
78857918
HAVING COUNT(1) > 0;';
78867919
END; --of Check 218.
78877920

@@ -7913,7 +7946,9 @@ EXEC dbo.sp_MSforeachdb 'USE [?]; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITT
79137946
+ CAST(iro.sql_text AS NVARCHAR(1000)) AS Details
79147947
FROM sys.index_resumable_operations iro
79157948
JOIN sys.objects o ON iro.[object_id] = o.[object_id]
7916-
WHERE iro.state <> 0;';
7949+
WHERE iro.state <> 0
7950+
AND ''?'' != ''rdsadmin''
7951+
;';
79177952
END; --of Check 225.
79187953

79197954
--/* Check 220 - Statistics Without Histograms */
@@ -7947,7 +7982,7 @@ EXEC dbo.sp_MSforeachdb 'USE [?]; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITT
79477982
-- WHERE o.is_ms_shipped = 0 AND o.type_desc = ''USER_TABLE''
79487983
-- AND h.object_id IS NULL
79497984
-- AND 0 < (SELECT SUM(row_count) FROM sys.dm_db_partition_stats ps WHERE ps.object_id = o.object_id)
7950-
-- AND ''?'' NOT IN (''master'', ''model'', ''msdb'', ''tempdb'')
7985+
-- AND ''?'' NOT IN (''master'', ''model'', ''msdb'', ''rdsadmin'', ''tempdb'')
79517986
-- HAVING COUNT(DISTINCT o.object_id) > 0;';
79527987
--END; --of Check 220.
79537988

0 commit comments

Comments
 (0)