Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 7

Tempdb space usage

My Tempdb is filling up fast How can I use DPA to identify the spid using most tempdb space?

Tags (2)
0 Kudos
1 Reply
Level 14

Here is one way:

Step 1: Set up an alert for tempdb filling up.

Grab the script you feel most comfortable with to check tempdb used space (or free space if you like to look at it from that perspective). There are a lot out there and some are % based, some are byte based, so don't want to assume anything here.

If you get an alert from DPA that TempDB is filling past a threshold you define, then move to step 2.

Step 2: Query against the instance alerting the following to get the data you are looking for.

SELECT SU.session_id,
(SU.internal_objects_alloc_page_count) as session_internal_alloc,
(SU.internal_objects_dealloc_page_count) as sesion_internal_dealloc,
(SU.user_objects_alloc_page_count) as session_user_alloc,
(SU.user_objects_dealloc_page_count) as sesion_user_dealloc,
(TS.internal_objects_alloc_page_count) as task_internal_alloc ,
(TS.internal_objects_dealloc_page_count) as task_internal_dealloc,
(TS.user_objects_alloc_page_count) as task_user_alloc ,
(TS.user_objects_dealloc_page_count) as task_user_dealloc
FROM sys.dm_db_session_space_usage SU
inner join sys.dm_db_task_space_usage TS
on SU.session_id = TS.session_id
where SU.session_id > 50  
GROUP BY SU.session_id;

-- You could also add an order by clause desc so that you rank them by most used to least by spid.

0 Kudos