Skip to content

Commit 982b0be

Browse files
committed
Update SQL Server Diagnostic Information Queries to 2019-08
1 parent 4a81f61 commit 982b0be

6 files changed

+397
-413
lines changed

Scripts/SQL Managed Instance Diagnostic Information Queries.sql

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

22
-- SQL Managed Instance Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: July 18, 2019
4+
-- Last Modified: August 8, 2019
55
-- https://www.sqlskills.com/blogs/glenn/
66
-- http://sqlserverperformance.wordpress.com/
77
-- Twitter: GlennAlanBerry
@@ -88,8 +88,8 @@ SERVERPROPERTY('InstanceDefaultDataPath') AS [InstanceDefaultDataPath],
8888
SERVERPROPERTY('InstanceDefaultLogPath') AS [InstanceDefaultLogPath],
8989
SERVERPROPERTY('BuildClrVersion') AS [Build CLR Version],
9090
SERVERPROPERTY('IsXTPSupported') AS [IsXTPSupported],
91-
SERVERPROPERTY('IsPolybaseInstalled') AS [IsPolybaseInstalled],-- New for SQL Server 2016
92-
SERVERPROPERTY('IsAdvancedAnalyticsInstalled') AS [IsRServicesInstalled];-- New for SQL Server 2016
91+
SERVERPROPERTY('IsPolybaseInstalled') AS [IsPolybaseInstalled],
92+
SERVERPROPERTY('IsAdvancedAnalyticsInstalled') AS [IsRServicesInstalled];
9393
------
9494

9595
-- This gives you a lot of useful information about your "instance" of SQL Managed Instance
@@ -194,10 +194,17 @@ WHERE node_state_desc <> N'ONLINE DAC' OPTION (RECOMPILE);
194194

195195
-- Server Resource Statistics (Query 7) (Server Resource Stats)
196196
SELECT TOP(250) resource_type, resource_name, sku, hardware_generation,
197-
virtual_core_count, avg_cpu_percent,
198-
io_requests, io_bytes_read, io_bytes_written, start_time, end_time
197+
virtual_core_count, avg_cpu_percent, io_requests,
198+
CONVERT(DECIMAL(18,2), io_bytes_read/1048576.0) AS [MB Read],
199+
CONVERT(DECIMAL(18,2), io_bytes_read * 1./(io_bytes_read + io_bytes_written) * 100.) AS [Read Percentage],
200+
CONVERT(DECIMAL(18,2), io_bytes_written/1048576.0) AS [MB Written],
201+
CONVERT(DECIMAL(18,2), io_bytes_written * 1./(io_bytes_read + io_bytes_written) * 100.) AS [Write Percentage],
202+
CONVERT(DECIMAL(18,2), (io_bytes_read + io_bytes_written)/1048576.0) AS [MB Total IO],
203+
start_time, end_time
199204
FROM master.sys.server_resource_stats WITH (NOLOCK)
205+
WHERE io_bytes_read > 0 AND io_bytes_written > 0
200206
ORDER BY end_time DESC OPTION (RECOMPILE);
207+
------
201208

202209
-- Shows recent resource usage, in 15-second slices
203210

