Welcome To DBA Share

Unable to Shrink Tempdb database files in SQL server

0 comments

The Tempdb ! Yes temporary database in SQL server is most important database. This is the temporary work space for all users as well as system too. Some times we will get an error in sql server error log that your tempdb database got filled. In such case we need to shrink tempdb log file as well as data file. However, if you try to shrink tempdb database using commands or wizard base you may not shrunk tempdb. Here is the solution for clearing tempdb database in sql server.

Method1
USE TempDB
GO
--Use below query for clearing plan cache in the server.
DBCC FREEPROCCACHE
go
--Use below query for clearing buffers from bufferpool.
DBCC DROPCLEANBUFFERS
go

-- Use below query, this will Releases all unused cache entries from all caches.
DBCC FREESYSTEMCACHE ('ALL')
go

Method2
sp_helpfile
go 
You will get logical name as well as file id. use this logical name or file id in the below query.

dbcc shrinkfile(1.10) --> This will shrink Tempdb database Datafile. (1=fileid, 10=expected tempfile size)
dbcc shrinkfile(2,10) --> This will shrink Tempdb database Logfile. (2=fileid, 10=expected tempfile size)

Method3
sp_helpfile
go 
You will get logical name. use this logical name in the below query.
Alter database tempdb modify file (name= 'tempdev', SIZE = 10)
Alter database tempdb modify file (name= 'templog', SIZE = 10)
Above query will shrink tempdb database to 10 mb.

Please make sure we need to restart sql services after using this query.
Share this article :

Post a Comment

 
Support : 2005 | 2008 | 2008R2 | 2012 | 2014 | SQL Server DBA
Copyright © 2013. DBA Share - All Rights Reserved
Template Created by Creating Website Modify by CaraGampang.Com
Proudly powered by Blogger