Sqlserver-dba.com

Shrink tempdb without sql server restart

 Despite best efforts to size a tempdb , on occasions the tempdb expands to a size as big as the drive. Because the drive is full the tempdb can no longer expand. This triggers a situation in a monitoring framework. A quick solution is required, to shrink down the tempdb . Following are 2 different methods I use , that don’t require a SQL Server restart.

 If I receive consistency errors , than I resort to a SQL Server restart , depending on the situation

 DBCC DHRINKFILE will allow you to decrease to a size smaller than the original size

 Method 1: DBCC SHRINKFILE

 Use tempdb

GO

--shrink the main data file

DBCC shrinkfile (tempdev,’<enter_target_size_in_MB’>)

GO

--shrink the main log file

DBCC shrinkfile (templog, ’<enter_target_size_in_MB’>)

 

e.g DBCC shrinkfile (tempdev, 5000)

 

 Method 2:DBCC SHRINKDATABASE

 DBCC SHRINKDATABASE(tempdb,’<enter_target_percent>’)

 e.g DBCC SHRINKDATABASE(tempdb,20)

 

 

 

Ref:Jack Vamvas (http://www.sqlserver-dba.com)

 


Author: Jack Vamvas (http://www.sqlserver-dba.com)

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact