DAGDA SEARCH | Back to results | Support

Script to shrink Tempdb data files and Virtual Logs · GitHub

Source: https://gist.github.com/DataSlugger/11ccf089c6ee2efcfda4a7dbe19f6fde

Instantly share code, notes, and snippets.

@DataSlugger

DataSlugger/ReduceTempdbSizeandVFL.sql

Created May 16, 2020 23:40 Show Gist options

Select an option

No results found

Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/DataSlugger/11ccf089c6ee2efcfda4a7dbe19f6fde.js"></script> Save DataSlugger/11ccf089c6ee2efcfda4a7dbe19f6fde to your computer and use it in GitHub Desktop. Download ZIP Script to shrink Tempdb data files and Virtual Logs Raw ReduceTempdbSizeandVFL.sql This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters
/*Get spaceused*/
sp_spaceused @updateusage=true
/*Check # of Virtual Log Files - VFL*/
dbcc loginfo
/*
DBCC DROPCLEANBUFFERS
Clears the clean buffers. This will flush cached indexes and data pages. You may want to run a CHECKPOINT command first, in order to flush everything to disk.*/
CHECKPOINT;
GO
DBCC DROPCLEANBUFFERS;
GO
/*ONLY IF IS NECESSARY, THIS COMMAND AFFECT PROCEDURE AND MAY NEED TO RECOMPILE AGAIN AND CAN IMPACT PERFORMANCE*/
DBCC FREEPROCCACHE
/*DBCC FREESYSTEMCACHE
This operation is similar to FREEPROCCACHE, except it affects other types of caches.*/
DBCC FREESYSTEMCACHE ('ALL');
GO
/*FINALLY*/
DBCC SHRINKFILE (N'templog', NOTRUNCATE) -- Move allocated pages from end of file to top of file
GO
DBCC SHRINKFILE (N'templog' , 0, TRUNCATEONLY) -- Drop unallocated pages from end of file
GO
DBCC SHRINKFILE (N'templog', 20480) --Return Tempdb logfile to initial size
go
DBCC SHRINKFILE(N'templog', EMPTYFILE)
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment