A very big size of tempdb

Akino picture Akino · Jan 4, 2018 · Viewed 11.2k times · Source

I have a spring project, when I start the server a named file 'tempdb' is created in the sql server directory, the size of this file is too big (reaches 8G) I like to know why this file is created? is there a way to reduce its size? Thanks in advance

Answer

matson kepson picture matson kepson · Nov 20, 2018

run this

-- use the proper DB
USE tempdb;
GO
-- sync
CHECKPOINT; 
GO
-- drop buffers
DBCC DROPCLEANBUFFERS; 
DBCC FREEPROCCACHE;
DBCC FREESYSTEMCACHE('ALL');
DBCC FREESESSIONCACHE;
GO
--shrink db (file_name, size_in_MB)
DBCC SHRINKFILE (TEMPDEV, 1024);
GO

Either, you can always restart whole Database (like service restart), it will also drop the tempdb.