Wednesday, June 17, 2015

Clear Temp DB without restart

Doesn't always work but sometimes magic happens. This is essentially other peoples work put here so I remember.


use tempdb
GO

DBCC FREEPROCCACHE -- clean cache
DBCC DROPCLEANBUFFERS -- clean buffers
DBCC FREESYSTEMCACHE ('ALL') -- clean system cache
DBCC FREESESSIONCACHE -- clean session cache
DBCC SHRINKDATABASE(tempdb, 20); -- shrink tempdb
DBCC shrinkfile ('tempdev') -- shrink db file
DBCC shrinkfile ('templog') -- shrink log file
GO

-- report the new file sizes
SELECT name, size
FROM sys.master_files
WHERE database_id = DB_ID(N'tempdb');
GO

No comments: