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語句呢?SQL
- 如何快速定位當前資料庫消耗 CPU 最高的 sql 語句?資料庫SQL
- php中有哪些迴圈控制語句PHP
- sqlserver dba常用的sql語句SQLServer
- SQL Server如何判斷哪些會話/連線是長連線?SQLServer會話
- Python中流程控制語句有哪些?Python
- 25 屆秋招真的回暖了?說這句話的都是哪些人
- SQLServer的tempdb暴增導致磁碟消耗的處理方案SQLServer
- 騰訊面試:一條SQL語句執行得很慢的原因有哪些?面試SQL
- sqlserver採集欄位的sql語句SQLServer
- html與css中都有哪些定位?HTMLCSS
- 『Java 語法基礎』物件導向有哪些特性Java物件
- 物件導向有哪些特性物件
- 物件儲存有哪些用處?物件
- js中bom物件有哪些JS物件
- 遍歷陣列和物件的方法都有哪些?陣列物件
- SQLServer查詢哪些索引利用率低SQLServer索引
- Python的控制語句有哪些?常見內容介紹!Python
- MySQL 5.7定位消耗CPU高的SQLMySql
- 程式語言有哪些
- 會引起Reflow和Repaint的操作有哪些?AI
- WebFlux 和 Spring Security 會碰出哪些火花?WebUXSpring
- 騰訊面試:一條SQL語句執行得很慢的原因有哪些?---不看後悔系列面試SQL
- Java建立物件的方法有哪些?Java物件
- SqlServer中迴圈和條件語句SQLServer
- Sql語句本身的優化-定位慢查詢SQL優化
- JVM 還支援哪些語言JVM
- CWE-384: Session Fixation 會話固定漏洞有哪些修補方法?Session會話
- SQL語言有哪些分類?linux資料庫學習班SQLLinux資料庫
- Oracle 中定位重要(消耗資源多)的SQLOracleSQL
- 1.4 資料庫和常用SQL語句(正文)——MySQL資料庫命令和SQL語句資料庫MySql
- go語言有哪些優勢Go
- 使用電話機器人有哪些便利?機器人
- Java中如何解析SQL語句、格式化SQL語句、生成SQL語句?JavaSQL
- SQL語句SQL
- 必知必會——SQL語句基本語法整理SQL
- sql 語句網路除錯和 sql 語句低層傳輸檢視SQL除錯
- jvm(4)---垃圾回收(哪些物件可以被回收)JVM物件