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關於indexed view索引檢視的總結SQLServerIndexView索引
- SQL Server 檢視錶佔用空間大小SQLServer
- Oracle相關資料字典檢視Oracle
- 19 Oracle Data Guard 相關檢視Oracle
- SQL Server檢視所有表大小,所佔空間SQLServer
- Linux檢視相關係統資訊Linux
- DBA_HIST相關檢視說明
- HGDB的分割槽表實現SQL Server的分割槽檢視SQLServer
- 檢視SQL Server資料庫修改了哪些內容SQLServer資料庫
- Linux檔案內容檢視相關命令Linux
- SQL Server建立使用者只能訪問指定資料庫和檢視SQLServer資料庫
- odoo檢視入門學習- tree檢視的使用Odoo
- mysql鎖分析相關的幾個系統檢視MySql
- 11 UML中的邏輯檢視、程序檢視、實現檢視、部署檢視
- 如何使用SQL查詢檢視,Postico使用技巧分享~SQL
- Linux根據程式號,檢視相關資訊Linux
- [20241021]使用gdb檢視修改記憶體地址以及相關值.txt記憶體
- 檢視sqlserver的某程式的sql文字SQLServer
- 如何SQL Server中檢視對映網路驅動器NASQLServer
- Oracle檢視歷史TOP SQLOracleSQL
- 控制檯實時檢視 sqlSQL
- SAP PM IW33裡檢視維護訂單相關的檢驗批
- ASP.NET Core 5.0 MVC中的檢視分類——佈局檢視、啟動檢視、具體檢視、分部檢視ASP.NETMVC
- [Django REST framework - 檢視元件之檢視基類、檢視擴充套件類、檢視子類、檢視集]DjangoRESTFramework元件套件
- 【AWR】Oracle awr相關檢視及體系介紹Oracle
- 檢視錶和索引碎片情況相關資訊索引
- 如何檢視SQL的執行計劃SQL
- Audio Kit 檢視檔案波形的相關原始碼,easy o原始碼
- 關於開發檢視
- dwg檢視器使用技巧(方便好用的dwg檢視器推薦 )
- 選擇使用通用檢視(Generic Views)或檢視集(ViewSets)View
- sql大資料 基礎(檢視)SQL大資料
- linux:檢視使用中的埠Linux
- docker 容器的使用與檢視Docker
- 資料庫檢視的使用資料庫
- 使用Excel的2個檢視Excel
- SQL Server資料庫檢視一個資料表各列的註釋SQLServer資料庫
- 檢視oracle資料庫的連線數以及使用者檢視Oracle資料庫