Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
533 changes: 323 additions & 210 deletions Install-All-Scripts.sql

Large diffs are not rendered by default.

140 changes: 111 additions & 29 deletions Install-Azure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ AS
SET NOCOUNT ON;
SET STATISTICS XML OFF;

SELECT @Version = '8.24', @VersionDate = '20250407';
SELECT @Version = '8.25', @VersionDate = '20250704';

IF(@VersionCheckMode = 1)
BEGIN
Expand Down Expand Up @@ -1147,6 +1147,7 @@ ALTER PROCEDURE dbo.sp_BlitzCache
@DurationFilter DECIMAL(38,4) = NULL ,
@HideSummary BIT = 0 ,
@IgnoreSystemDBs BIT = 1 ,
@IgnoreReadableReplicaDBs BIT = 1 ,
@OnlyQueryHashes VARCHAR(MAX) = NULL ,
@IgnoreQueryHashes VARCHAR(MAX) = NULL ,
@OnlySqlHandles VARCHAR(MAX) = NULL ,
Expand All @@ -1173,7 +1174,7 @@ SET NOCOUNT ON;
SET STATISTICS XML OFF;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

SELECT @Version = '8.24', @VersionDate = '20250407';
SELECT @Version = '8.25', @VersionDate = '20250704';
SET @OutputType = UPPER(@OutputType);

IF(@VersionCheckMode = 1)
Expand Down Expand Up @@ -2296,7 +2297,7 @@ CREATE TABLE #plan_usage
);


IF EXISTS (SELECT * FROM sys.all_objects o WHERE o.name = 'dm_hadr_database_replica_states')
IF @IgnoreReadableReplicaDBs = 1 AND EXISTS (SELECT * FROM sys.all_objects o WHERE o.name = 'dm_hadr_database_replica_states')
BEGIN
RAISERROR('Checking for Read intent databases to exclude',0,0) WITH NOWAIT;

Expand Down Expand Up @@ -2715,7 +2716,7 @@ IF @VersionShowsAirQuoteActualPlans = 1

SET @body += N' WHERE 1 = 1 ' + @nl ;

IF EXISTS (SELECT * FROM sys.all_objects o WHERE o.name = 'dm_hadr_database_replica_states')
IF @IgnoreReadableReplicaDBs = 1 AND EXISTS (SELECT * FROM sys.all_objects o WHERE o.name = 'dm_hadr_database_replica_states')
BEGIN
RAISERROR(N'Ignoring readable secondaries databases by default', 0, 1) WITH NOWAIT;
SET @body += N' AND CAST(xpa.value AS INT) NOT IN (SELECT database_id FROM #ReadableDBs)' + @nl ;
Expand Down Expand Up @@ -8557,7 +8558,7 @@ SET NOCOUNT ON;
SET STATISTICS XML OFF;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

SELECT @Version = '8.24', @VersionDate = '20250407';
SELECT @Version = '8.25', @VersionDate = '20250704';

IF(@VersionCheckMode = 1)
BEGIN
Expand Down Expand Up @@ -10148,22 +10149,22 @@ BEGIN
'Maintenance Tasks Running' AS FindingGroup,
'Restore Running' AS Finding,
'https://www.brentozar.com/askbrent/backups/' AS URL,
'Restore of ' + DB_NAME(db.resource_database_id) + ' database (' + (SELECT CAST(CAST(SUM(size * 8.0 / 1024 / 1024) AS BIGINT) AS NVARCHAR) FROM #MasterFiles WHERE database_id = db.resource_database_id) + 'GB) is ' + CAST(r.percent_complete AS NVARCHAR(100)) + '% complete, has been running since ' + CAST(r.start_time AS NVARCHAR(100)) + '. ' AS Details,
'Restore of ' + COALESCE(DB_NAME(db.resource_database_id), 'Unknown Database') + ' database (' + COALESCE((SELECT CAST(CAST(SUM(size * 8.0 / 1024 / 1024) AS BIGINT) AS NVARCHAR) FROM #MasterFiles WHERE database_id = db.resource_database_id), 'Unknown') + 'GB) is ' + CAST(r.percent_complete AS NVARCHAR(100)) + '% complete, has been running since ' + CAST(r.start_time AS NVARCHAR(100)) + '. ' AS Details,
'KILL ' + CAST(r.session_id AS NVARCHAR(100)) + ';' AS HowToStopIt,
pl.query_plan AS QueryPlan,
r.start_time AS StartTime,
s.login_name AS LoginName,
s.nt_user_name AS NTUserName,
s.[program_name] AS ProgramName,
s.[host_name] AS HostName,
db.[resource_database_id] AS DatabaseID,
DB_NAME(db.resource_database_id) AS DatabaseName,
COALESCE(db.[resource_database_id],0) AS DatabaseID,
COALESCE(DB_NAME(db.resource_database_id), 'Unknown') AS DatabaseName,
0 AS OpenTransactionCount,
r.query_hash
FROM sys.dm_exec_requests r
INNER JOIN sys.dm_exec_connections c ON r.session_id = c.session_id
INNER JOIN sys.dm_exec_sessions s ON r.session_id = s.session_id
INNER JOIN (
LEFT OUTER JOIN (
SELECT DISTINCT request_session_id, resource_database_id
FROM sys.dm_tran_locks
WHERE resource_type = N'DATABASE'
Expand Down Expand Up @@ -10531,6 +10532,7 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
FROM sys.databases
WHERE database_id > 4;


/* Server Info - Memory Grants pending - CheckID 39 */
IF (@Debug = 1)
BEGIN
Expand Down Expand Up @@ -11590,6 +11592,28 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
END;


/* Query Problems - Deadlocks - CheckID 51 */
IF (@Debug = 1)
BEGIN
RAISERROR('Running CheckID 51',10,1) WITH NOWAIT;
END

INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, URL, Details, HowToStopIt)
SELECT 51 AS CheckID,
100 AS Priority,
'Query Problems' AS FindingGroup,
'Deadlocks' AS Finding,
' https://www.brentozar.com/go/deadlocks' AS URL,
'Number of deadlocks during the sample: ' + CAST(ps.value_delta AS NVARCHAR(20)) + @LineFeed
+ 'Determined by sampling Perfmon counter ' + ps.object_name + ' - ' + ps.counter_name + @LineFeed AS Details,
'Check sp_BlitzLock to find which indexes and queries to tune.' AS HowToStopIt
FROM #PerfmonStats ps
WHERE ps.Pass = 2
AND counter_name = 'Number of Deadlocks/sec'
AND instance_name LIKE '_Total%'
AND value_delta > 0;


/* SQL Server Internal Maintenance - Log File Growing - CheckID 13 */
IF (@Debug = 1)
BEGIN
Expand Down Expand Up @@ -11835,6 +11859,53 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
OR max_session_percent >= 90);
END

/* Server Info - Thread Time - CheckID 50 */
IF (@Debug = 1)
BEGIN
RAISERROR('Running CheckID 50',10,1) WITH NOWAIT;
END

;WITH max_batch AS (
SELECT MAX(SampleTime) AS SampleTime
FROM #WaitStats
)
INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, Details, DetailsInt, URL)
SELECT TOP 1
50 AS CheckID,
251 AS Priority,
'Server Info' AS FindingGroup,
'Thread Time' AS Finding,
LTRIM(
CASE
WHEN c.[TotalThreadTimeSeconds] >= 86400 THEN
CAST(c.[TotalThreadTimeSeconds] / 86400 AS VARCHAR) + 'd '
ELSE ''
END +
CASE
WHEN c.[TotalThreadTimeSeconds] % 86400 >= 3600 THEN
CAST((c.[TotalThreadTimeSeconds] % 86400) / 3600 AS VARCHAR) + 'h '
ELSE ''
END +
CASE
WHEN c.[TotalThreadTimeSeconds] % 3600 >= 60 THEN
CAST((c.[TotalThreadTimeSeconds] % 3600) / 60 AS VARCHAR) + 'm '
ELSE ''
END +
CASE
WHEN c.[TotalThreadTimeSeconds] % 60 > 0 OR c.[TotalThreadTimeSeconds] = 0 THEN
CAST(c.[TotalThreadTimeSeconds] % 60 AS VARCHAR) + 's'
ELSE ''
END
) AS Details,
CAST(c.[TotalThreadTimeSeconds] AS DECIMAL(18,1)) AS DetailsInt,
'https://www.brentozar.com/go/threadtime' AS URL
FROM max_batch b
JOIN #WaitStats wd2 ON wd2.SampleTime = b.SampleTime
JOIN #WaitStats wd1 ON wd1.wait_type = wd2.wait_type AND wd2.SampleTime > wd1.SampleTime
CROSS APPLY (
SELECT CAST((wd2.thread_time_ms - wd1.thread_time_ms) / 1000 AS INT) AS TotalThreadTimeSeconds
) AS c;

/* Server Info - Batch Requests per Sec - CheckID 19 */
IF (@Debug = 1)
BEGIN
Expand Down Expand Up @@ -13164,13 +13235,13 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
wd1.wait_type,
COALESCE(wcat.WaitCategory, 'Other') AS wait_category,
CAST(c.[Wait Time (Seconds)] / 60. / 60. AS DECIMAL(18,1)) AS [Wait Time (Hours)],
CAST((wd2.wait_time_ms - wd1.wait_time_ms) / 1000.0 / cores.cpu_count / DATEDIFF(ss, wd1.SampleTime, wd2.SampleTime) AS DECIMAL(18,1)) AS [Per Core Per Hour],
(wd2.waiting_tasks_count - wd1.waiting_tasks_count) AS [Number of Waits],
CASE WHEN (wd2.waiting_tasks_count - wd1.waiting_tasks_count) > 0
THEN
CAST((wd2.wait_time_ms-wd1.wait_time_ms)/
(1.0*(wd2.waiting_tasks_count - wd1.waiting_tasks_count)) AS NUMERIC(12,1))
ELSE 0 END AS [Avg ms Per Wait]
ELSE 0 END AS [Avg ms Per Wait],
CAST((wd2.wait_time_ms - wd1.wait_time_ms) / 1000.0 / cores.cpu_count / DATEDIFF(ss, wd1.SampleTime, wd2.SampleTime) AS DECIMAL(18,1)) AS [Per Core Per Hour],
(wd2.waiting_tasks_count - wd1.waiting_tasks_count) AS [Number of Waits]
FROM max_batch b
JOIN #WaitStats wd2 ON
wd2.SampleTime =b.SampleTime
Expand Down Expand Up @@ -13309,17 +13380,17 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
wd1.wait_type,
COALESCE(wcat.WaitCategory, 'Other') AS wait_category,
CAST(c.[Wait Time (Seconds)] / 60. / 60. AS DECIMAL(18,1)) AS [Wait Time (Hours)],
CASE WHEN (wd2.waiting_tasks_count - wd1.waiting_tasks_count) > 0
THEN
CAST((wd2.wait_time_ms-wd1.wait_time_ms)/
(1.0*(wd2.waiting_tasks_count - wd1.waiting_tasks_count)) AS NUMERIC(12,1))
ELSE 0 END AS [Avg ms Per Wait],
CAST((wd2.wait_time_ms - wd1.wait_time_ms) / 1000.0 / cores.cpu_count / DATEDIFF(ss, wd1.SampleTime, wd2.SampleTime) AS DECIMAL(18,1)) AS [Per Core Per Hour],
CAST(c.[Signal Wait Time (Seconds)] / 60.0 / 60 AS DECIMAL(18,1)) AS [Signal Wait Time (Hours)],
CASE WHEN c.[Wait Time (Seconds)] > 0
THEN CAST(100.*(c.[Signal Wait Time (Seconds)]/c.[Wait Time (Seconds)]) AS NUMERIC(4,1))
ELSE 0 END AS [Percent Signal Waits],
(wd2.waiting_tasks_count - wd1.waiting_tasks_count) AS [Number of Waits],
CASE WHEN (wd2.waiting_tasks_count - wd1.waiting_tasks_count) > 0
THEN
CAST((wd2.wait_time_ms-wd1.wait_time_ms)/
(1.0*(wd2.waiting_tasks_count - wd1.waiting_tasks_count)) AS NUMERIC(12,1))
ELSE 0 END AS [Avg ms Per Wait],
N'https://www.sqlskills.com/help/waits/' + LOWER(wd1.wait_type) + '/' AS URL
FROM max_batch b
JOIN #WaitStats wd2 ON
Expand Down Expand Up @@ -13353,17 +13424,17 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
wd1.wait_type,
COALESCE(wcat.WaitCategory, 'Other') AS wait_category,
c.[Wait Time (Seconds)],
CASE WHEN (wd2.waiting_tasks_count - wd1.waiting_tasks_count) > 0
THEN
CAST((wd2.wait_time_ms-wd1.wait_time_ms)/
(1.0*(wd2.waiting_tasks_count - wd1.waiting_tasks_count)) AS NUMERIC(12,1))
ELSE 0 END AS [Avg ms Per Wait],
CAST((CAST(wd2.wait_time_ms - wd1.wait_time_ms AS MONEY)) / 1000.0 / cores.cpu_count / DATEDIFF(ss, wd1.SampleTime, wd2.SampleTime) AS DECIMAL(18,1)) AS [Per Core Per Second],
c.[Signal Wait Time (Seconds)],
CASE WHEN c.[Wait Time (Seconds)] > 0
THEN CAST(100.*(c.[Signal Wait Time (Seconds)]/c.[Wait Time (Seconds)]) AS NUMERIC(4,1))
ELSE 0 END AS [Percent Signal Waits],
(wd2.waiting_tasks_count - wd1.waiting_tasks_count) AS [Number of Waits],
CASE WHEN (wd2.waiting_tasks_count - wd1.waiting_tasks_count) > 0
THEN
CAST((wd2.wait_time_ms-wd1.wait_time_ms)/
(1.0*(wd2.waiting_tasks_count - wd1.waiting_tasks_count)) AS NUMERIC(12,1))
ELSE 0 END AS [Avg ms Per Wait],
N'https://www.sqlskills.com/help/waits/' + LOWER(wd1.wait_type) + '/' AS URL
FROM max_batch b
JOIN #WaitStats wd2 ON
Expand Down Expand Up @@ -13567,7 +13638,7 @@ SET NOCOUNT ON;
SET STATISTICS XML OFF;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

SELECT @Version = '8.24', @VersionDate = '20250407';
SELECT @Version = '8.25', @VersionDate = '20250704';
SET @OutputType = UPPER(@OutputType);

IF(@VersionCheckMode = 1)
Expand Down Expand Up @@ -20357,7 +20428,7 @@ BEGIN
SET XACT_ABORT OFF;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

SELECT @Version = '8.24', @VersionDate = '20250407';
SELECT @Version = '8.25', @VersionDate = '20250704';

IF @VersionCheckMode = 1
BEGIN
Expand Down Expand Up @@ -21570,7 +21641,7 @@ BEGIN
END;

/* If table target */
IF @TargetSessionType = 'table'
IF LOWER(@TargetSessionType) = N'table'
BEGIN
SET @d = CONVERT(varchar(40), GETDATE(), 109);
RAISERROR('Inserting to #deadlock_data from table source %s', 0, 1, @d) WITH NOWAIT;
Expand All @@ -21588,9 +21659,19 @@ BEGIN
SELECT TOP (1)
@xe = xe.e.exist(''.''),
@xd = xd.e.exist(''.'')
FROM [master].[dbo].[bpr] AS x
OUTER APPLY x.[bpr].nodes(''/event'') AS xe(e)
OUTER APPLY x.[bpr].nodes(''/deadlock'') AS xd(e)
FROM ' +
QUOTENAME(@TargetDatabaseName) +
N'.' +
QUOTENAME(@TargetSchemaName) +
N'.' +
QUOTENAME(@TargetTableName) +
N' AS x
OUTER APPLY x.' +
QUOTENAME(@TargetColumnName) +
N'.nodes(''/event'') AS xe(e)
OUTER APPLY x.' +
QUOTENAME(@TargetColumnName) +
N'.nodes(''/deadlock'') AS xd(e)
OPTION(RECOMPILE);
';

Expand Down Expand Up @@ -21727,6 +21808,7 @@ BEGIN
LEFT JOIN #t AS t
ON 1 = 1
WHERE @xe = 1
OR LOWER(@TargetSessionType) <> N'table'

UNION ALL

Expand Down Expand Up @@ -24890,7 +24972,7 @@ BEGIN
SET STATISTICS XML OFF;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

SELECT @Version = '8.24', @VersionDate = '20250407';
SELECT @Version = '8.25', @VersionDate = '20250704';

IF(@VersionCheckMode = 1)
BEGIN
Expand Down
4 changes: 4 additions & 0 deletions SqlServerVersions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ INSERT INTO dbo.SqlServerVersions
(MajorVersionNumber, MinorVersionNumber, Branch, [Url], ReleaseDate, MainstreamSupportEndDate, ExtendedSupportEndDate, MajorVersionName, MinorVersionName)
VALUES
/*2022*/
(17, 800, 'CTP 2.1', 'https://info.microsoft.com/ww-landing-sql-server-2025.html', '2025-06-16', '2025-12-31', '2025-12-31', 'SQL Server 2025', 'Preview CTP 2.1'),
(17, 700, 'CTP 2.0', 'https://info.microsoft.com/ww-landing-sql-server-2025.html', '2025-05-19', '2025-12-31', '2025-12-31', 'SQL Server 2025', 'Preview CTP 2.0'),
/*2022*/
(16, 4195, 'CU19', 'https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2022/cumulativeupdate19', '2025-05-19', '2028-01-11', '2033-01-11', 'SQL Server 2022', 'Cumulative Update 19'),
(16, 4185, 'CU18', 'https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2022/cumulativeupdate18', '2025-03-13', '2028-01-11', '2033-01-11', 'SQL Server 2022', 'Cumulative Update 18'),
(16, 4175, 'CU17', 'https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2022/cumulativeupdate17', '2025-01-16', '2028-01-11', '2033-01-11', 'SQL Server 2022', 'Cumulative Update 17'),
(16, 4165, 'CU16', 'https://support.microsoft.com/en-us/help/5048033', '2024-11-14', '2028-01-11', '2033-01-11', 'SQL Server 2022', 'Cumulative Update 16'),
Expand Down
2 changes: 1 addition & 1 deletion sp_Blitz.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ AS
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;


SELECT @Version = '8.24', @VersionDate = '20250407';
SELECT @Version = '8.25', @VersionDate = '20250704';
SET @OutputType = UPPER(@OutputType);

IF(@VersionCheckMode = 1)
Expand Down
2 changes: 1 addition & 1 deletion sp_BlitzAnalysis.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ AS
SET NOCOUNT ON;
SET STATISTICS XML OFF;

SELECT @Version = '8.24', @VersionDate = '20250407';
SELECT @Version = '8.25', @VersionDate = '20250704';

IF(@VersionCheckMode = 1)
BEGIN
Expand Down
2 changes: 1 addition & 1 deletion sp_BlitzBackups.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ AS
SET STATISTICS XML OFF;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

SELECT @Version = '8.24', @VersionDate = '20250407';
SELECT @Version = '8.25', @VersionDate = '20250704';

IF(@VersionCheckMode = 1)
BEGIN
Expand Down
2 changes: 1 addition & 1 deletion sp_BlitzCache.sql
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ SET NOCOUNT ON;
SET STATISTICS XML OFF;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

SELECT @Version = '8.24', @VersionDate = '20250407';
SELECT @Version = '8.25', @VersionDate = '20250704';
SET @OutputType = UPPER(@OutputType);

IF(@VersionCheckMode = 1)
Expand Down
Loading
Loading