Skip to content

Commit f49d927

Browse files
Updating with minor changes
Update with query number and add version store information
1 parent 76fffc9 commit f49d927

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

AzureTempDB_SpaceMonitoring.txt

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
-- get Database name
1+
-- (1) get Database name
22
select db_name() as DatabaseName
33

4-
-- Get SLO Level
4+
-- (2) Get SLO Level
55
select *
66
from sys.database_service_objectives
77

8-
-- Get TempDB information current and max size
8+
-- (3) Get TempDB information current and max size
99
SELECT
1010
FILE_ID,
1111
type_desc,
@@ -14,13 +14,14 @@ SELECT
1414
FROM tempdb.sys.database_files
1515

1616

17-
-- From the current size, how much is used or free
18-
SELECT 
19-
[used space in MB] = (SUM(allocated_extent_page_count)*1.0/128),
20-
[free space in MB] = (SUM(unallocated_extent_page_count)*1.0/128) 
21-
FROM tempdb.sys.dm_db_file_space_usage; 
17+
-- (4) From the current size, how much is used or free
18+
SELECT
19+
[free space in MB] = format((SUM(unallocated_extent_page_count)*1.0/128),'#,##0'),
20+
[used space in MB] = format((SUM(allocated_extent_page_count)*1.0/128),'#,##0'),
21+
[VersionStore space in MB] = format((SUM(version_store_reserved_page_count)*1.0/128),'#,##0')
22+
FROM tempdb.sys.dm_db_file_space_usage;
2223

23-
-- Get Allocations by session.
24+
-- (5) Get Allocations by session.
2425
;with TempDBAlloc
2526
as
2627
(
@@ -40,7 +41,7 @@ where tempdb_current_usage_MB>0
4041
order by tempdb_current_usage_MB desc
4142

4243

43-
-- get size for temp tables
44+
-- (6) get size for temp tables
4445
SELECT
4546
s.Name AS SchemaName,
4647
t.NAME AS TableName,
@@ -65,13 +66,13 @@ GROUP BY
6566
ORDER BY
6667
s.Name, t.Name
6768

68-
-- Get Log file information
69+
-- (7) Get Log file information
6970
select counter_name,instance_name, SizeInMB=cntr_value/1024
7071
from sys.dm_os_performance_counters
7172
where counter_name in('Log File(s) Size (KB)','Log File(s) Used Size (KB)')
7273
and instance_name='tempdb'
7374

74-
-- Drill down to get information about log consumers
75+
--(8) Drill down to get information about log consumers
7576
select
7677
SS.session_id,
7778
SS.host_name,
@@ -106,7 +107,6 @@ From sys.dm_tran_database_transactions DBT
106107

107108

108109
-- another option to monitor TemoDB usage is by using Adam Machanic WhoIsActive stored procedure.
109-
-- http://dataeducation.com/sp_whoisactive-for-azure-sql-database-attempt-2/
110-
110+
-- http://whoisactive.com/
111111

112112

0 commit comments

Comments
 (0)