简体   繁体   English

SQL Server 2005-如何缩小tempdb

[英]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. 我的tempdb大小增长太多,因为我们在数据库中执行了太多事务。 Can someone let me know how to shrink this tempdb without restarting the server. 有人可以让我知道如何在不重新启动服务器的情况下缩小此tempdb。 I have tried DBCC SHRINKDATABASE and it didn't help 我尝试了DBCC SHRINKDATABASE,但没有帮助

Thanks in advance 提前致谢

Your tempdb is the size it needs to be... 您的tempdb大小应为...

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... 更严重的是,我将tempdb的大小设置为合理,并且比现在稍大一些,关闭SQL,以确保110%删除旧文件,然后再次启动SQL Server ...

I have found shrinking the tempdb to often be a troublesome task. 我发现缩小tempdb通常是一项麻烦的任务。

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. 我以前使用的解决方案是将tempdb数据库的初始大小设置为数据库的实际所需大小。 Restarting the SQL Server Service will then re-create the tempdb database to this sepcified size. 然后,重新启动SQL Server服务将重新创建tempdb数据库,使其达到此分隔大小。

You may also find the following Microsoft reference to be useful reading: 您可能还会发现以下Microsoft参考对于阅读很有帮助:

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

Shrink the data files. 收缩数据文件。 From tempdb: 从tempdb:

dbcc shrinkfile ('tempdev')

dbcc shrinkfile ('templog')

If you have other data files for tempdb you may need to shrink them also. 如果您有tempdb的其他数据文件,则可能还需要缩小它们。 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." 即使使用“ DBCC SHRINKFILE”,您也会收到类似“ DBCC SHRINKFILE:页面1:878039不能移动,因为它是工作文件页面”的警告。 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/ 我找到了一个博客,该博客很好地解释了这种情况,并介绍了解决方法以及如何在不重新启动SQL的情况下成功缩小tempdb的方法: 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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