You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sp_Blitz.sql
+62-27Lines changed: 62 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -570,8 +570,7 @@ AS
570
570
SELECT
571
571
DB_NAME(d.database_id)
572
572
FROMsys.databasesAS d
573
-
WHERE (DB_NAME(d.database_id) LIKE'rdsadmin%'
574
-
ORLOWER(d.name) IN ('dbatools', 'dbadmin', 'dbmaintenance'))
573
+
WHERELOWER(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,7 +2046,9 @@ AS
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 =2AND @StringToExecute ISNOTNULLPRINT @StringToExecute;
2053
2054
IF @Debug =2AND @StringToExecute ISNULLPRINT'@StringToExecute has gone NULL, for some reason.';
@@ -2706,7 +2707,8 @@ AS
2706
2707
+'. Tables in the master database may not be restored in the event of a disaster.' ) AS Details
/* 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 ASNVARCHAR(200)) +', d.[name], '+CAST(@CurrentPriority ASNVARCHAR(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 ASNVARCHAR(200)) +', d.[name], '+CAST(@CurrentPriority ASNVARCHAR(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 =2AND @StringToExecute ISNOTNULLPRINT @StringToExecute;
4894
4896
IF @Debug =2AND @StringToExecute ISNULLPRINT'@StringToExecute has gone NULL, for some reason.';
@@ -6776,7 +6778,12 @@ IF @ProductVersionMajor >= 10
6776
6778
6777
6779
IF @Debug IN (1, 2) RAISERROR('Running CheckId [%d].', 0, 1, 99) WITHNOWAIT;
6778
6780
6779
-
EXECdbo.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
+
EXECdbo.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.'')';
6780
6787
END;
6781
6788
/*
6782
6789
Note that by using sp_MSforeachdb, we're running the query in all
@@ -6813,7 +6820,7 @@ IF @ProductVersionMajor >= 10
6813
6820
''https://www.brentozar.com/go/querystore'',
6814
6821
(''The new SQL Server 2016 Query Store feature has not been enabled on this database.'')
6815
6822
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)';
6817
6824
END;
6818
6825
6819
6826
IFNOTEXISTS ( SELECT1
@@ -6845,6 +6852,7 @@ IF @ProductVersionMajor >= 10
6845
6852
FROM [?].sys.database_query_store_options
6846
6853
WHERE desired_state <> 0
6847
6854
AND wait_stats_capture_mode = 0
6855
+
AND ''?'' != ''rdsadmin''
6848
6856
OPTION (RECOMPILE)';
6849
6857
END;
6850
6858
@@ -6876,6 +6884,7 @@ IF @ProductVersionMajor >= 10
6876
6884
FROM [?].sys.database_query_store_options
6877
6885
WHERE desired_state <> 0
6878
6886
AND actual_state <> 2
6887
+
AND ''?'' != ''rdsadmin''
6879
6888
OPTION (RECOMPILE)';
6880
6889
END;
6881
6890
@@ -6907,6 +6916,7 @@ IF @ProductVersionMajor >= 10
6907
6916
FROM [?].sys.database_query_store_options
6908
6917
WHERE desired_state <> 0
6909
6918
AND desired_state <> actual_state
6919
+
AND ''?'' != ''rdsadmin''
6910
6920
OPTION (RECOMPILE)';
6911
6921
END;
6912
6922
@@ -6942,6 +6952,7 @@ IF @ProductVersionMajor >= 10
6942
6952
FROM [?].sys.database_query_store_options
6943
6953
WHERE desired_state <> 0 /* No point in checking this if Query Store is off. */
6944
6954
AND query_capture_mode_desc <> ''AUTO''
6955
+
AND ''?'' != ''rdsadmin''
6945
6956
OPTION (RECOMPILE)';
6946
6957
END;
6947
6958
@@ -6972,7 +6983,9 @@ IF @ProductVersionMajor >= 10
6972
6983
''https://www.brentozar.com/go/cleanup'',
6973
6984
(''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/'')
6974
6985
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);';
6976
6989
6977
6990
IF @Debug =2AND @StringToExecute ISNOTNULLPRINT @StringToExecute;
6978
6991
IF @Debug =2AND @StringToExecute ISNULLPRINT'@StringToExecute has gone NULL, for some reason.';
@@ -7008,7 +7021,7 @@ IF @ProductVersionMajor >= 10
7008
7021
FROM [?].sys.database_query_store_options dqso
7009
7022
join master.sys.databases D on D.name = N''?''
7010
7023
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)';
7012
7025
END;
7013
7026
7014
7027
IFNOTEXISTS ( SELECT1
@@ -7035,11 +7048,12 @@ IF @ProductVersionMajor >= 10
7035
7048
''Multiple Log Files on One Drive'',
7036
7049
''https://www.brentozar.com/go/manylogs'',
7037
7050
(''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'')
7040
7054
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);';
7043
7057
END;
7044
7058
7045
7059
IFNOTEXISTS ( SELECT1
@@ -7068,6 +7082,7 @@ IF @ProductVersionMajor >= 10
7068
7082
(''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.'')
7069
7083
FROM [?].sys.database_files
7070
7084
WHERE type_desc = ''ROWS''
7085
+
AND ''?'' != ''rdsadmin''
7071
7086
GROUP BY data_space_id
7072
7087
HAVING COUNT(DISTINCT growth) > 1 OR COUNT(DISTINCT is_percent_growth) > 1 OPTION (RECOMPILE);';
7073
7088
END;
@@ -7096,7 +7111,9 @@ IF @ProductVersionMajor >= 10
7096
7111
''https://www.brentozar.com/go/percentgrowth'' AS URL,
7097
7112
''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.''
7098
7113
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);';
7100
7117
END;
7101
7118
7102
7119
/* addition by Henrik Staun Poulsen, Stovi Software */
@@ -7124,7 +7141,9 @@ IF @ProductVersionMajor >= 10
7124
7141
''https://www.brentozar.com/go/percentgrowth'' AS URL,
7125
7142
''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.''
7126
7143
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);';
7128
7147
END;
7129
7148
7130
7149
IFNOTEXISTS ( SELECT1
@@ -7154,7 +7173,9 @@ IF @ProductVersionMajor >= 10
7154
7173
''Enterprise Edition Features In Use'',
7155
7174
''https://www.brentozar.com/go/ee'',
7156
7175
(''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);';
7158
7179
END;
7159
7180
END;
7160
7181
@@ -7212,8 +7233,9 @@ IF @ProductVersionMajor >= 10
7212
7233
''https://www.brentozar.com/go/repl'',
7213
7234
(''['' + DB_NAME() + ''] has MSreplication_objects tables in it, indicating it is a replication subscriber.'')
7214
7235
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)';
7217
7239
END;
7218
7240
7219
7241
IFNOTEXISTS ( SELECT1
@@ -7241,7 +7263,9 @@ IF @ProductVersionMajor >= 10
7241
7263
''https://www.brentozar.com/go/trig'',
7242
7264
(''The ['' + DB_NAME() + ''] database has '' + CAST(SUM(1) AS NVARCHAR(50)) + '' triggers.'')
7243
7265
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'')
7245
7269
HAVING SUM(1) > 0 OPTION (RECOMPILE)';
7246
7270
END;
7247
7271
@@ -7271,7 +7295,9 @@ IF @ProductVersionMajor >= 10
7271
7295
''Plan Guides Failing'',
7272
7296
''https://www.brentozar.com/go/misguided'',
7273
7297
(''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)';
7275
7301
END;
7276
7302
7277
7303
IFNOTEXISTS ( SELECT1
@@ -7299,7 +7325,9 @@ IF @ProductVersionMajor >= 10
7299
7325
''https://www.brentozar.com/go/hypo'',
7300
7326
(''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.'')
7301
7327
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);';
7303
7331
END;
7304
7332
7305
7333
IFNOTEXISTS ( SELECT1
@@ -7355,7 +7383,9 @@ IF @ProductVersionMajor >= 10
7355
7383
''https://www.brentozar.com/go/trust'',
7356
7384
(''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.'')
7357
7385
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'')
INNER JOIN #DatabaseScopedConfigurationDefaults def1 ON dsc.configuration_id = def1.configuration_id
7845
7875
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)
7846
7876
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
0 commit comments