Skip to content

Commit 74e9fd5

Browse files
Update AzureTempDB_SpaceMonitoring.txt
Adding query to get information for temp table sizes
1 parent acbcdb7 commit 74e9fd5

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

AzureTempDB_SpaceMonitoring.txt

+28-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SELECT 
2020
[free space in MB] = (SUM(unallocated_extent_page_count)*1.0/128) 
2121
FROM tempdb.sys.dm_db_file_space_usage; 
2222

23-
23+
-- Get Allocations by session.
2424
;with TempDBAlloc
2525
as
2626
(
@@ -40,6 +40,33 @@ where tempdb_current_usage_MB>0
4040
order by tempdb_current_usage_MB desc
4141

4242

43+
-- get size for temp tables
44+
SELECT
45+
s.Name AS SchemaName,
46+
t.NAME AS TableName,
47+
p.rows AS RowCounts,
48+
SUM(a.total_pages) * 8 AS TotalSpaceKB,
49+
SUM(a.used_pages) * 8 AS UsedSpaceKB,
50+
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
51+
FROM
52+
tempdb.sys.tables t
53+
INNER JOIN
54+
tempdb.sys.schemas s ON s.schema_id = t.schema_id
55+
INNER JOIN
56+
tempdb.sys.indexes i ON t.OBJECT_ID = i.object_id
57+
INNER JOIN
58+
tempdb.sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
59+
INNER JOIN
60+
tempdb.sys.allocation_units a ON p.partition_id = a.container_id
61+
WHERE
62+
t.NAME LIKE '#%' -- filter out system tables for diagramming
63+
GROUP BY
64+
t.Name, s.Name, p.Rows
65+
ORDER BY
66+
s.Name, t.Name
67+
68+
69+
4370
-- another option to monitor TemoDB usage is by using Adam Machanic WhoIsActive stored procedure.
4471
-- http://dataeducation.com/sp_whoisactive-for-azure-sql-database-attempt-2/
4572

0 commit comments

Comments
 (0)