Link to home
Start Free TrialLog in
Avatar of Jim Youmans
Jim YoumansFlag for United States of America

asked on

TempDB won't shrink on SQL Server 2014

I was helping a friend with a TempDB problem.  He is running SQL Server 2014 on Azure VM and it is part of an always on group.  The problem is that TempDB grew to fill up the drive and when we tried to shrink it, nothing worked.  We did the DBCC FREESYSTEMCACHE('ALL')  and shrink. We did alter TempDB size.  We did everything we could think of and nothing worked.  We finally failed the database over to secondary server and stopped and restarted the SQL instance to reset TempDB on the primary server.  That worked.

Has anyone come across a problem like this and if so how did you handle it?

Thanks!
Jim
Avatar of lcohan
lcohan
Flag of Canada image

As far as I'm aware you will need to restart that SQL Server Service as tempdb gets recreated on every SQL restart and as far as I'm aware that's the best way to do it.
I have created a maintenance plan to shrink the database, also sql code after to change the log database mode to Simple Recovery, shrink and then set it back to full recovery. Every evening the maintenance plan runs and I have had no issues so far.
Well if nothing works as already tried above the SQL restart would do that but maybe try the DBCC FREEPROCCACHE first and see if that helps but if that doesnt...maybe only restart would help.
https://support.microsoft.com/en-us/topic/how-to-shrink-the-tempdb-database-in-sql-server-ea0a95c2-eff8-7075-9ee2-2ee42226ca1c
https://www.brentozar.com/archive/2016/02/when-shrinking-tempdb-just-wont-shrink/

Avatar of Jim Youmans

ASKER

We tried all of that and nothing worked except the restart.  Just want to make sure I did not overlook something obvious.

Thanks!  
ASKER CERTIFIED SOLUTION
Avatar of lcohan
lcohan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When there are active transactions, then you cannot resize it.

Imho you should set a meaningful max size and restart the instance.

But keep in mind, this size can be an indicator for a huge workload. So you should examine whether this is from a single event or whether your workloads have increased over time. In the latter case you need more disk space.
And that is what I told my friend.  There must have been an open transaction using TempDB.  That is the only thing I can think of.

Thank you everyone!!!!
dbcc opentran; 
DBCC INPUTBUFFER;
--and then 
sp_who2 spid#

Open in new window

should help you identify the offender and eventually kill that SPID only assuming that can be safely done without causing any data issues.