1
- -- get Database name
1
+ -- (1) get Database name
2
2
select db_name() as DatabaseName
3
3
4
- -- Get SLO Level
4
+ -- (2) Get SLO Level
5
5
select *
6
6
from sys.database_service_objectives
7
7
8
- -- Get TempDB information current and max size
8
+ -- (3) Get TempDB information current and max size
9
9
SELECT
10
10
FILE_ID,
11
11
type_desc,
@@ -14,13 +14,14 @@ SELECT
14
14
FROM tempdb.sys.database_files
15
15
16
16
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;
22
23
23
- -- Get Allocations by session.
24
+ -- (5) Get Allocations by session.
24
25
;with TempDBAlloc
25
26
as
26
27
(
@@ -40,7 +41,7 @@ where tempdb_current_usage_MB>0
40
41
order by tempdb_current_usage_MB desc
41
42
42
43
43
- -- get size for temp tables
44
+ -- (6) get size for temp tables
44
45
SELECT
45
46
s.Name AS SchemaName,
46
47
t.NAME AS TableName,
@@ -65,13 +66,13 @@ GROUP BY
65
66
ORDER BY
66
67
s.Name, t.Name
67
68
68
- -- Get Log file information
69
+ -- (7) Get Log file information
69
70
select counter_name,instance_name, SizeInMB=cntr_value/1024
70
71
from sys.dm_os_performance_counters
71
72
where counter_name in('Log File(s) Size (KB)','Log File(s) Used Size (KB)')
72
73
and instance_name='tempdb'
73
74
74
- -- Drill down to get information about log consumers
75
+ --(8) Drill down to get information about log consumers
75
76
select
76
77
SS.session_id,
77
78
SS.host_name,
@@ -106,7 +107,6 @@ From sys.dm_tran_database_transactions DBT
106
107
107
108
108
109
-- 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/
111
111
112
112
0 commit comments