Skip to content

Commit a96836f

Browse files
authored
Merge pull request #402 from VladDBA/dev
Updated resources, additional instance and memory info, HTML improvements, bug fixes
2 parents 908c98a + 42a8f69 commit a96836f

12 files changed

+1047
-502
lines changed

PSBlitz.ps1

Lines changed: 71 additions & 66 deletions
Large diffs are not rendered by default.

Resources/GetInstanceInfo.sql

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,19 @@ SELECT ISNULL(SERVERPROPERTY('MachineName'),'N/A')
4848
WHEN SERVERPROPERTY('IsFullTextInstalled') = 0 THEN 'No'
4949
ELSE 'N/A'
5050
END AS [fulltext_installed],
51+
CASE
52+
WHEN SERVERPROPERTY('IsXTPSupported') = 1 THEN 'Yes'
53+
WHEN SERVERPROPERTY('IsXTPSupported') = 0 THEN 'No'
54+
ELSE 'N/A'
55+
END AS [in-memory_oltp_supported],
56+
CASE
57+
WHEN SERVERPROPERTY('IsServerSuspendedForSnapshotBackup') = 1 THEN 'Yes'
58+
WHEN SERVERPROPERTY('IsServerSuspendedForSnapshotBackup') = 0 THEN 'No'
59+
ELSE 'N/A'
60+
END AS [server_suspended_for_snapshot],
5161
SERVERPROPERTY('Collation') AS [instance_collation],
5262
(SELECT COUNT([database_id]) FROM [sys].[databases] WHERE [database_id] > 4) AS [user_db_count],
63+
ISNULL(CAST(SERVERPROPERTY('SuspendedDatabaseCount') AS NVARCHAR(10)),'N/A') AS [suspended_db_count],
5364
CONVERT(VARCHAR(22),[sqlserver_start_time],120) AS [instance_last_startup],
5465
SERVERPROPERTY('ProcessID') AS [process_id],
5566
CAST(DATEDIFF(HH, [sqlserver_start_time], GETDATE()) / 24.00 AS NUMERIC(23, 2)) AS [uptime_days],
@@ -70,8 +81,9 @@ SET @LineFeed = CHAR(13) + CHAR(10);
7081
SELECT @SQL = CASE
7182
/*Skipping this query on Azure SQL DB*/
7283
WHEN CAST(SERVERPROPERTY('Edition') AS NVARCHAR(100)) = N'SQL Azure'
73-
AND SERVERPROPERTY('EngineEdition') IN ( 5, 6 ) THEN CAST(N'SELECT ''Not available'' AS [logical_cpu_cores], '' in Azure '' AS [physical_CPU_cores], ''SQL DB'' ' AS NVARCHAR(MAX))
74-
+ N'[AS physical_memory_GB], NULL AS [max_server_memory_GB], NULL AS [target_server_memory_GB], '
84+
AND SERVERPROPERTY('EngineEdition') IN ( 5, 6 ) THEN /*This fake result set is only used in the Excel version of the report*/
85+
CAST(N'SELECT ''Not available'' AS [logical_cpu_cores], '' in Azure '' AS [physical_CPU_cores], ''SQL DB'' ' AS NVARCHAR(MAX))
86+
+ N'AS [physical_memory_GB], NULL AS [max_server_memory_GB], NULL AS [target_server_memory_GB], '
7587
+ N'NULL AS [total_memory_used_GB], NULL AS [proc_physical_memory_low], NULL AS [proc_virtual_memory_low], '
7688
+ N'NULL AS [available_physical_memory_GB], NULL AS [os_memory_state], NULL AS [CTP], NULL AS [MAXDOP]'
7789
ELSE CAST(N'SELECT [cpu_count] AS [logical_cpu_cores],' AS NVARCHAR(MAX))
@@ -113,6 +125,14 @@ SELECT @SQL = CASE
113125
+ @LineFeed
114126
+ N' FROM sys.dm_os_buffer_descriptors WHERE database_id <> 32767) AS [buffer_pool_usage_GB],'
115127
+ @LineFeed
128+
+ N'(SELECT CAST(([locked_page_allocations_kb] / 1024.00/1024.00) AS DECIMAL(15, 2)) '
129+
+ @LineFeed
130+
+ N' FROM sys.dm_os_process_memory) AS [locked_pages_allocated_GB],'
131+
+ @LineFeed
132+
+ N'(SELECT CAST(([large_page_allocations_kb] / 1024.00/1024.00) AS DECIMAL(15, 2)) '
133+
+ @LineFeed
134+
+ N' FROM sys.dm_os_process_memory) AS [large_pages_allocated_GB],'
135+
+ @LineFeed
116136
+ N'(SELECT CASE WHEN [process_physical_memory_low] = 1 THEN ''Yes'''
117137
+ @LineFeed
118138
+ N'ELSE ''No'' END FROM sys.dm_os_process_memory) AS [process_physical_memory_low],'

