Shrinking Tempdb in SQL Server won’t work?

Problem statement

When I was working DML operation on the database, It is noted that the tempdb has grown significantly larger and I didn’t have much space on the drive of that server. I tried shrinking the mdf file of tempdb. It executes successfully but no space is released to OS. Is restarting the SQL Server is the only way to release the space. what are other steps available to troubleshoot this issue? Is there any way I can do it without restarting the SQL service?.

Let’s explore the options.

Here are quick steps to analyze the tempdb resource contention issue.

DBCC SHRINKFILE (‘tempdev’, 1024)

The query executed successfully but the size of the database did not change.

SELECT * FROM sys.dm_exec_requests WHERE database_id = 2

No open transactions! Alright, any process holding locks on tempdb?

select * from sys.dm_tran_locks where resource_database_id= 2

No locks! There was a mention of sys.dm_db_session_space_usage DMV which helps to track the number of page allocation and deallocation by each session on the instance. Hence tried my luck with this query.

select * from sys.dm_db_session_space_usage where user_objects_alloc_page_count<> 0

Any session would use tempdb for creating some temporary objects. Since the database was not shrinking, obviously some user-defined tables would be there

SELECT * FROM tempdb..sys.all_objectswhere is_ms_shipped = 0

Check for user tables on tempdb

After performing all the above steps, Space is big constraint than execute the below command to free up the cache.

Note: It is not a recommended step. 

DBCC FREEPROCCACHE

This should free up tempdb

7)DBCC SHRINKFILE (‘tempdev’, 1024)

If this doesn’t help then the last step would restart the sql server.

Advertisements

About Prashanth Jayaram

DB Technologist, Author, Blogger, Service Delivery Manager at CTS, Automation Expert, Technet WIKI Ninja, MVB and Powershell Geek My Profile: https://social.technet.microsoft.com/profile/prashanth jayaram/ http://www.sqlshack.com/author/prashanth/ http://codingsight.com/author/prashanthjayaram/ https://www.red-gate.com/simple-talk/author/prashanthjayaram/ http://www.sqlservercentral.com/blogs/powersql-by-prashanth-jayaram/ Connect Me: Twitter @prashantjayaram GMAIL powershellsql@gmail.com The articles are published in: http://www.ssas-info.com/analysis-services-articles/ http://db-pub.com/ http://www.sswug.org/sswugresearch/community/
This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s