Shrinking Temp DB

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.
Appaji PatilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
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..
Appaji PatilAuthor Commented:
Its been  from Long time I am getting this msg.
Is there any alternative way other Restart of SQL services
Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
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..
	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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
Initiating auto close as we haven't heard back from Author and solution was proposed..
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.