Skip to content

Commit b4569d3

Browse files
2 parents 4512041 + cb01d5a commit b4569d3

18 files changed

Lines changed: 2131 additions & 1364 deletions

Install-All-Scripts.sql

Lines changed: 658 additions & 413 deletions
Large diffs are not rendered by default.

Install-Core-Blitz-No-Query-Store.sql

Lines changed: 579 additions & 403 deletions
Large diffs are not rendered by default.

Install-Core-Blitz-With-Query-Store.sql

Lines changed: 653 additions & 408 deletions
Large diffs are not rendered by default.

SqlServerVersions.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ DELETE FROM dbo.SqlServerVersions;
4141
INSERT INTO dbo.SqlServerVersions
4242
(MajorVersionNumber, MinorVersionNumber, Branch, [Url], ReleaseDate, MainstreamSupportEndDate, ExtendedSupportEndDate, MajorVersionName, MinorVersionName)
4343
VALUES
44+
(16, 4075, 'CU8', 'https://support.microsoft.com/en-us/help/5029666', '2023-09-14', '2028-01-11', '2033-01-11', 'SQL Server 2022', 'Cumulative Update 8'),
4445
(16, 4065, 'CU7', 'https://support.microsoft.com/en-us/help/5028743', '2023-08-10', '2028-01-11', '2033-01-11', 'SQL Server 2022', 'Cumulative Update 7'),
4546
(16, 4055, 'CU6', 'https://support.microsoft.com/en-us/help/5027505', '2023-07-13', '2028-01-11', '2033-01-11', 'SQL Server 2022', 'Cumulative Update 6'),
4647
(16, 4045, 'CU5', 'https://support.microsoft.com/en-us/help/5026806', '2023-06-15', '2028-01-11', '2033-01-11', 'SQL Server 2022', 'Cumulative Update 5'),

sp_AllNightLog.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ SET STATISTICS XML OFF;
3131
BEGIN;
3232

3333

34-
SELECT @Version = '8.16', @VersionDate = '20230820';
34+
SELECT @Version = '8.17', @VersionDate = '20231010';
3535

3636
IF(@VersionCheckMode = 1)
3737
BEGIN

sp_AllNightLog_Setup.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ SET STATISTICS XML OFF;
3838

3939
BEGIN;
4040

41-
SELECT @Version = '8.16', @VersionDate = '20230820';
41+
SELECT @Version = '8.17', @VersionDate = '20231010';
4242

4343
IF(@VersionCheckMode = 1)
4444
BEGIN

sp_Blitz.sql

Lines changed: 138 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ AS
3838
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
3939

4040

41-
SELECT @Version = '8.16', @VersionDate = '20230820';
41+
SELECT @Version = '8.17', @VersionDate = '20231010';
4242
SET @OutputType = UPPER(@OutputType);
4343

4444
IF(@VersionCheckMode = 1)
@@ -199,7 +199,11 @@ AS
199199
,@SkipMSDB bit = 0
200200
,@SkipModel bit = 0
201201
,@SkipTempDB bit = 0
202-
,@SkipValidateLogins bit = 0;
202+
,@SkipValidateLogins bit = 0
203+
/* Variables for check 211: */
204+
,@powerScheme varchar(36)
205+
,@cpu_speed_mhz int
206+
,@cpu_speed_ghz decimal(18,2);
203207

204208
DECLARE
205209
@db_perms table
@@ -225,6 +229,16 @@ AS
225229
/* End of declarations for First Responder Kit consistency check:*/
226230
;
227231

232+
/* Create temp table for check 2301 */
233+
IF OBJECT_ID('tempdb..#InvalidLogins') IS NOT NULL
234+
EXEC sp_executesql N'DROP TABLE #InvalidLogins;';
235+
236+
CREATE TABLE #InvalidLogins
237+
(
238+
LoginSID varbinary(85),
239+
LoginName VARCHAR(256)
240+
);
241+
228242
/*Starting permissions checks here, but only if we're not a sysadmin*/
229243
IF
230244
(
@@ -264,16 +278,37 @@ AS
264278
SET @SkipTrace = 1;
265279
END; /*We need this permission to execute trace stuff, apparently*/
266280

267-
IF NOT EXISTS
268-
(
269-
SELECT
270-
1/0
271-
FROM fn_my_permissions(N'xp_regread', N'OBJECT') AS fmp
272-
WHERE fmp.permission_name = N'EXECUTE'
273-
)
274-
BEGIN
275-
SET @SkipXPRegRead = 1;
276-
END; /*Need execute on xp_regread*/
281+
IF ISNULL(@SkipXPRegRead, 0) != 1 /*If @SkipXPRegRead hasn't been set to 1 by the caller*/
282+
BEGIN
283+
BEGIN TRY
284+
/* Get power plan if set by group policy [Git Hub Issue #1620] */
285+
EXEC xp_regread @rootkey = N'HKEY_LOCAL_MACHINE',
286+
@key = N'SOFTWARE\Policies\Microsoft\Power\PowerSettings',
287+
@value_name = N'ActivePowerScheme',
288+
@value = @powerScheme OUTPUT,
289+
@no_output = N'no_output';
290+
291+
IF @powerScheme IS NULL /* If power plan was not set by group policy, get local value [Git Hub Issue #1620]*/
292+
EXEC xp_regread @rootkey = N'HKEY_LOCAL_MACHINE',
293+
@key = N'SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes',
294+
@value_name = N'ActivePowerScheme',
295+
@value = @powerScheme OUTPUT;
296+
297+
/* Get the cpu speed*/
298+
EXEC xp_regread @rootkey = N'HKEY_LOCAL_MACHINE',
299+
@key = N'HARDWARE\DESCRIPTION\System\CentralProcessor\0',
300+
@value_name = N'~MHz',
301+
@value = @cpu_speed_mhz OUTPUT;
302+
303+
/* Convert the Megahertz to Gigahertz */
304+
SET @cpu_speed_ghz = CAST(CAST(@cpu_speed_mhz AS decimal) / 1000 AS decimal(18,2));
305+
306+
SET @SkipXPRegRead = 0; /*We could execute xp_regread*/
307+
END TRY
308+
BEGIN CATCH
309+
SET @SkipXPRegRead = 1; /*We have don't have execute rights or xp_regread throws an error so skip it*/
310+
END CATCH;
311+
END; /*Need execute on xp_regread*/
277312

278313
IF NOT EXISTS
279314
(
@@ -297,16 +332,23 @@ AS
297332
SET @SkipXPCMDShell = 1;
298333
END; /*Need execute on xp_cmdshell*/
299334

300-
IF NOT EXISTS
301-
(
302-
SELECT
303-
1/0
304-
FROM fn_my_permissions(N'sp_validatelogins', N'OBJECT') AS fmp
305-
WHERE fmp.permission_name = N'EXECUTE'
306-
)
307-
BEGIN
308-
SET @SkipValidateLogins = 1;
309-
END; /*Need execute on sp_validatelogins*/
335+
IF ISNULL(@SkipValidateLogins, 0) != 1 /*If @SkipValidateLogins hasn't been set to 1 by the caller*/
336+
BEGIN
337+
BEGIN TRY
338+
/* Try to fill the table for check 2301 */
339+
INSERT INTO #InvalidLogins
340+
(
341+
[LoginSID]
342+
,[LoginName]
343+
)
344+
EXEC sp_validatelogins;
345+
346+
SET @SkipValidateLogins = 0; /*We can execute sp_validatelogins*/
347+
END TRY
348+
BEGIN CATCH
349+
SET @SkipValidateLogins = 1; /*We have don't have execute rights or sp_validatelogins throws an error so skip it*/
350+
END CATCH;
351+
END; /*Need execute on sp_validatelogins*/
310352

311353
IF ISNULL(@SkipModel, 0) != 1 /*If @SkipModel hasn't been set to 1 by the caller*/
312354
BEGIN
@@ -336,6 +378,35 @@ AS
336378
SET @SkipModel = 1; /*We don't have read permissions in the model database*/
337379
END;
338380
END;
381+
382+
IF ISNULL(@SkipMSDB, 0) != 1 /*If @SkipMSDB hasn't been set to 1 by the caller*/
383+
BEGIN
384+
IF EXISTS
385+
(
386+
SELECT 1/0
387+
FROM @db_perms
388+
WHERE database_name = N'msdb'
389+
)
390+
BEGIN
391+
BEGIN TRY
392+
IF EXISTS
393+
(
394+
SELECT 1/0
395+
FROM msdb.sys.objects
396+
)
397+
BEGIN
398+
SET @SkipMSDB = 0; /*We have read permissions in the msdb database, and can view the objects*/
399+
END;
400+
END TRY
401+
BEGIN CATCH
402+
SET @SkipMSDB = 1; /*We have read permissions in the msdb database ... oh wait we got tricked, we can't view the objects*/
403+
END CATCH;
404+
END;
405+
ELSE
406+
BEGIN
407+
SET @SkipMSDB = 1; /*We don't have read permissions in the msdb database*/
408+
END;
409+
END;
339410
END;
340411

341412
SET @crlf = NCHAR(13) + NCHAR(10);
@@ -502,6 +573,21 @@ AS
502573
FROM (VALUES(NULL, 29, NULL)) AS v (DatabaseName, CheckID, ServerName) /*Looks for user tables in model*/
503574
WHERE @SkipModel = 1;
504575

576+
INSERT #SkipChecks (DatabaseName, CheckID, ServerName)
577+
SELECT
578+
v.*
579+
FROM (VALUES(NULL, 6, NULL), /*Jobs Owned By Users*/
580+
(NULL, 28, NULL), /*SQL Agent Job Runs at Startup*/
581+
(NULL, 57, NULL), /*Tables in the MSDB Database*/
582+
(NULL, 79, NULL), /*Shrink Database Job*/
583+
(NULL, 94, NULL), /*Agent Jobs Without Failure Emails*/
584+
(NULL, 123, NULL), /*Agent Jobs Starting Simultaneously*/
585+
(NULL, 180, NULL), /*Shrink Database Step In Maintenance Plan*/
586+
(NULL, 181, NULL), /*Repetitive Maintenance Tasks*/
587+
(NULL, 219, NULL) /*Alerts Without Event Descriptions*/
588+
) AS v (DatabaseName, CheckID, ServerName)
589+
WHERE @SkipMSDB = 1;
590+
505591
INSERT #SkipChecks (DatabaseName, CheckID, ServerName)
506592
SELECT
507593
v.*
@@ -544,16 +630,6 @@ AS
544630
FROM (VALUES(NULL, 2301, NULL)) AS v (DatabaseName, CheckID, ServerName) /*sp_validatelogins*/
545631
WHERE @SkipValidateLogins = 1
546632

547-
IF(OBJECT_ID('tempdb..#InvalidLogins') IS NOT NULL)
548-
BEGIN
549-
EXEC sp_executesql N'DROP TABLE #InvalidLogins;';
550-
END;
551-
552-
CREATE TABLE #InvalidLogins (
553-
LoginSID varbinary(85),
554-
LoginName VARCHAR(256)
555-
);
556-
557633
IF @SkipChecksTable IS NOT NULL
558634
AND @SkipChecksSchema IS NOT NULL
559635
AND @SkipChecksDatabase IS NOT NULL
@@ -1109,17 +1185,17 @@ AS
11091185
least one of the relevant checks is not being skipped then we can extract the
11101186
dbinfo information.
11111187
*/
1112-
IF NOT EXISTS ( SELECT 1
1113-
FROM #BlitzResults
1114-
WHERE CheckID = 223 AND URL = 'https://aws.amazon.com/rds/sqlserver/')
1115-
AND (
1116-
NOT EXISTS ( SELECT 1
1117-
FROM #SkipChecks
1118-
WHERE DatabaseName IS NULL AND CheckID = 2 )
1119-
OR NOT EXISTS ( SELECT 1
1120-
FROM #SkipChecks
1121-
WHERE DatabaseName IS NULL AND CheckID = 68 )
1122-
)
1188+
IF NOT EXISTS
1189+
(
1190+
SELECT 1/0
1191+
FROM #BlitzResults
1192+
WHERE CheckID = 223 AND URL = 'https://aws.amazon.com/rds/sqlserver/'
1193+
) AND NOT EXISTS
1194+
(
1195+
SELECT 1/0
1196+
FROM #SkipChecks
1197+
WHERE DatabaseName IS NULL AND CheckID IN (2, 68)
1198+
)
11231199
BEGIN
11241200

11251201
IF @Debug IN (1, 2) RAISERROR('Extracting DBCC DBINFO data (used in checks 2 and 68).', 0, 1, 68) WITH NOWAIT;
@@ -1686,9 +1762,9 @@ AS
16861762

16871763
IF @Debug IN (1, 2) RAISERROR('Running CheckId [%d].', 0, 1, 2301) WITH NOWAIT;
16881764

1689-
INSERT INTO #InvalidLogins
1690-
EXEC sp_validatelogins
1691-
;
1765+
/*
1766+
#InvalidLogins is filled at the start during the permissions check
1767+
*/
16921768

16931769
INSERT INTO #BlitzResults
16941770
( CheckID ,
@@ -8621,12 +8697,22 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
86218697
END
86228698
ELSE
86238699
BEGIN
8624-
INSERT INTO #ErrorLog
8625-
EXEC sys.xp_readerrorlog 0, 1, N'Database Instant File Initialization: enabled';
8700+
BEGIN TRY
8701+
INSERT INTO #ErrorLog
8702+
EXEC sys.xp_readerrorlog 0, 1, N'Database Instant File Initialization: enabled';
8703+
END TRY
8704+
BEGIN CATCH
8705+
IF @Debug IN (1, 2) RAISERROR('No permissions to execute xp_readerrorlog.', 0, 1) WITH NOWAIT;
8706+
END CATCH
86268707
END
86278708

8628-
IF @@ROWCOUNT > 0
8629-
begin
8709+
IF EXISTS
8710+
(
8711+
SELECT 1/0
8712+
FROM #ErrorLog
8713+
WHERE LEFT([Text], 45) = N'Database Instant File Initialization: enabled'
8714+
)
8715+
BEGIN
86308716
INSERT INTO #BlitzResults
86318717
( CheckID ,
86328718
[Priority] ,
@@ -8642,7 +8728,7 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
86428728
'Instant File Initialization Enabled' AS [Finding] ,
86438729
'https://www.brentozar.com/go/instant' AS [URL] ,
86448730
'The service account has the Perform Volume Maintenance Tasks permission.';
8645-
end
8731+
END;
86468732
else -- if version of sql server has instant_file_initialization_enabled column in dm_server_services, check that too
86478733
-- in the event the error log has been cycled and the startup messages are not in the current error log
86488734
begin
@@ -9083,30 +9169,6 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
90839169

90849170
IF @Debug IN (1, 2) RAISERROR('Running CheckId [%d].', 0, 1, 211) WITH NOWAIT;
90859171

9086-
DECLARE @outval VARCHAR(36);
9087-
/* Get power plan if set by group policy [Git Hub Issue #1620] */
9088-
EXEC master.sys.xp_regread @rootkey = 'HKEY_LOCAL_MACHINE',
9089-
@key = 'SOFTWARE\Policies\Microsoft\Power\PowerSettings',
9090-
@value_name = 'ActivePowerScheme',
9091-
@value = @outval OUTPUT,
9092-
@no_output = 'no_output';
9093-
9094-
IF @outval IS NULL /* If power plan was not set by group policy, get local value [Git Hub Issue #1620]*/
9095-
EXEC master.sys.xp_regread @rootkey = 'HKEY_LOCAL_MACHINE',
9096-
@key = 'SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes',
9097-
@value_name = 'ActivePowerScheme',
9098-
@value = @outval OUTPUT;
9099-
9100-
DECLARE @cpu_speed_mhz int,
9101-
@cpu_speed_ghz decimal(18,2);
9102-
9103-
EXEC master.sys.xp_regread @rootkey = 'HKEY_LOCAL_MACHINE',
9104-
@key = 'HARDWARE\DESCRIPTION\System\CentralProcessor\0',
9105-
@value_name = '~MHz',
9106-
@value = @cpu_speed_mhz OUTPUT;
9107-
9108-
SELECT @cpu_speed_ghz = CAST(CAST(@cpu_speed_mhz AS DECIMAL) / 1000 AS DECIMAL(18,2));
9109-
91109172
INSERT INTO #BlitzResults
91119173
( CheckID ,
91129174
Priority ,
@@ -9123,7 +9185,7 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
91239185
'Your server has '
91249186
+ CAST(@cpu_speed_ghz as VARCHAR(4))
91259187
+ 'GHz CPUs, and is in '
9126-
+ CASE @outval
9188+
+ CASE @powerScheme
91279189
WHEN 'a1841308-3541-4fab-bc81-f71556f20b4a'
91289190
THEN 'power saving mode -- are you sure this is a production SQL Server?'
91299191
WHEN '381b4222-f694-41f0-9685-ff5bb260df2e'

sp_BlitzAnalysis.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ AS
3737
SET NOCOUNT ON;
3838
SET STATISTICS XML OFF;
3939

40-
SELECT @Version = '8.16', @VersionDate = '20230820';
40+
SELECT @Version = '8.17', @VersionDate = '20231010';
4141

4242
IF(@VersionCheckMode = 1)
4343
BEGIN

sp_BlitzBackups.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ AS
2424
SET STATISTICS XML OFF;
2525
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
2626

27-
SELECT @Version = '8.16', @VersionDate = '20230820';
27+
SELECT @Version = '8.17', @VersionDate = '20231010';
2828

2929
IF(@VersionCheckMode = 1)
3030
BEGIN

0 commit comments

Comments
 (0)