|
570 | 570 | SELECT |
571 | 571 | DB_NAME(d.database_id) |
572 | 572 | 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') |
575 | 574 | OPTION(RECOMPILE); |
576 | 575 |
|
577 | 576 | /*Skip checks for database where we don't have read permissions*/ |
|
2047 | 2046 | ''Performance'' AS FindingsGroup, |
2048 | 2047 | ''Server Triggers Enabled'' AS Finding, |
2049 | 2048 | ''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);'; |
2051 | 2052 |
|
2052 | 2053 | IF @Debug = 2 AND @StringToExecute IS NOT NULL PRINT @StringToExecute; |
2053 | 2054 | IF @Debug = 2 AND @StringToExecute IS NULL PRINT '@StringToExecute has gone NULL, for some reason.'; |
|
2706 | 2707 | + '. Tables in the master database may not be restored in the event of a disaster.' ) AS Details |
2707 | 2708 | FROM master.sys.tables |
2708 | 2709 | 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 '^'; |
2710 | 2712 | /* That last one is the Dynamics NAV licensing table: https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/issues/2426 */ |
2711 | 2713 | END; |
2712 | 2714 |
|
@@ -4883,12 +4885,12 @@ AS |
4883 | 4885 | SET @StringToExecute = 'INSERT INTO #BlitzResults (CheckID, DatabaseName, Priority, FindingsGroup, Finding, URL, Details) |
4884 | 4886 | 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.') + ''' |
4885 | 4887 | 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);'; |
4887 | 4889 | ELSE |
4888 | 4890 | SET @StringToExecute = 'INSERT INTO #BlitzResults (CheckID, DatabaseName, Priority, FindingsGroup, Finding, URL, Details) |
4889 | 4891 | 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.') + ''' |
4890 | 4892 | 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);'; |
4892 | 4894 |
|
4893 | 4895 | IF @Debug = 2 AND @StringToExecute IS NOT NULL PRINT @StringToExecute; |
4894 | 4896 | IF @Debug = 2 AND @StringToExecute IS NULL PRINT '@StringToExecute has gone NULL, for some reason.'; |
@@ -6873,7 +6875,7 @@ IF @ProductVersionMajor >= 10 |
6873 | 6875 | ''https://www.brentozar.com/go/querystore'', |
6874 | 6876 | (''The new SQL Server 2016 Query Store feature has not been enabled on this database.'') |
6875 | 6877 | 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)'; |
6877 | 6879 | END; |
6878 | 6880 |
|
6879 | 6881 | IF NOT EXISTS ( SELECT 1 |
@@ -6905,6 +6907,7 @@ IF @ProductVersionMajor >= 10 |
6905 | 6907 | FROM [?].sys.database_query_store_options |
6906 | 6908 | WHERE desired_state <> 0 |
6907 | 6909 | AND wait_stats_capture_mode = 0 |
| 6910 | + AND ''?'' != ''rdsadmin'' |
6908 | 6911 | OPTION (RECOMPILE)'; |
6909 | 6912 | END; |
6910 | 6913 |
|
@@ -6936,6 +6939,7 @@ IF @ProductVersionMajor >= 10 |
6936 | 6939 | FROM [?].sys.database_query_store_options |
6937 | 6940 | WHERE desired_state <> 0 |
6938 | 6941 | AND actual_state <> 2 |
| 6942 | + AND ''?'' != ''rdsadmin'' |
6939 | 6943 | OPTION (RECOMPILE)'; |
6940 | 6944 | END; |
6941 | 6945 |
|
@@ -6967,6 +6971,7 @@ IF @ProductVersionMajor >= 10 |
6967 | 6971 | FROM [?].sys.database_query_store_options |
6968 | 6972 | WHERE desired_state <> 0 |
6969 | 6973 | AND desired_state <> actual_state |
| 6974 | + AND ''?'' != ''rdsadmin'' |
6970 | 6975 | OPTION (RECOMPILE)'; |
6971 | 6976 | END; |
6972 | 6977 |
|
@@ -7002,6 +7007,7 @@ IF @ProductVersionMajor >= 10 |
7002 | 7007 | FROM [?].sys.database_query_store_options |
7003 | 7008 | WHERE desired_state <> 0 /* No point in checking this if Query Store is off. */ |
7004 | 7009 | AND query_capture_mode_desc <> ''AUTO'' |
| 7010 | + AND ''?'' != ''rdsadmin'' |
7005 | 7011 | OPTION (RECOMPILE)'; |
7006 | 7012 | END; |
7007 | 7013 |
|
@@ -7032,7 +7038,9 @@ IF @ProductVersionMajor >= 10 |
7032 | 7038 | ''https://www.brentozar.com/go/cleanup'', |
7033 | 7039 | (''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/'') |
7034 | 7040 | 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);'; |
7036 | 7044 |
|
7037 | 7045 | IF @Debug = 2 AND @StringToExecute IS NOT NULL PRINT @StringToExecute; |
7038 | 7046 | IF @Debug = 2 AND @StringToExecute IS NULL PRINT '@StringToExecute has gone NULL, for some reason.'; |
@@ -7068,7 +7076,7 @@ IF @ProductVersionMajor >= 10 |
7068 | 7076 | FROM [?].sys.database_query_store_options dqso |
7069 | 7077 | join master.sys.databases D on D.name = N''?'' |
7070 | 7078 | 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)'; |
7072 | 7080 | END; |
7073 | 7081 |
|
7074 | 7082 | IF NOT EXISTS ( SELECT 1 |
@@ -7096,7 +7104,7 @@ IF @ProductVersionMajor >= 10 |
7096 | 7104 | ''https://www.brentozar.com/go/manylogs'', |
7097 | 7105 | (''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.'') |
7098 | 7106 | FROM [?].sys.database_files WHERE type_desc = ''LOG'' |
7099 | | - AND N''?'' <> ''[tempdb]'' |
| 7107 | + AND ''?'' NOT IN (''rdsadmin'',''tempdb'') |
7100 | 7108 | GROUP BY LEFT(physical_name, 1) |
7101 | 7109 | HAVING COUNT(*) > 1 |
7102 | 7110 | AND SUM(size) < 268435456 OPTION (RECOMPILE);'; |
@@ -7128,6 +7136,7 @@ IF @ProductVersionMajor >= 10 |
7128 | 7136 | (''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.'') |
7129 | 7137 | FROM [?].sys.database_files |
7130 | 7138 | WHERE type_desc = ''ROWS'' |
| 7139 | + AND ''?'' != ''rdsadmin'' |
7131 | 7140 | GROUP BY data_space_id |
7132 | 7141 | HAVING COUNT(DISTINCT growth) > 1 OR COUNT(DISTINCT is_percent_growth) > 1 OPTION (RECOMPILE);'; |
7133 | 7142 | END; |
@@ -7156,7 +7165,9 @@ IF @ProductVersionMajor >= 10 |
7156 | 7165 | ''https://www.brentozar.com/go/percentgrowth'' AS URL, |
7157 | 7166 | ''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.'' |
7158 | 7167 | 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);'; |
7160 | 7171 | END; |
7161 | 7172 |
|
7162 | 7173 | /* addition by Henrik Staun Poulsen, Stovi Software */ |
@@ -7184,7 +7195,9 @@ IF @ProductVersionMajor >= 10 |
7184 | 7195 | ''https://www.brentozar.com/go/percentgrowth'' AS URL, |
7185 | 7196 | ''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.'' |
7186 | 7197 | 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);'; |
7188 | 7201 | END; |
7189 | 7202 |
|
7190 | 7203 | IF NOT EXISTS ( SELECT 1 |
@@ -7214,7 +7227,9 @@ IF @ProductVersionMajor >= 10 |
7214 | 7227 | ''Enterprise Edition Features In Use'', |
7215 | 7228 | ''https://www.brentozar.com/go/ee'', |
7216 | 7229 | (''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);'; |
7218 | 7233 | END; |
7219 | 7234 | END; |
7220 | 7235 |
|
@@ -7272,8 +7287,9 @@ IF @ProductVersionMajor >= 10 |
7272 | 7287 | ''https://www.brentozar.com/go/repl'', |
7273 | 7288 | (''['' + DB_NAME() + ''] has MSreplication_objects tables in it, indicating it is a replication subscriber.'') |
7274 | 7289 | 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)'; |
7277 | 7293 | END; |
7278 | 7294 |
|
7279 | 7295 | IF NOT EXISTS ( SELECT 1 |
@@ -7301,7 +7317,9 @@ IF @ProductVersionMajor >= 10 |
7301 | 7317 | ''https://www.brentozar.com/go/trig'', |
7302 | 7318 | (''The ['' + DB_NAME() + ''] database has '' + CAST(SUM(1) AS NVARCHAR(50)) + '' triggers.'') |
7303 | 7319 | 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'') |
7305 | 7323 | HAVING SUM(1) > 0 OPTION (RECOMPILE)'; |
7306 | 7324 | END; |
7307 | 7325 |
|
@@ -7331,7 +7349,9 @@ IF @ProductVersionMajor >= 10 |
7331 | 7349 | ''Plan Guides Failing'', |
7332 | 7350 | ''https://www.brentozar.com/go/misguided'', |
7333 | 7351 | (''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)'; |
7335 | 7355 | END; |
7336 | 7356 |
|
7337 | 7357 | IF NOT EXISTS ( SELECT 1 |
@@ -7359,7 +7379,9 @@ IF @ProductVersionMajor >= 10 |
7359 | 7379 | ''https://www.brentozar.com/go/hypo'', |
7360 | 7380 | (''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.'') |
7361 | 7381 | 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);'; |
7363 | 7385 | END; |
7364 | 7386 |
|
7365 | 7387 | IF NOT EXISTS ( SELECT 1 |
@@ -7415,7 +7437,9 @@ IF @ProductVersionMajor >= 10 |
7415 | 7437 | ''https://www.brentozar.com/go/trust'', |
7416 | 7438 | (''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.'') |
7417 | 7439 | 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);'; |
7419 | 7443 | END; |
7420 | 7444 |
|
7421 | 7445 | IF NOT EXISTS ( SELECT 1 |
@@ -7904,8 +7928,10 @@ EXEC dbo.sp_MSforeachdb 'USE [?]; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITT |
7904 | 7928 | INNER JOIN #DatabaseScopedConfigurationDefaults def1 ON dsc.configuration_id = def1.configuration_id |
7905 | 7929 | 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) |
7906 | 7930 | 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);'; |
7909 | 7935 | END; |
7910 | 7936 |
|
7911 | 7937 | /* Check 218 - Show me the dodgy SET Options */ |
@@ -7942,6 +7968,7 @@ EXEC dbo.sp_MSforeachdb 'USE [?]; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITT |
7942 | 7968 | OR sm.uses_quoted_identifier <> 1 |
7943 | 7969 | ) |
7944 | 7970 | AND o.is_ms_shipped = 0 |
| 7971 | + AND ''?'' != ''rdsadmin'' |
7945 | 7972 | HAVING COUNT(1) > 0;'; |
7946 | 7973 | END; --of Check 218. |
7947 | 7974 |
|
@@ -7973,7 +8000,9 @@ EXEC dbo.sp_MSforeachdb 'USE [?]; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITT |
7973 | 8000 | + CAST(iro.sql_text AS NVARCHAR(1000)) AS Details |
7974 | 8001 | FROM sys.index_resumable_operations iro |
7975 | 8002 | 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 | + ;'; |
7977 | 8006 | END; --of Check 225. |
7978 | 8007 |
|
7979 | 8008 | --/* Check 220 - Statistics Without Histograms */ |
@@ -8007,7 +8036,7 @@ EXEC dbo.sp_MSforeachdb 'USE [?]; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITT |
8007 | 8036 | -- WHERE o.is_ms_shipped = 0 AND o.type_desc = ''USER_TABLE'' |
8008 | 8037 | -- AND h.object_id IS NULL |
8009 | 8038 | -- 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'') |
8011 | 8040 | -- HAVING COUNT(DISTINCT o.object_id) > 0;'; |
8012 | 8041 | --END; --of Check 220. |
8013 | 8042 |
|
|
0 commit comments