sql server 檢視tempdb使用的相關檢視
1、tempdb使用查詢,查詢當前的tempdb資料庫
SELECT 'tempdb' AS database_name , GETDATE() AS Time , SUM(user_object_reserved_page_count)/128. AS user_objects_mb ,
SUM(internal_object_reserved_page_count)/128. AS internal_objects_mb , SUM(version_store_reserved_page_count)/128. AS version_store_kb ,
SUM(unallocated_extent_page_count)/128. AS freespace_mb
FROM sys.dm_db_file_space_usage
WHERE database_id = 2
2、tempdb臨時資料庫分配給各個會話的使用情況
SELECT t1.session_id , t1.internal_objects_alloc_page_count , t1.user_objects_alloc_page_count , t1.internal_objects_dealloc_page_count ,
t1.user_objects_dealloc_page_count , t3.login_time , t3.login_name , t3.host_name , t3.nt_domain , t3.nt_user_name , t3.program_name ,
t3.status , t3.client_interface_name , t3.cpu_time , t3.memory_usage , t3.total_scheduled_time , t3.total_elapsed_time ,
t3.last_request_start_time , t3.last_request_end_time , t3.reads , t3.writes , t3.logical_reads , t3.is_user_process , t3.row_count ,
t3.prev_error , t3.original_security_id , t3.original_login_name , t3.last_successful_logon , t3.last_unsuccessful_logon ,
t3.unsuccessful_logons , t3.group_id
FROM sys.dm_db_session_space_usage t1 ,
sys.dm_exec_sessions AS t3
WHERE t1.session_id = t3.session_id
AND (
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
)
如果查詢出來,發現某個使用者使用較大,可以透過如下語句來查詢出當前執行的會話
select p.spid,t.text from sys.sysprocesses p CROSS APPLY sys.dm_exec_sql_text( p.sql_handle ) t where p.spid in (250,356,472)
3、返回正在執行並且做過空間申請的session正在執行的語句
SELECT t1.session_id , st.text , GETDATE()
FROM sys.dm_db_session_space_usage AS t1 ,
sys.dm_exec_requests AS t4
CROSS APPLY sys.dm_exec_sql_text(t4.sql_handle) AS st
WHERE t1.session_id = t4.session_id
AND t1.session_id > 50
AND (
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
)
4、返回正在執行的活動的空間使用情況以及語句內容和執行計劃
WITH task_space_usage AS (
-- SUM alloc/delloc pages
SELECT session_id,
request_id,
SUM(internal_objects_alloc_page_count) AS alloc_pages,
SUM(internal_objects_dealloc_page_count) AS dealloc_pages
FROM sys.dm_db_task_space_usage WITH (NOLOCK)
WHERE session_id <> @@SPID
GROUP BY session_id, request_id
)
SELECT TSU.session_id,
TSU.alloc_pages * 1.0 / 128 AS [internal object MB space],
TSU.dealloc_pages * 1.0 / 128 AS [internal object dealloc MB space],
EST.text,
-- Extract statement from sql text
ISNULL(
NULLIF(
SUBSTRING(
EST.text,
ERQ.statement_start_offset / 2,
CASE WHEN ERQ.statement_end_offset < ERQ.statement_start_offset THEN 0 ELSE( ERQ.statement_end_offset - ERQ.statement_start_offset ) / 2 END
), ''
), EST.text
) AS [statement text],
EQP.query_plan
FROM task_space_usage AS TSU
INNER JOIN sys.dm_exec_requests ERQ WITH (NOLOCK)
ON TSU.session_id = ERQ.session_id
AND TSU.request_id = ERQ.request_id
OUTER APPLY sys.dm_exec_sql_text(ERQ.sql_handle) AS EST
OUTER APPLY sys.dm_exec_query_plan(ERQ.plan_handle) AS EQP
WHERE EST.text IS NOT NULL OR EQP.query_plan IS NOT NULL
ORDER BY 3 DESC, 5 DESC
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29371470/viewspace-2018452/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- sql-server檢視SQLServer
- Sql Server系列:檢視SQLServer
- oracle-一些檢視效能相關的檢視Oracle
- oracle Metrics相關檢視Oracle
- 檢視SQL SERVER表的空間使用情況SQLServer
- Sql Server關於indexed view索引檢視的總結SQLServerIndexView索引
- Dataguard (Standby) 相關的檢視(View)View
- 檢視oracle鎖相關資訊Oracle
- SQL SERVER檢視列的預設值SQLServer
- 檢視Sql Server的log檔案大小SQLServer
- 檢視SQL SERVER表的空間使用情況(續)SQLServer
- sql server檢視函式定義SQLServer函式
- 檢視SQL Server 效能優化工具SQLServer優化
- 檢視SQL PROFILE使用的HINTSQL
- SQL檢視SQL
- RMAN相關的動態效能檢視
- 查詢基表的相關檢視
- 19 Oracle Data Guard 相關檢視Oracle
- Oracle相關資料字典檢視Oracle
- 物化檢視相關工具包
- linux檢視cpu相關資訊Linux
- oracle許可權相關檢視Oracle
- 批量更新SQL Server資料庫的使用者檢視SQLServer資料庫
- 在pl/SQL中呼叫logminer相關檢視的問題SQL
- sql server如何檢視欄位註釋?SQLServer
- SQL Server 檢視資料庫日誌SQLServer資料庫
- 檢視Undo使用情況的SQLSQL
- 【ORACLE】物化檢視相關後設資料檢視欄位說明Oracle
- Data Guard相關的動態效能檢視
- 使用V$SQL_PLAN檢視SQL
- v$sql檢視和v$sqlarea檢視的構建SQL
- 在SQL Server tempdb滿時檢查資料檔案SQLServer
- 深刻的教訓——SQL Server關於TempDB的使用SQLServer
- Linux檢視相關係統資訊Linux
- Sql Server 獲取指定表、檢視結構SQLServer
- SQL Server 檢視錶佔用空間大小SQLServer
- MySQL Profile檢視SQL的資源使用MySql
- 檢視包正在被哪個程式使用,檢視包含SQL語句的PACKAGESQLPackage