@@ -526,21 +533,24 @@ ORDER BY [VLF Count] DESC OPTION (RECOMPILE);
526533
-- Get CPU utilization by database (Query 20) (CPU Usage by Database)
527534
WITH DB_CPU_Stats
528535
AS
529-
(SELECT pa.DatabaseID, DB_Name(pa.DatabaseID) AS [Database Name], SUM(qs.total_worker_time/1000) AS [CPU_Time_Ms]
536+
(SELECT pa.DatabaseID, DB_Name(pa.DatabaseID) AS [Database Name],
537+
SUM(qs.total_worker_time/1000) AS [CPU_Time_Ms]
530538
FROM sys.dm_exec_query_stats AS qs WITH (NOLOCK)
531539
CROSS APPLY (SELECT CONVERT(int, value) AS [DatabaseID]
532540
FROM sys.dm_exec_plan_attributes(qs.plan_handle)
533541
WHERE attribute = N'dbid') AS pa
534542
GROUP BY DatabaseID)
535-
SELECT ROW_NUMBER() OVER(ORDER BY [CPU_Time_Ms] DESC) AS [CPU Rank],
536-
[Database Name], [CPU_Time_Ms] AS [CPU Time (ms)],
543+
SELECT ROW_NUMBER() OVER(ORDER BY [CPU_Time_Ms] DESC) AS [CPU Rank],
544+
[Database Name], DatabaseID, [CPU_Time_Ms] AS [CPU Time (ms)],
537545
CAST([CPU_Time_Ms] * 1.0 / SUM([CPU_Time_Ms]) OVER() * 100.0 AS DECIMAL(5, 2)) AS [CPU Percent]
538546
FROM DB_CPU_Stats
539547
WHERE DatabaseID <> 32767 -- ResourceDB
540548
ORDER BY [CPU Rank] OPTION (RECOMPILE);
541549
------
542550

543551
-- Helps determine which database is using the most CPU resources on the instance
552+
-- There are two copies on the master database. The low DatabaseID is the physical master,
553+
-- and the high DatabaseID is the replicated master
544554
-- Note: This only reflects CPU usage from the currently cached query plans
545555

546556

@@ -549,11 +559,11 @@ WITH Aggregate_IO_Statistics
549559
AS (SELECT DB_NAME(database_id) AS [Database Name],
550560
CAST(SUM(num_of_bytes_read + num_of_bytes_written) / 1048576 AS DECIMAL(12, 2)) AS [ioTotalMB],
551561
CAST(SUM(num_of_bytes_read ) / 1048576 AS DECIMAL(12, 2)) AS [ioReadMB],
552-
CAST(SUM(num_of_bytes_written) / 1048576 AS DECIMAL(12, 2)) AS [ioWriteMB]
562+
CAST(SUM(num_of_bytes_written) / 1048576 AS DECIMAL(12, 2)) AS [ioWriteMB], database_id
553563
FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS [DM_IO_STATS]
554564
GROUP BY database_id)
555565
SELECT ROW_NUMBER() OVER (ORDER BY ioTotalMB DESC) AS [I/O Rank],
556-
[Database Name], ioTotalMB AS [Total I/O (MB)],
566+
[Database Name], database_id, ioTotalMB AS [Total I/O (MB)],
557567
CAST(ioTotalMB / SUM(ioTotalMB) OVER () * 100.0 AS DECIMAL(5, 2)) AS [Total I/O %],
558568
ioReadMB AS [Read I/O (MB)],
559569
CAST(ioReadMB / SUM(ioReadMB) OVER () * 100.0 AS DECIMAL(5, 2)) AS [Read I/O %],
@@ -572,13 +582,14 @@ ORDER BY [I/O Rank] OPTION (RECOMPILE);
572582
-- This make take some time to run on a busy instance
573583
WITH AggregateBufferPoolUsage
574584
AS
575-
(SELECT DB_NAME(database_id) AS [Database Name],
585+
(SELECT DB_NAME(database_id) AS [Database Name], database_id,
576586
CAST(COUNT(*) * 8/1024.0 AS DECIMAL (10,2)) AS [CachedSize]
577587
FROM sys.dm_os_buffer_descriptors WITH (NOLOCK)
578588
WHERE database_id <> 32767 -- ResourceDB
579-
GROUP BY DB_NAME(database_id))
580-
SELECT ROW_NUMBER() OVER(ORDER BY CachedSize DESC) AS [Buffer Pool Rank], [Database Name], CachedSize AS [Cached Size (MB)],
581-
CAST(CachedSize / SUM(CachedSize) OVER() * 100.0 AS DECIMAL(5,2)) AS [Buffer Pool Percent]
589+
GROUP BY DB_NAME(database_id), database_id)
590+
SELECT ROW_NUMBER() OVER(ORDER BY CachedSize DESC) AS [Buffer Pool Rank],
591+
[Database Name], database_id, CachedSize AS [Cached Size (MB)],
592+
CAST(CachedSize / SUM(CachedSize) OVER() * 100.0 AS DECIMAL(5,2)) AS [Buffer Pool Percent]
582593
FROM AggregateBufferPoolUsage
583594
ORDER BY [Buffer Pool Rank] OPTION (RECOMPILE);
584595
------
@@ -1129,7 +1140,7 @@ qs.total_elapsed_time, qs.total_elapsed_time/qs.execution_count AS [avg_elapsed_
11291140
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
11301141
FORMAT(qs.last_execution_time, 'yyyy-MM-dd HH:mm:ss', 'en-US') AS [Last Execution Time],
11311142
FORMAT(qs.cached_time, 'yyyy-MM-dd HH:mm:ss', 'en-US') AS [Plan Cached Time]
1132-
-- ,qp.query_plan AS [Query Plan] -- Uncomment if you want the Query Plan
1143+
--,qp.query_plan AS [Query Plan] -- Uncomment if you want the Query Plan
11331144
FROM sys.procedures AS p WITH (NOLOCK)
11341145
INNER JOIN sys.dm_exec_procedure_stats AS qs WITH (NOLOCK)
11351146
ON p.[object_id] = qs.[object_id]
@@ -1631,6 +1642,8 @@ AND bs.[type] = 'D'
16311642
ORDER BY bs.backup_finish_date DESC OPTION (RECOMPILE);
16321643
------
16331644

1645+
-- Automatic database backups by the MI Service will not appear in this list
1646+
16341647
-- Are your backup sizes and times changing over time?
16351648
-- Are you using backup compression?
16361649
-- Are you using backup checksums?

Scripts/SQL Server 2014 Diagnostic Information Queries.sql

Lines changed: 4 additions & 2 deletions
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: July 9, 2019
4+
-- Last Modified: August 1, 2019
55
-- https://www.sqlskills.com/blogs/glenn/
66
-- http://sqlserverperformance.wordpress.com/
77
-- Twitter: GlennAlanBerry
@@ -84,7 +84,7 @@ SELECT @@SERVERNAME AS [Server Name], @@VERSION AS [SQL Server and OS Version In
8484
--12.0.4502 SP1 CU11 2/21/2017 12.0.5540 SP2 CU4 2/21/2017
8585
--12.0.4511 SP1 CU12 4/17/2017 12.0.5546 SP2 CU5 4/17/2017
8686
--12.0.4522 SP1 CU13 7/17/2017 12.0.5552 SP2 CU6 7/17/2017
87-
--12.0.5556 SP2 CU7 8/28/2017
87+
--12.0.5556 SP2 CU7 8/28/2017
8888
--12.0.5557 SP2 CU8 10/16/2017
8989
--12.0.5563 SP2 CU9 12/18/2017
9090
--12.0.5571 SP2 CU10 1/16/2018
@@ -96,6 +96,7 @@ SELECT @@SERVERNAME AS [Server Name], @@VERSION AS [SQL Server and OS Version In
9696
--12.0.5605 SP2 CU15 12/12/2018 ----> 12.0.6205 SP3 CU1 12/12/2018
9797
--12.0.5626 SP2 CU16 2/19/2019 ----> 12.0.6214 SP3 CU2 2/19/2019
9898
--12.0.5632 SP2 CU17 4/16/2019 ----> 12.0.6259 SP3 CU3 4/16/2019
99+
--12.0.5687 SP2 CU18 7/29/2019 ----> 12.0.6329 SP3 CU4 7/29/2019
99100

100101

101102

@@ -245,6 +246,7 @@ EXEC sys.xp_readerrorlog 0, 1, N'Database Instant File Initialization';
245246

246247
-- Lets you determine whether Instant File Initialization (IFI) is enabled for the instance
247248
-- This should be enabled in the vast majority of cases
249+
-- Note: This query won't return any results if the SQL Server error log has been recycled
248250

249251

250252
-- Database Instant File Initialization

0 commit comments

Comments
 (0)