在TempDB中查找占用空间的程序SQL
Find What Process Is Taking Up Space In TempDB With SQL
TIME STAMP
Contents
中文
这是我编写的一个脚本,可以找出哪些程序占用了TempDB中的空间,以及程序的来源。
English
Here’s a script I threw together to find what process is taking up space in the TempDB, and where the process came from.
Logic
--find what objects are taking up the most TempDB space and where the process is coming from
--查找哪些对象占用了最多的TempDB空间以及程序的来源
use master;
set nocount on
select
sddssu.session_id
, 'login name' = sdes.login_name
, 'from device' = sdes.host_name
, 'database' = db_name(sddssu.database_id)
, 'space consumed in gb' = (sddssu.user_objects_alloc_page_count *8 / 1024 / 2014)
, 'process' = sder.command
, 'statement' = sdest.text
from
sys.dm_db_session_space_usage sddssu
join sys.dm_exec_requests sder on sddssu.session_id = sder.session_id
cross apply sys.dm_exec_sql_text(sder.sql_handle) sdest
join sys.dm_exec_sessions sdes on sdes.session_id = sder.session_id
where
db_name(sddssu.database_id) in ('tempdb')
and sddssu.user_objects_alloc_page_count > 0
Build-Info
Build Quality | Build History | ||||
---|---|---|---|---|---|
Author
- 李聪明的数据库 Lee's Clever Data
- Mike的数据库宝典 Mikes Database Collection
- 李聪明的数据库 "Lee Songming"