Skip to content

Commit 3ab56b6

Browse files
authored
Merge pull request #1692 from Adedba/dev
Issue 1689 - Memory Grants and Query workspace info
2 parents 244abf2 + b55edc6 commit 3ab56b6

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

Documentation/sp_BlitzFirst Checks by Priority.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Before adding a new check, make sure to add a Github issue for it first, and hav
66

77
If you want to change anything about a check - the priority, finding, URL, or ID - open a Github issue first. The relevant scripts have to be updated too.
88

9-
CURRENT HIGH CHECKID: 38
10-
If you want to add a new check, start at 39
9+
CURRENT HIGH CHECKID: 40
10+
If you want to add a new check, start at 41
1111

1212
| Priority | FindingsGroup | Finding | URL | CheckID |
1313
|----------|---------------------------------|---------------------------------------|-------------------------------------------------|----------|
@@ -37,6 +37,7 @@ If you want to add a new check, start at 39
3737
| 50 | Server Performance | Slow Data File Reads | https://BrentOzar.com/go/slow | 11 |
3838
| 50 | Server Performance | Slow Log File Writes | https://BrentOzar.com/go/slow | 12 |
3939
| 50 | Server Performance | Too Much Free Memory | https://BrentOzar.com/go/freememory | 34 |
40+
| 50 | Server Performance | Memory Grants pending | https://www.brentozar.com/blitz/memory-grants | 39 |
4041
| 100 | In-Memory OLTP | Transactions aborted | https://BrentOzar.com/go/aborted | 32 |
4142
| 100 | Query Problems | Suboptimal Plans/Sec High | https://BrentOzar.com/go/suboptimal | 33 |
4243
| 200 | Wait Stats | (One per wait type) | https://BrentOzar.com/sql/wait-stats/#(waittype) | 6 |
@@ -49,3 +50,4 @@ If you want to add a new check, start at 39
4950
| 251 | Server Info | CPU Utilization | | 23 |
5051
| 251 | Server Info | Database Count | | 22 |
5152
| 251 | Server Info | Database Size, Total GB | | 21 |
53+
| 251 | Server Info | Memory Grant/Workspace info | | 40 |

sp_BlitzFirst.sql

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,43 @@ BEGIN
16551655
FROM sys.databases
16561656
WHERE database_id > 4;
16571657

1658+
/* Server Info - Memory Grants pending - CheckID 39 */
1659+
INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, Details, DetailsInt, URL)
1660+
SELECT 39 AS CheckID,
1661+
50 AS Priority,
1662+
'Server Performance' AS FindingGroup,
1663+
'Memory Grants Pending' AS Finding,
1664+
CAST(PendingGrants.Details AS NVARCHAR(50)) AS Details,
1665+
PendingGrants.DetailsInt,
1666+
'https://www.brentozar.com/blitz/memory-grants/' AS URL
1667+
FROM
1668+
(
1669+
SELECT
1670+
COUNT(1) AS Details,
1671+
COUNT(1) AS DetailsInt
1672+
FROM sys.dm_exec_query_memory_grants AS Grants
1673+
WHERE queue_id IS NOT NULL
1674+
) AS PendingGrants
1675+
WHERE PendingGrants.Details > 0;
1676+
1677+
/* Server Info - Memory Grant/Workspace info - CheckID 40 */
1678+
DECLARE @MaxWorkspace BIGINT
1679+
SET @MaxWorkspace = (SELECT CAST(cntr_value AS INT)/1024 FROM #PerfmonStats WHERE counter_name = N'Maximum Workspace Memory (KB)')
1680+
1681+
INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, Details, DetailsInt, URL)
1682+
SELECT 40 AS CheckID,
1683+
251 AS Priority,
1684+
'Server Info' AS FindingGroup,
1685+
'Memory Grant/Workspace info' AS Finding,
1686+
+ 'Grants Outstanding: ' + CAST((SELECT COUNT(*) FROM sys.dm_exec_query_memory_grants WHERE queue_id IS NULL) AS NVARCHAR(50)) + @LineFeed
1687+
+ 'Total Granted(MB): ' + CAST(ISNULL(SUM(Grants.granted_memory_kb)/1024,0) AS NVARCHAR(50)) + @LineFeed
1688+
+ 'Total WorkSpace(MB): '+ CAST(ISNULL(@MaxWorkspace,0) AS NVARCHAR(50))+ @LineFeed
1689+
+ 'Granted workspace: '+ CAST(ISNULL((CAST(SUM(Grants.granted_memory_kb)/1024 AS MONEY)/CAST(@MaxWorkspace AS MONEY))*100,0) AS NVARCHAR(50)) +'%'+ @LineFeed
1690+
+ 'Oldest Grant in seconds: '+ CAST(ISNULL(DATEDIFF(SECOND,MIN(Grants.request_time),GETDATE()),0) AS NVARCHAR(50)) AS Details,
1691+
(SELECT COUNT(*) FROM sys.dm_exec_query_memory_grants WHERE queue_id IS NULL) AS DetailsInt,
1692+
'http://www.BrentOzar.com/askbrent/' AS URL
1693+
FROM sys.dm_exec_query_memory_grants AS Grants;
1694+
16581695
/* Server Performance - High CPU Utilization CheckID 24 */
16591696
IF @Seconds < 30
16601697
BEGIN

0 commit comments

Comments
 (0)