简体   繁体   中英

SQL Server 2005 - how to shrink the tempdb

My tempdb size is growing too much, as we are doing too many transactions in the database. Can someone let me know how to shrink this tempdb without restarting the server. I have tried DBCC SHRINKDATABASE and it didn't help

Thanks in advance

Your tempdb is the size it needs to be...

It will just grow again, just even more fragmented on disk and possibly blocking while it grows too.

More seriously, I'd set the size of tempdb to soemthing sensible and slightly larger than now, shut down SQL, delete the old files to be 110% sure, start SQL Server up again...

I have found shrinking the tempdb to often be a troublesome task.

The solution I have used previously is to set the initial size of the tempdb database to be the actual desired size of the database. Restarting the SQL Server Service will then re-create the tempdb database to this sepcified size.

You may also find the following Microsoft reference to be useful reading:

http://support.microsoft.com/kb/307487/en-gb

Shrink the data files. From tempdb:

dbcc shrinkfile ('tempdev')

dbcc shrinkfile ('templog')

If you have other data files for tempdb you may need to shrink them also. You can see this from the system data dictionary. Look in the 'name' column.

select * from sys.database_files

Even with "DBCC SHRINKFILE" you can receive warning like "DBCC SHRINKFILE: Page 1:878039 could not be moved because it is a work file page." that lead to no shrinking.

I found a blog that explain well that situation and tell how to workaround and how to successfully shrink tempdb without restarting SQL: http://adventuresinsql.com/2009/12/how-to-shrink-tempdb-in-sql-2005/

So here is an exemple from that blog:

DBCC FREEPROCCACHE
GO
USE [tempdb]
GO
DBCC SHRINKFILE (N'tempdev')
GO
DBCC SHRINKDATABASE(N'tempdb')
GO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM