Script to shrink tempdb

Script to shrink tempdb

shrinkIn general shrinking a database is easy. This operation is done when an administrator wants to make database files smaller. It can be even done with SQL Server Management Studio. It becomes a little more complex when the database is tempdb. It is a system database that stores different types of temporary objects. As a consequence, it cannot be easily shrinked to reduce occupied disk space. This post contains a script that allows for that.

 

 

USE [TEMPDB];
GO
CHECKPOINT
; GO DBCC DROPCLEANBUFFERS; GO DBCC FREEPROCCACHE; GO DBCC FREESYSTEMCACHE ('ALL'); GO DBCC FREESESSIONCACHE; GO DBCC SHRINKFILE (TEMPDEV, 1024); GO

It shrinks tempdb data file to 1024 MB.

We use cookies

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.