收缩临时库 shrink tempdb

时间:2022-06-21 16:34:03

tempdb实际占用空间40mb,文件大小70G, 原始大小2GB

无法使用dbcc shrinkfile进行收缩.

 

看到的解决方案是

  1. 重启数据库
  2. DBCC FREESYSTEMCACHE ('ALL') ,然后再收缩.

http://social.msdn.microsoft.com/Forums/en/sqldatabaseengine/thread/7b45f0de-2aa3-4de0-930b-d9d0fe931b3a

http://support.microsoft.com/kb/328551/en-us

http://blogs.msdn.com/b/sqlserverstorageengine/archive/2008/12/22/tempdb-basics-cont.aspx

 

从sqlserver 2005起,会缓存一些临时表的iam页,导致这些被缓存的页没有办法被回收...

 Improved caching for temporary objects. SQL Server caches 1 IAM page and 1 data page with the associated query plan. The benefit of this is significant. First, if the same plan is executed multiple times, the temporary table needs to be created once there by reducing DDL contention. Imagine if a temporary table with say 5 columns gets created/destroyed every time, SQL Server will need to insert one row system table for ‘tables’ and 5 rows for columns in ‘columns’ and then remove these entries when table is removed. Second, it reduces allocation overhead. Let me illustrate this with the following example