Resources/GetStatsInfoForWholeDB.sql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ CREATE TABLE ##PSBlitzStatsInfo
5050
[persisted_sample] NVARCHAR(3) NOT NULL,
5151
[persisted_sample_percent] FLOAT NULL,
5252
[steps] INT NOT NULL,
53-
[partitioned] NVARCHAR(40) NOT NULL,
5453
[partition_number] INT NULL,
5554
[get_details] NVARCHAR(1000) NULL,
5655
[update_table_stats] NVARCHAR(1000) NULL,
@@ -64,7 +63,7 @@ SELECT @SQL = CAST(N'INSERT INTO ##PSBlitzStatsInfo ([database], [object_schema]
6463
+ @LineFeed + N'[rows], [unfiltered_rows], [rows_sampled], [sample_percent], [modification_counter],'
6564
+ @LineFeed + N'[modified_percent], [incremental], [temporary], [no_recompute], '
6665
+ @LineFeed + N'[persisted_sample], [persisted_sample_percent], [steps], '
67-
+ @LineFeed + N'[partitioned], [partition_number], [get_details])'
66+
+ @LineFeed + N'[partition_number], [get_details])'
6867
+ @LineFeed + N'SELECT DB_NAME() AS [database],'
6968
+ @LineFeed + N'SCHEMA_NAME([obj].[schema_id]) AS [object_schema],'
7069
+ @LineFeed + N'[obj].[name] AS [object_name],'
@@ -108,7 +107,7 @@ THEN @LineFeed + N'[sp].[persisted_sample_percent],'
108107
ELSE @LineFeed + N'0 AS [persisted_sample_percent],'
109108
END
110109
+ @LineFeed + N'ISNULL([sp].[steps],0) AS [steps],'
111-
+ @LineFeed + N'''No'' AS [partitioned], 1 AS [partition_number]'
110+
+ @LineFeed + N'NULL AS [partition_number]'
112111
+ @LineFeed + N',N''DBCC SHOW_STATISTICS ("''+SCHEMA_NAME([obj].[schema_id])+N''.'''
113112
+ N'+[obj].[name]+N''", ''+[stat].[name]+N'');'' AS [get_details]'
114113
+ @LineFeed + N'FROM [sys].[stats] AS [stat]'
@@ -165,7 +164,6 @@ END
165164
END
166165
+ @LineFeed + N'0 AS [persisted_sample_percent],'
167166
+ @LineFeed + N'ISNULL([sip].[steps],0) AS [steps],'
168-
+ @LineFeed + N'''Yes'' AS [partitioned],'
169167
+ @LineFeed + N'[sip].[partition_number]'
170168
+ @LineFeed + N',N''DBCC SHOW_STATISTICS ("''+SCHEMA_NAME([obj].[schema_id])+N''.'''
171169
+ N'+[obj].[name]+N''", ''+[stat].[name]+N'');'' AS [get_details]'
@@ -254,7 +252,7 @@ SELECT TOP(10000) /*[id], */
254252
[modification_counter], [modified_percent],
255253
[incremental], [temporary], [no_recompute],
256254
[persisted_sample], [persisted_sample_percent],
257-
[steps], [partitioned], [partition_number],
255+
[steps], [partition_number],
258256
[get_details], [update_table_stats],
259257
[update_individual_stats], [update_partition_stats]
260258
FROM ##PSBlitzStatsInfo

Resources/PSBlitzOutput.xlsx

345 Bytes
Binary file not shown.

Resources/spBlitzCache_NonSPLatest.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ SET NOCOUNT ON;
117117
SET STATISTICS XML OFF;
118118
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
119119

120-
SELECT @Version = '8.25', @VersionDate = '20250704';
120+
SELECT @Version = '8.26', @VersionDate = '20251002';
121121
SET @OutputType = UPPER(@OutputType);
122122

123123
IF(@VersionCheckMode = 1)
@@ -3906,12 +3906,12 @@ SELECT @@SPID AS SPID,
39063906
AND ci.comma_paren_charindex > 0
39073907
THEN SUBSTRING(ci.expression, ci.paren_charindex, ci.comma_paren_charindex)
39083908
END AS converted_to,
3909-
CASE WHEN ci.at_charindex = 0
3909+
LEFT(CASE WHEN ci.at_charindex = 0
39103910
AND ci.convert_implicit_charindex = 0
39113911
AND ci.proc_name = 'Statement'
39123912
THEN SUBSTRING(ci.expression, ci.equal_charindex, 4000)
39133913
ELSE '**idk_man**'
3914-
END AS compile_time_value
3914+
END, 258) AS compile_time_value
39153915
FROM #conversion_info AS ci
39163916
OPTION (RECOMPILE);
39173917

@@ -6261,6 +6261,7 @@ BEGIN
62616261

62626262
END;
62636263

6264+
62646265
/*Vlad - column changes for PSBlitz*/
62656266
SELECT [Priority],
62666267
FindingsGroup,

Resources/spBlitzFirst_NonSPLatest.sql

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ SET NOCOUNT ON;
104104
SET STATISTICS XML OFF;
105105
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
106106

107-
SELECT @Version = '8.25', @VersionDate = '20250704';
107+
SELECT @Version = '8.26', @VersionDate = '20251002';
108108

109109
IF(@VersionCheckMode = 1)
110110
BEGIN
@@ -1695,7 +1695,11 @@ BEGIN
16951695
'Maintenance Tasks Running' AS FindingGroup,
16961696
'Restore Running' AS Finding,
16971697
'https://www.brentozar.com/askbrent/backups/' AS URL,
1698-
'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,
1698+
'Restore of ' + COALESCE(DB_NAME(db.resource_database_id),
1699+
(SELECT db1.name FROM sys.databases db1
1700+
LEFT OUTER JOIN sys.databases db2 ON db1.name <> db2.name AND db1.state_desc = db2.state_desc
1701+
WHERE db1.state_desc = 'RESTORING' AND db2.name IS NULL),
1702+
'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,
16991703
'KILL ' + CAST(r.session_id AS NVARCHAR(100)) + ';' AS HowToStopIt,
17001704
pl.query_plan AS QueryPlan,
17011705
r.start_time AS StartTime,
@@ -2645,6 +2649,27 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
26452649

26462650
END
26472651

2652+
/* Server Performance - Azure Operation Ongoing - CheckID 53 */
2653+
IF (@Debug = 1)
2654+
BEGIN
2655+
RAISERROR('Running CheckID 53',10,1) WITH NOWAIT;
2656+
END
2657+
IF EXISTS (SELECT * FROM sys.all_objects WHERE name = 'dm_operation_status')
2658+
BEGIN
2659+
INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, URL, Details)
2660+
SELECT 53 AS CheckID,
2661+
50 AS Priority,
2662+
'Server Performance' AS FindingGroup,
2663+
'Azure Operation ' + CASE WHEN state IN (2, 3, 5) THEN 'Ended Recently' ELSE 'Ongoing' END AS Finding,
2664+
'https://learn.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-operation-status-azure-sql-database' AS URL,
2665+
N'Operation: ' + operation + N' State: ' + state_desc + N' Percent Complete: ' + CAST(percent_complete AS NVARCHAR(10)) + @LineFeed
2666+
+ N' On: ' + CAST(resource_type_desc AS NVARCHAR(100)) + N':' + CAST(major_resource_id AS NVARCHAR(100)) + @LineFeed
2667+
+ N' Started: ' + CAST(start_time AS NVARCHAR(100)) + N' Last Modified Time: ' + CAST(last_modify_time AS NVARCHAR(100)) + @LineFeed
2668+
+ N' For more information, query SELECT * FROM sys.dm_operation_status; ' AS Details
2669+
FROM sys.dm_operation_status
2670+
END
2671+
2672+
26482673
/* Potential Upcoming Problems - High Number of Connections - CheckID 49 */
26492674
IF (@Debug = 1)
26502675
BEGIN
@@ -2674,6 +2699,27 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
26742699
END
26752700
END
26762701

2702+
2703+
2704+
/* Server Performance - Memory Dangerously Low Recently - CheckID 52 */
2705+
IF (@Debug = 1)
2706+
BEGIN
2707+
RAISERROR('Running CheckID 52',10,1) WITH NOWAIT;
2708+
END
2709+
IF EXISTS (SELECT * FROM sys.all_objects WHERE name = 'dm_os_memory_health_history')
2710+
BEGIN
2711+
INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, URL, Details)
2712+
SELECT TOP 1 52 AS CheckID,
2713+
10 AS Priority,
2714+
'Server Performance' AS FindingGroup,
2715+
'Memory Dangerously Low Recently' AS Finding,
2716+
'https://www.brentozar.com/go/memhist' AS URL,
2717+
N'As recently as ' + CONVERT(NVARCHAR(19), snapshot_time, 120) + N', memory health issues are being reported in sys.dm_os_memory_health_history, indicating extreme memory pressure.' AS Details
2718+
FROM sys.dm_os_memory_health_history
2719+
WHERE severity_level > 1;
2720+
END
2721+
2722+
26772723
RAISERROR('Finished running investigatory queries',10,1) WITH NOWAIT;
26782724

