Shrinking Temp DB

Appaji Patil
Appaji Patil used Ask the Experts™
on
When trying to Shrink TempDB on one of the Production DB server getting below error msg.

Could not cleanup worktable IAM chains to allow shrink or remove file operation. Please try again when tempdb is idle.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Raja Jegan RSQL Server DBA & Architect, EE Solution Guide
Awarded 2009
Distinguished Expert 2018

Commented:
As mentioned in the error message, some Index Allocation Map(IAM) process is using your tempdb pages which SQL Server can't move as part of your tempdb Shrink file request. So, you have 2 options, either to wait for those process to complete and perform Shrink tempdb during idle hours as suggested above or Restart SQL Server service to get the file size shrunk out..

Author

Commented:
Its been  from Long time I am getting this msg.
Is there any alternative way other Restart of SQL services
SQL Server DBA & Architect, EE Solution Guide
Awarded 2009
Distinguished Expert 2018
Commented:
Unless you identify the long running query and clear all those sessions, you need to wait till it finishes.
Script to find out Long running queries..
SELECT TOP 20 t.TEXT Query,
	s.execution_count AS ExecutionCount,
	s.max_elapsed_time AS MaxElapsedTime,
	ISNULL(s.total_elapsed_time / s.execution_count, 0) AS AvgElapsedTime,
	s.creation_time AS LogCreatedOn,
	ISNULL(s.execution_count / DATEDIFF(s, s.creation_time, GETDATE()), 0) AS FrequencyPerSec
FROM sys.dm_exec_query_stats s
CROSS APPLY sys.dm_exec_sql_text( s.sql_handle ) t
ORDER BY s.max_elapsed_time DESC

Open in new window

another set of scripts.
SELECT spid, login_time, last_batch, cpu, physical_io, memusage 
FROM sys.sysprocesses
where spid > 49
order by login_time

Open in new window

Raja Jegan RSQL Server DBA & Architect, EE Solution Guide
Awarded 2009
Distinguished Expert 2018

Commented:
Initiating auto close as we haven't heard back from Author and solution was proposed..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial