File tree 1 file changed +28
-1
lines changed
1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change 20
20
[free space in MB] = (SUM(unallocated_extent_page_count)*1.0/128)
21
21
FROM tempdb.sys.dm_db_file_space_usage;
22
22
23
-
23
+ -- Get Allocations by session.
24
24
;with TempDBAlloc
25
25
as
26
26
(
@@ -40,6 +40,33 @@ where tempdb_current_usage_MB>0
40
40
order by tempdb_current_usage_MB desc
41
41
42
42
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
+
43
70
-- another option to monitor TemoDB usage is by using Adam Machanic WhoIsActive stored procedure.
44
71
-- http://dataeducation.com/sp_whoisactive-for-azure-sql-database-attempt-2/
45
72
You can’t perform that action at this time.
0 commit comments