26792725

@@ -4848,7 +4894,6 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
48484894
CAST([QueryPlan] AS NVARCHAR(MAX)) AS QueryPlan*/
48494895
FROM #BlitzFirstResults
48504896
WHERE (@Seconds > 0 OR (Priority IN (0, 250, 251, 255))) /* For @Seconds = 0, filter out broken checks for now */
4851-
AND [Priority] NOT IN (0,255)
48524897
ORDER BY Priority ,
48534898
FindingsGroup ,
48544899
CASE
@@ -4948,11 +4993,13 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
49484993
THEN CAST(100.*(c.[Signal Wait Time (Seconds)]/c.[Wait Time (Seconds)]) AS NUMERIC(4,1))
49494994
ELSE 0 END AS [Percent Signal Waits],
49504995
(wd2.waiting_tasks_count - wd1.waiting_tasks_count) AS [Number of Waits],
4996+
/*Vlad - moved for PSBlitz - start*/
49514997
CASE WHEN (wd2.waiting_tasks_count - wd1.waiting_tasks_count) > 0
49524998
THEN
49534999
CAST((wd2.wait_time_ms-wd1.wait_time_ms)/
49545000
(1.0*(wd2.waiting_tasks_count - wd1.waiting_tasks_count)) AS NUMERIC(12,1))
49555001
ELSE 0 END AS [Avg ms Per Wait],
5002+
/*Vlad - moved for PSBlitz - end*/
49565003
N'https://www.sqlskills.com/help/waits/' + LOWER(wd1.wait_type) + '/' AS URL
49575004
FROM max_batch b
49585005
JOIN #WaitStats wd2 ON
@@ -4988,7 +5035,7 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
49885035
+ '/'' target=''_blank''>'+wd1.wait_type+'</a>' AS [wait_typeHL], /*changes for PSBlitz */
49895036
COALESCE(wcat.WaitCategory, 'Other') AS wait_category,
49905037
c.[Wait Time (Seconds)],
4991-
/*CASE WHEN (wd2.waiting_tasks_count - wd1.waiting_tasks_count) > 0
5038+
/*CASE WHEN (wd2.waiting_tasks_count - wd1.waiting_tasks_count) > 0
49925039
THEN
49935040
CAST((wd2.wait_time_ms-wd1.wait_time_ms)/
49945041
(1.0*(wd2.waiting_tasks_count - wd1.waiting_tasks_count)) AS NUMERIC(12,1))
@@ -4999,11 +5046,13 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
49995046
THEN CAST(100.*(c.[Signal Wait Time (Seconds)]/c.[Wait Time (Seconds)]) AS NUMERIC(4,1))
50005047
ELSE 0 END AS [Percent Signal Waits],
50015048
(wd2.waiting_tasks_count - wd1.waiting_tasks_count) AS [Number of Waits],
5049+
/*Vlad - moved for PSBlitz - start*/
50025050
CASE WHEN (wd2.waiting_tasks_count - wd1.waiting_tasks_count) > 0
50035051
THEN
50045052
CAST((wd2.wait_time_ms-wd1.wait_time_ms)/
50055053
(1.0*(wd2.waiting_tasks_count - wd1.waiting_tasks_count)) AS NUMERIC(12,1))
50065054
ELSE 0 END AS [Avg ms Per Wait],
5055+
/*Vlad - moved for PSBlitz - end*/
50075056
N'https://www.sqlskills.com/help/waits/' + LOWER(wd1.wait_type) + '/' AS URL
50085057
FROM max_batch b
50095058
JOIN #WaitStats wd2 ON
@@ -5071,15 +5120,14 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
50715120
AND wd1.FileID = wd2.FileID
50725121
)
50735122
SELECT
5074-
Pattern,
5123+
Pattern,
50755124
CONVERT(VARCHAR(25),CAST([Sample Time] AS DATETIME),120) AS [Sample Time], /*changes for PSBlitz */
5076-
[Sample (seconds)],
5077-
[File Name], [Drive], [# Reads/Writes],[MB Read/Written],[Avg Stall (ms)], [file physical name], [DatabaseName], [StallRank]
5125+
[Sample (seconds)], [File Name], [Drive], [# Reads/Writes],[MB Read/Written],[Avg Stall (ms)], [file physical name], [DatabaseName], [StallRank]
50785126
FROM readstats
50795127
WHERE StallRank <=20 AND [MB Read/Written] > 0
50805128
UNION ALL
50815129
SELECT Pattern, CONVERT(VARCHAR(25),CAST([Sample Time] AS DATETIME),120) AS [Sample Time], /*changes for PSBlitz */
5082-
[Sample (seconds)], [File Name], [Drive], [# Reads/Writes],[MB Read/Written],[Avg Stall (ms)], [file physical name], [DatabaseName], [StallRank]
5130+
[Sample (seconds)], [File Name], [Drive], [# Reads/Writes],[MB Read/Written],[Avg Stall (ms)], [file physical name], [DatabaseName], [StallRank]
50835131
FROM writestats
50845132
WHERE StallRank <=20 AND [MB Read/Written] > 0
50855133
ORDER BY Pattern, StallRank;
@@ -5093,17 +5141,17 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
50935141
SELECT /*'PERFMON' AS Pattern, -- Vlad - column changes for PSBlitz */
50945142
pLast.[object_name], pLast.counter_name, pLast.instance_name,
50955143
CONVERT(VARCHAR(30),pFirst.SampleTime,120) AS FirstSampleTime, /*Vlad - the original version of this column doesn't contain the TZ offset,
5096-
so it ends up looking wrong eitherway - changes for PSBlitz */
5144+
so it ends up looking wrong eitherway - changes for PSBlitz */
50975145
pFirst.cntr_value AS FirstSampleValue,
5098-
CONVERT(VARCHAR(30),pLast.SampleTime,120) AS LastSampleTime, /* changes for PSBlitz */
5146+
CONVERT(VARCHAR(30),pLast.SampleTime,120) AS LastSampleTime, /* changes for PSBlitz */
50995147
pLast.cntr_value AS LastSampleValue,
51005148
pLast.cntr_value - pFirst.cntr_value AS ValueDelta,
51015149
((1.0 * pLast.cntr_value - pFirst.cntr_value) / DATEDIFF(ss, pFirst.SampleTime, pLast.SampleTime)) AS ValuePerSecond
51025150
FROM #PerfmonStats pLast
51035151
INNER JOIN #PerfmonStats pFirst ON pFirst.[object_name] = pLast.[object_name] AND pFirst.counter_name = pLast.counter_name AND (pFirst.instance_name = pLast.instance_name OR (pFirst.instance_name IS NULL AND pLast.instance_name IS NULL))
51045152
AND pLast.ID > pFirst.ID
51055153
WHERE pLast.cntr_value <> pFirst.cntr_value
5106-
ORDER BY /*Pattern, -- Vlad - column changes for PSBlitz */
5154+
ORDER BY /*Pattern, -- Vlad - column changes for PSBlitz */
51075155
pLast.[object_name], pLast.counter_name, pLast.instance_name;
51085156

51095157

0 commit comments

Comments
 (0)