Follow sqlserver-dba.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

SQLServer-DBA.com Links

Dba_db2_button

dba-ninja.com

SQL Server DBA Jobs

List current SQL Server tempdb statements

26 November,2012 by Tom Collins

Do you know what statements are currently running on the SQL Server tempdb database? Can you tell which statements are creating insufficient disk space in the tempdb?

Use this statement to list the current tempdb statements. It is very useful for troubleshooting tempdb disk usage and which queries are creating resource contention on SQL Server tempdb.

 Maintaining SQL Server tempdb performance is critical for overall performance. Tempdb has many uses – such as Version Stores, Internal objects (join work files) and User objects (tables,indices). Read more on TempDB performance and strategy checklist

The statement uses the DMV:

sys.dm_db_session_space_usage - Returns the number of pages allocated and deallocated by each session for the database

sys.dm_exec_requests - Returns information about each request that is executing within SQL Server.SQL Server – Current queries executing on SQL Server

sys.dm_exec_sql_text - Returns the text of the SQL batch that is identified by the specified sql_handle

sys.dm_db_task_space_usage - Returns page allocation and deallocation activity by task for the database

 

SELECT ssu.session_id, 
(ssu.internal_objects_alloc_page_count + sess_alloc) as allocated, 
(ssu.internal_objects_dealloc_page_count + sess_dealloc) as deallocated 
 , stm.TEXT
from sys.dm_db_session_space_usage as ssu,  
        sys.dm_exec_requests req
        CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS stm ,
(select session_id,  
   sum(internal_objects_alloc_page_count) as sess_alloc, 
   sum (internal_objects_dealloc_page_count) as sess_dealloc 
   from sys.dm_db_task_space_usage group by session_id) as tsk 
where ssu.session_id = tsk.session_id 
and ssu.session_id >50 
and ssu.session_id = req.session_id 
and ssu.database_id = 2 
order by allocated DESC

Read More

SQL Server - Shrink tempdb without sql server restart - SQL Server ...

SQL Server – tempdb and solid state drives - SQL Server DBA

TempDB performance and strategy checklist - SQL Server DBA

How to fix : Operarator used tempdb to spill data during execution warning


Author: Tom Collins (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on List current SQL Server tempdb statements


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer