Sqlserver定位哪些物件和哪些會話哪些sql語句消耗了tempdb
SELECT SUM(user_object_reserved_page_count) * 8/1024/1024 as user_object_size_GB,
SUM(internal_object_reserved_page_count) * 8/1024/1024 as internal_object_size_GB,
SUM(unallocated_extent_page_count) * 8/1024/1024 as unallocated_size_GB,
SUM(allocated_extent_page_count) * 8/1024/1024 as allocated_size_GB,
SUM(mixed_extent_page_count) * 8/1024/1024 as mixed_size_GB,
SUM(version_store_reserved_page_count) * 8/1024/1024 as version_store_size_GB,
SUM(total_page_count) * 8/1024/1024 as total_size_GB
FROM tempdb.sys.dm_db_file_space_usage;
--查詢tempdb的tempfile的使用情況
--user_object_reserved_page_count表示:全域性臨時表和索引、區域性臨時表和索引、表變數
--internal_object_reserved_page_count表示:遊標、臨時大型物件 (LOB) 、雜湊聯接、排序等操作
--version_store_reserved_page_count表示:版本儲存
use tempdb
go
SELECT top 100 t1.session_id, 'KILL '+CAST(t1.session_id AS NVARCHAR(100)) AS KillCmd ,
t1.internal_objects_alloc_page_count,t1.user_objects_alloc_page_count, t3.host_name,t3.login_name,t3.login_time,
(t1.internal_objects_alloc_page_count-t1.internal_objects_dealloc_page_count)*8/1024/1024 internal_nodealloc_GB ,
(t1.user_objects_alloc_page_count-t1.user_objects_dealloc_page_count)*8/1024/1024 user_nodealloc_GB ,
t3.last_request_start_time,t3.status,t3.total_elapsed_time
from sys.dm_db_session_space_usage t1
inner join sys.dm_exec_sessions as t3
on t1.session_id = t3.session_id
where (t1.internal_objects_alloc_page_count>0
or t1.user_objects_alloc_page_count >0
or t1.internal_objects_dealloc_page_count>0
or t1.user_objects_dealloc_page_count>0)
order by t1.internal_objects_alloc_page_count-t1.internal_objects_dealloc_page_count desc
--查詢消耗tempdb的session資訊
select Replace(b.text,'''','''') ,a.*
from sys.sysprocesses as a with(nolock)
cross apply sys.dm_exec_sql_text(sql_handle) as b where a.spid in (XX)
--查詢session中執行的sql語句,XX就是第一個語句結果中的第一列t1.session_id
SELECT a.session_id, a.transaction_id, a.transaction_sequence_num, a.elapsed_time_seconds, b.program_name
, b.open_tran, b.STATUS, b.login_time, b.hostname, db_name(b.dbid) dbname
FROM sys.dm_tran_active_snapshot_database_transactions a
JOIN sys.sysprocesses b ON a.session_id = b.spid
ORDER BY elapsed_time_seconds DESC
--查詢生成行版本或可能訪問行版本的活動事務,即涉及使用version_store_reserved_page_count的會話
select db_name(database_id),* from sys.dm_tran_version_store_space_usage order by 3 desc
查詢每個資料庫在tempdb中佔有的消耗的版本儲存空間
SELECT session_id,
SUM(internal_objects_alloc_page_count) AS task_internal_objects_alloc_page_count,
SUM(internal_objects_dealloc_page_count) AS task_internal_objects_dealloc_page_count,
SUM(internal_objects_dealloc_page_count*8/1024/1024) AS task_internal_objects_dealloc_size_GB
FROM sys.dm_db_task_space_usage
GROUP BY session_id
order by 4 desc;
--獲取每個會話中當前執行的所有任務的內部物件所消耗的空間
SELECT R2.session_id,
R1.internal_objects_alloc_page_count
+ SUM(R2.internal_objects_alloc_page_count) AS session_internal_objects_alloc_page_count,
R1.internal_objects_dealloc_page_count
+ SUM(R2.internal_objects_dealloc_page_count) AS session_internal_objects_dealloc_page_count
FROM sys.dm_db_session_space_usage AS R1
INNER JOIN sys.dm_db_task_space_usage AS R2 ON R1.session_id = R2.session_id
GROUP BY R2.session_id, R1.internal_objects_alloc_page_count,
R1.internal_objects_dealloc_page_count
order by 2 desc;
--獲取當前會話中的內部物件在執行和完成任務時所消耗的空間
select name,snapshot_isolation_state_desc from sys.databases order by 2
--查詢資料庫的隔離級別
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30126024/viewspace-2793298/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 如何定位SQL語句在共享池裡用到了哪些chunksSQL
- Oracle高資源消耗SQL語句定位OracleSQL
- php中有哪些迴圈控制語句PHP
- 工作中,我們經常用到哪些SQL語句呢?SQL
- SQL Server如何判斷哪些會話/連線是長連線?SQLServer會話
- 25 屆秋招真的回暖了?說這句話的都是哪些人
- 騰訊面試:一條SQL語句執行得很慢的原因有哪些?面試SQL
- Python中流程控制語句有哪些?Python
- 如何快速定位當前資料庫消耗 CPU 最高的 sql 語句?資料庫SQL
- html與css中都有哪些定位?HTMLCSS
- sqlserver dba常用的sql語句SQLServer
- 『Java 語法基礎』物件導向有哪些特性Java物件
- SQLServer的tempdb暴增導致磁碟消耗的處理方案SQLServer
- 物件導向有哪些特性物件
- js中bom物件有哪些JS物件
- 物件儲存有哪些用處?物件
- 程式語言有哪些
- sqlserver 檢視和sql語句的效率對比SQLServer
- SQLServer查詢哪些索引利用率低SQLServer索引
- SQLServer資料庫管理常用的SQL和T-SQL語句SQLServer資料庫
- Java建立物件的方法有哪些?Java物件
- 哪些oracle物件可以重新命名Oracle物件
- 騰訊面試:一條SQL語句執行得很慢的原因有哪些?---不看後悔系列面試SQL
- WebFlux 和 Spring Security 會碰出哪些火花?WebUXSpring
- JVM 還支援哪些語言JVM
- CWE-384: Session Fixation 會話固定漏洞有哪些修補方法?Session會話
- Python的控制語句有哪些?常見內容介紹!Python
- sqlserver採集欄位的sql語句SQLServer
- 使用電話機器人有哪些便利?機器人
- go語言有哪些優勢Go
- JavaScript6裡出現了哪些新語法、新特徵?JavaScript特徵
- 快速定位sql語句執行內容SQL
- 找出消耗CPU最高的程式對應的SQL語句SQL
- 檢視哪些表的哪些列含有指定字串(如‘andy’存在哪些表的哪些列中)字串
- SQLServer效能優化之改寫SQL語句SQLServer優化
- SQLServer資料庫管理的常用SQL語句SQLServer資料庫
- 查詢處理死鎖會話的sql語句(轉貼)會話SQL
- 是哪些技術把你和小夥伴分開了?