Skip to content

Commit e2e5018

Browse files
Save-DbaDiagnosticQueryScript - fix downloader and update files (#9788)
1 parent 939dde8 commit e2e5018

12 files changed

+649
-199
lines changed

bin/diagnosticquery/SQLServerDiagnosticQueries_2012.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
-- SQL Server 2012 Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: February 13, 2025
4+
-- Last Modified: August 4, 2025
55
-- https://glennsqlperformance.com/
66
-- https://sqlserverperformance.wordpress.com/
77
-- YouTube: https://bit.ly/2PkoAM1

bin/diagnosticquery/SQLServerDiagnosticQueries_2014.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
-- SQL Server 2014 Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: February 13, 2025
4+
-- Last Modified: August 4, 2025
55
-- https://glennsqlperformance.com/
66
-- https://sqlserverperformance.wordpress.com/
77
-- YouTube: https://bit.ly/2PkoAM1

bin/diagnosticquery/SQLServerDiagnosticQueries_2016.sql renamed to bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP1.sql

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
-- SQL Server 2016 Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: March 1, 2025
4+
-- Last Modified: August 4, 2025
55
-- https://glennsqlperformance.com/
66
-- https://sqlserverperformance.wordpress.com/
77
-- YouTube: https://bit.ly/2PkoAM1
@@ -481,22 +481,79 @@ FROM sys.dm_os_sys_memory WITH (NOLOCK) OPTION (RECOMPILE);
481481

482482

483483

484-
-- You can skip the next two queries if you know you don't have a clustered instance
485484

485+
-- Consolidated memory information from SQL Server 2025 (Query 14) (Memory Snapshot)
486+
DECLARE @MaxServerMemoryMB AS DECIMAL (15,2);
487+
DECLARE @SQLServerMemoryUsageMB AS BIGINT;
488+
DECLARE @SQLServerLockedPagesAllocationMB AS BIGINT;
489+
DECLARE @TotalPhysicalMemoryMB AS DECIMAL (15,2);
490+
DECLARE @AvailablePhysicalMemoryMB AS BIGINT;
491+
DECLARE @SystemMemoryState AS NVARCHAR(50);
492+
DECLARE @SQLServerStartTime AS DATETIME;
493+
DECLARE @SQLBufferPoolMemoryUsageMB AS DECIMAL (15,2);
494+
DECLARE @SQLSOSNODEMemoryUsageMB AS DECIMAL (15,2);
495+
DECLARE @AvgPageLifeExpectancy int = 0;
486496

487-
-- Get information about your cluster nodes and their status (Query 14) (Cluster Node Properties)
488-
-- (if your database server is in a failover cluster)
489-
SELECT NodeName, status_description, is_current_owner
490-
FROM sys.dm_os_cluster_nodes WITH (NOLOCK) OPTION (RECOMPILE);
497+
-- Basic information about OS memory amounts and state
498+
SELECT @TotalPhysicalMemoryMB = total_physical_memory_kb/1024,
499+
@AvailablePhysicalMemoryMB = available_physical_memory_kb/1024,
500+
@SystemMemoryState = system_memory_state_desc
501+
FROM sys.dm_os_sys_memory WITH (NOLOCK) OPTION (RECOMPILE);
502+
503+
-- Get instance-level configuration value for instance
504+
SELECT @MaxServerMemoryMB = CONVERT(INT, value)
505+
FROM sys.configurations WITH (NOLOCK)
506+
WHERE [name] = N'max server memory (MB)' OPTION (RECOMPILE);
507+
508+
-- SQL Server Memory Usage and Locked Pages Allocations
509+
SELECT @SQLServerMemoryUsageMB = physical_memory_in_use_kb/1024,
510+
@SQLServerLockedPagesAllocationMB = locked_page_allocations_kb/1024
511+
FROM sys.dm_os_process_memory WITH (NOLOCK) OPTION (RECOMPILE);
512+
513+
-- SQL Server Start Time
514+
SELECT @SQLServerStartTime = sqlserver_start_time
515+
FROM sys.dm_os_sys_info WITH (NOLOCK) OPTION (RECOMPILE);
516+
517+
-- SQLBUFFERPOOL Memory Clerk Usage
518+
SELECT @SQLBufferPoolMemoryUsageMB =
519+
CAST((SUM(mc.pages_kb)/1024.0) AS DECIMAL (15,2))
520+
FROM sys.dm_os_memory_clerks AS mc WITH (NOLOCK)
521+
WHERE mc.[type] = N'MEMORYCLERK_SQLBUFFERPOOL'
522+
GROUP BY mc.[type] OPTION (RECOMPILE);
523+
524+
-- MEMORYCLERK_SOSNODE Memory Clerk Usage
525+
SELECT @SQLSOSNODEMemoryUsageMB =
526+
CAST((SUM(mc.pages_kb)/1024.0) AS DECIMAL (15,2))
527+
FROM sys.dm_os_memory_clerks AS mc WITH (NOLOCK)
528+
WHERE mc.[type] = N'MEMORYCLERK_SOSNODE'
529+
GROUP BY mc.[type] OPTION (RECOMPILE);
530+
531+
-- Page Life Expectancy (PLE) value for current instance
532+
SET @AvgPageLifeExpectancy = (SELECT AVG(cntr_value) AS [PageLifeExpectancy]
533+
FROM sys.dm_os_performance_counters WITH (NOLOCK)
534+
WHERE [object_name] LIKE N'%Buffer Node%' -- Handles named instances
535+
AND counter_name = N'Page life expectancy');
536+
537+
-- Return final results
538+
SELECT @@SERVERNAME AS [Server Name], @@VERSION AS [SQL Server and OS Version Info],
539+
CONVERT(INT, @TotalPhysicalMemoryMB) AS [OS Physical Memory (MB)],
540+
@SystemMemoryState AS [System Memory State],
541+
@AvailablePhysicalMemoryMB AS [OS Available Memory (MB)],
542+
CONVERT(INT, @MaxServerMemoryMB) AS [SQL Server Max Server Memory (MB)],
543+
CONVERT(DECIMAL(18,2),(@MaxServerMemoryMB/@TotalPhysicalMemoryMB) * 100.0) AS [Max Server Memory %],
544+
@SQLServerMemoryUsageMB AS [SQL Server Total Memory Usage (MB)],
545+
@AvgPageLifeExpectancy AS [Page Life Expectancy (Seconds)],
546+
@SQLBufferPoolMemoryUsageMB AS [SQL Buffer Pool Memory Usage (MB)],
547+
@SQLSOSNODEMemoryUsageMB AS [SOSNODE Memory Clerk Memory Usage (MB)],
548+
@SQLServerLockedPagesAllocationMB AS [SQL Server Locked Pages Allocation (MB)],
549+
@SQLServerStartTime AS [SQL Server Start Time];
550+
GO
491551
------
552+
-- End of Query 14 ***************************************************
492553

493-
-- Knowing which node owns the cluster resources is critical
494-
-- Especially when you are installing Windows or SQL Server updates
495-
-- You will see no results if your instance is not clustered
496554

497-
-- Recommended hotfixes and updates for Windows Server 2012 R2-based failover clusters
498-
-- https://bit.ly/1z5BfCw
499555

556+
-- You can skip the next two queries if you know you don't have an AG
500557

501558
-- Get information about any AlwaysOn AG cluster this instance is a part of (Query 15) (AlwaysOn AG Cluster)
502559
SELECT cluster_name, quorum_type_desc, quorum_state_desc

bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2.sql

Lines changed: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
-- SQL Server 2016 SP2 Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: March 1, 2025
4+
-- Last Modified: August 12, 2025
55
-- https://glennsqlperformance.com/
66
-- https://sqlserverperformance.wordpress.com/
77
-- YouTube: https://bit.ly/2PkoAM1
@@ -62,7 +62,8 @@ ELSE
6262
SELECT @@SERVERNAME AS [Server Name], @@VERSION AS [SQL Server and OS Version Info];
6363
------
6464

65-
-- SQL Server 2016 is out of mainstream from Microsoft
65+
-- SQL Server 2016 fell out of Mainstream Support on Jul 13, 2021
66+
-- SQL Server 2016 will fall out of Extended Support on Jul 14, 2026
6667

6768

6869
-- SQL Server 2016 Builds
@@ -99,6 +100,9 @@ SELECT @@SERVERNAME AS [Server Name], @@VERSION AS [SQL Server and OS Version In
99100
-- 13.0.6445.1 SP3 + GDR 9/10/2024 https://support.microsoft.com/en-us/topic/kb5042207-description-of-the-security-update-for-sql-server-2016-sp3-gdr-september-10-2024-e27a41df-009d-4a50-85e7-dc8f06b9a5a5
100101
-- 13.0.6450.1 SP3 + GDR 10/8/2024 https://support.microsoft.com/en-us/topic/kb5046063-description-of-the-security-update-for-sql-server-2016-sp3-gdr-october-8-2024-87f6091b-a0c0-48e7-8de4-b10381559ba7
101102
-- 13.0.6455.2 SP3 + GDR 11/12/2024 https://support.microsoft.com/en-us/topic/kb5046855-description-of-the-security-update-for-sql-server-2016-sp3-gdr-november-12-2024-736b0a32-912d-4ea5-baf8-50d046cbfa1a
103+
-- 13.0.6465.1 SP3 + GDR 8/12/2025 https://support.microsoft.com/en-us/topic/kb5063762-description-of-the-security-update-for-sql-server-2016-sp3-gdr-august-12-2025-c7c25df6-577c-49b3-9ca9-b7e9812b9344
104+
105+
102106

103107
-- Azure Connect Pack Builds
104108
-- 13.0.7000.253 Azure Connect Pack 5/19/2022 https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2016/servicepack3-azureconnect
@@ -109,6 +113,7 @@ SELECT @@SERVERNAME AS [Server Name], @@VERSION AS [SQL Server and OS Version In
109113
-- 13.0.7040.1 Azure Connect Pack + GDR 9/10/2024 https://support.microsoft.com/en-us/topic/kb5042207-description-of-the-security-update-for-sql-server-2016-sp3-gdr-september-10-2024-e27a41df-009d-4a50-85e7-dc8f06b9a5a5
110114
-- 13.0.7045.2 Azure Connect Pack + GDR 10/8/2024 https://support.microsoft.com/en-us/topic/kb5046062-description-of-the-security-update-for-sql-server-2016-sp3-azure-connect-feature-pack-october-8-2024-fb7d9289-bbef-4d1f-bd71-fb3e036d81ae
111115
-- 13.0.7050.2 Azure Connect Pack + GDR 11/12/2024 https://support.microsoft.com/en-us/topic/kb5046856-description-of-the-security-update-for-sql-server-2016-sp3-azure-connect-feature-pack-november-12-2024-b180cac0-187e-48eb-b6c6-3d48d0a00902
116+
-- 13.0.7060.1 Azure Connect Pack + GDR 8/12/2025 https://support.microsoft.com/en-us/topic/kb5063761-description-of-the-security-update-for-sql-server-2016-sp3-azure-connect-feature-pack-august-12-2025-78088dab-76e7-4a0d-8392-9ebb3f7dfefe
112117

113118

114119
-- How to determine the version, edition and update level of SQL Server and its components
@@ -486,22 +491,78 @@ FROM sys.dm_os_sys_memory WITH (NOLOCK) OPTION (RECOMPILE);
486491

487492

488493

489-
-- You can skip the next two queries if you know you don't have a clustered instance
494+
-- Consolidated memory information from SQL Server 2025 (Query 14) (Memory Snapshot)
495+
DECLARE @MaxServerMemoryMB AS DECIMAL (15,2);
496+
DECLARE @SQLServerMemoryUsageMB AS BIGINT;
497+
DECLARE @SQLServerLockedPagesAllocationMB AS BIGINT;
498+
DECLARE @TotalPhysicalMemoryMB AS DECIMAL (15,2);
499+
DECLARE @AvailablePhysicalMemoryMB AS BIGINT;
500+
DECLARE @SystemMemoryState AS NVARCHAR(50);
501+
DECLARE @SQLServerStartTime AS DATETIME;
502+
DECLARE @SQLBufferPoolMemoryUsageMB AS DECIMAL (15,2);
503+
DECLARE @SQLSOSNODEMemoryUsageMB AS DECIMAL (15,2);
504+
DECLARE @AvgPageLifeExpectancy int = 0;
505+
506+
-- Basic information about OS memory amounts and state
507+
SELECT @TotalPhysicalMemoryMB = total_physical_memory_kb/1024,
508+
@AvailablePhysicalMemoryMB = available_physical_memory_kb/1024,
509+
@SystemMemoryState = system_memory_state_desc
510+
FROM sys.dm_os_sys_memory WITH (NOLOCK) OPTION (RECOMPILE);
511+
512+
-- Get instance-level configuration value for instance
513+
SELECT @MaxServerMemoryMB = CONVERT(INT, value)
514+
FROM sys.configurations WITH (NOLOCK)
515+
WHERE [name] = N'max server memory (MB)' OPTION (RECOMPILE);
516+
517+
-- SQL Server Memory Usage and Locked Pages Allocations
518+
SELECT @SQLServerMemoryUsageMB = physical_memory_in_use_kb/1024,
519+
@SQLServerLockedPagesAllocationMB = locked_page_allocations_kb/1024
520+
FROM sys.dm_os_process_memory WITH (NOLOCK) OPTION (RECOMPILE);
521+
522+
-- SQL Server Start Time
523+
SELECT @SQLServerStartTime = sqlserver_start_time
524+
FROM sys.dm_os_sys_info WITH (NOLOCK) OPTION (RECOMPILE);
525+
526+
-- SQLBUFFERPOOL Memory Clerk Usage
527+
SELECT @SQLBufferPoolMemoryUsageMB =
528+
CAST((SUM(mc.pages_kb)/1024.0) AS DECIMAL (15,2))
529+
FROM sys.dm_os_memory_clerks AS mc WITH (NOLOCK)
530+
WHERE mc.[type] = N'MEMORYCLERK_SQLBUFFERPOOL'
531+
GROUP BY mc.[type] OPTION (RECOMPILE);
532+
533+
-- MEMORYCLERK_SOSNODE Memory Clerk Usage
534+
SELECT @SQLSOSNODEMemoryUsageMB =
535+
CAST((SUM(mc.pages_kb)/1024.0) AS DECIMAL (15,2))
536+
FROM sys.dm_os_memory_clerks AS mc WITH (NOLOCK)
537+
WHERE mc.[type] = N'MEMORYCLERK_SOSNODE'
538+
GROUP BY mc.[type] OPTION (RECOMPILE);
490539

540+
-- Page Life Expectancy (PLE) value for current instance
541+
SET @AvgPageLifeExpectancy = (SELECT AVG(cntr_value) AS [PageLifeExpectancy]
542+
FROM sys.dm_os_performance_counters WITH (NOLOCK)
543+
WHERE [object_name] LIKE N'%Buffer Node%' -- Handles named instances
544+
AND counter_name = N'Page life expectancy');
491545

492-
-- Get information about your cluster nodes and their status (Query 14) (Cluster Node Properties)
493-
-- (if your database server is in a failover cluster)
494-
SELECT NodeName, status_description, is_current_owner
495-
FROM sys.dm_os_cluster_nodes WITH (NOLOCK) OPTION (RECOMPILE);
546+
-- Return final results
547+
SELECT @@SERVERNAME AS [Server Name], @@VERSION AS [SQL Server and OS Version Info],
548+
CONVERT(INT, @TotalPhysicalMemoryMB) AS [OS Physical Memory (MB)],
549+
@SystemMemoryState AS [System Memory State],
550+
@AvailablePhysicalMemoryMB AS [OS Available Memory (MB)],
551+
CONVERT(INT, @MaxServerMemoryMB) AS [SQL Server Max Server Memory (MB)],
552+
CONVERT(DECIMAL(18,2),(@MaxServerMemoryMB/@TotalPhysicalMemoryMB) * 100.0) AS [Max Server Memory %],
553+
@SQLServerMemoryUsageMB AS [SQL Server Total Memory Usage (MB)],
554+
@AvgPageLifeExpectancy AS [Page Life Expectancy (Seconds)],
555+
@SQLBufferPoolMemoryUsageMB AS [SQL Buffer Pool Memory Usage (MB)],
556+
@SQLSOSNODEMemoryUsageMB AS [SOSNODE Memory Clerk Memory Usage (MB)],
557+
@SQLServerLockedPagesAllocationMB AS [SQL Server Locked Pages Allocation (MB)],
558+
@SQLServerStartTime AS [SQL Server Start Time];
559+
GO
496560
------
561+
-- End of Query 14 ***************************************************
497562

498-
-- Knowing which node owns the cluster resources is critical
499-
-- Especially when you are installing Windows or SQL Server updates
500-
-- You will see no results if your instance is not clustered
501563

502-
-- Recommended hotfixes and updates for Windows Server 2012 R2-based failover clusters
503-
-- https://bit.ly/1z5BfCw
504564

565+
-- You can skip the next two queries if you know you don't have an AG
505566

506567
-- Get information about any AlwaysOn AG cluster this instance is a part of (Query 15) (AlwaysOn AG Cluster)
507568
SELECT cluster_name, quorum_type_desc, quorum_state_desc
@@ -824,7 +885,7 @@ DROP TABLE IF EXISTS #IOWarningResults;
824885

825886

826887
-- Resource Governor Resource Pool information (Query 30) (RG Resource Pools)
827-
SELECT pool_id, [Name], statistics_start_time,
888+
SELECT pool_id, [name], statistics_start_time,
828889
min_memory_percent, max_memory_percent,
829890
max_memory_kb/1024 AS [max_memory_mb],
830891
used_memory_kb/1024 AS [used_memory_mb],
@@ -1765,7 +1826,7 @@ ORDER BY index_advantage DESC OPTION (RECOMPILE);
17651826
-- Note: This query could take some time on a busy instance
17661827
SELECT TOP(25) OBJECT_NAME(objectid) AS [ObjectName],
17671828
cp.objtype, cp.usecounts, cp.size_in_bytes
1768-
, qp.query_plan -- Uncomment if you want the Query Plan
1829+
-- , qp.query_plan -- Uncomment if you want the Query Plan
17691830
FROM sys.dm_exec_cached_plans AS cp WITH (NOLOCK)
17701831
CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) AS qp
17711832
WHERE CAST(qp.query_plan AS NVARCHAR(MAX)) LIKE N'%MissingIndex%'
@@ -1987,7 +2048,7 @@ ON ios.[object_id] = i.[object_id]
19872048
AND ios.index_id = i.index_id
19882049
WHERE o.[object_id] > 100
19892050
GROUP BY o.name, i.name, ios.index_id, ios.partition_number
1990-
HAVING SUM(ios.page_lock_wait_in_ms)+ SUM(row_lock_wait_in_ms) > 0
2051+
HAVING SUM(ios.page_lock_wait_in_ms) + SUM(row_lock_wait_in_ms) > 0
19912052
ORDER BY total_lock_wait_in_ms DESC OPTION (RECOMPILE);
19922053
------
19932054

0 commit comments

Comments
 (0)