DBCC SHRINKDATABASE xxxx was skipped because the file does not have enough free
2016-08-16 17:57
393 查看
假设你创建一个数据库时,指定其初始化大小(SIZE)非常大。例如,如下测试案例所示
此时我们检查数据库的空间使用情况如下所示:
然后你使用DBCCSHRINKDATABASE去收缩数据库时,就会遇到“DBCCSHRINKDATABASE:xxxwasskippedbecausethefiledoesnothaveenoughfreespacetoreclaim”这样的错误。
DBCCSHRINKDATABASE:FileID1ofdatabaseID8wasskippedbecausethefiledoesnothaveenoughfreespacetoreclaim.
DBCCSHRINKDATABASE:FileID2ofdatabaseID8wasskippedbecausethefiledoesnothaveenoughfreespacetoreclaim.
DBCCexecutioncompleted.IfDBCCprintederrormessages,contactyoursystemadministrator.
是不是有点纳闷,明明数据库有大量空闲空间,但是提示“DBCCSHRINKDATABASE:FileID1ofdatabaseID8wasskippedbecausethefiledoesnothaveenoughfreespacetoreclaim"没有足够剩余空间回收。我们先用DBCCSHRINKFILE将数据库的数据文件收缩一下,如下所示
如上所示,DBCCSHRINKFILE可以收缩数据库文件,但是DBCCSHRINKDATABASE为什么不行呢?
DBCCSHRINKDATABASE(database_name|database_id|0[,target_percent][,{NOTRUNCATE|TRUNCATEONLY}])[WITHNO_INFOMSGS]
这个是因为DBCCSHRINKDATABASE是数据文件/日志对象的百分比来收缩数据库,并且这个收缩后的值不能小于数据文件/日志文件的最小大小(minimumfilesize).但是DBCCSHRINKFILE收缩时,可以小于数据文件/日志文件的minimumfilesize。官方文档介绍如下:
收缩后的数据库不能小于数据库的最小大小。最小大小是在数据库最初创建时指定的大小,或是使用文件大小更改操作(如DBCCSHRINKFILE或ALTERDATABASE)显式设置的最后大小。例如,如果数据库最初创建时的大小为10MB,后来增长到100MB,则该数据库最小只能收缩到10MB,即使已经删除数据库的所有数据也是如此。
所以上面DBCCSHRINKDATABASE命令不能收缩数据库,因为上图的MimimumSize和CurrentSize大小相同。而使用DBCCSHRINKFILE可以收缩数据库文件.
参考资料:
https://msdn.microsoft.com/zh-cn/library/ms190488.aspx
https://blogs.msdn.microsoft.com/psssql/2008/03/24/how-it-works-dbcc-shrinkdatabase-shrinkfile-tabular/
USE[master]
GO
CREATEDATABASE[TEST]ONPRIMARY
(NAME=N'TEST_Data',FILENAME=N'D:\SQL_DATA\TEST_Data.mdf',SIZE=11527027KB,MAXSIZE=UNLIMITED,FILEGROWTH=102400KB)
LOGON
(NAME=N'TEST_log',FILENAME=N'D:\SQL_LOG\TEST_log.ldf',SIZE=40350KB,MAXSIZE=2048GB,FILEGROWTH=32768KB)
GO
此时我们检查数据库的空间使用情况如下所示:
USETEST;
GO
EXECSP_SPACEUSED;
然后你使用DBCCSHRINKDATABASE去收缩数据库时,就会遇到“DBCCSHRINKDATABASE:xxxwasskippedbecausethefiledoesnothaveenoughfreespacetoreclaim”这样的错误。
USETEST;
GO
DBCCSHRINKDATABASE('TEST',5);
DBCCSHRINKDATABASE:FileID1ofdatabaseID8wasskippedbecausethefiledoesnothaveenoughfreespacetoreclaim.
DBCCSHRINKDATABASE:FileID2ofdatabaseID8wasskippedbecausethefiledoesnothaveenoughfreespacetoreclaim.
DBCCexecutioncompleted.IfDBCCprintederrormessages,contactyoursystemadministrator.
是不是有点纳闷,明明数据库有大量空闲空间,但是提示“DBCCSHRINKDATABASE:FileID1ofdatabaseID8wasskippedbecausethefiledoesnothaveenoughfreespacetoreclaim"没有足够剩余空间回收。我们先用DBCCSHRINKFILE将数据库的数据文件收缩一下,如下所示
USETEST;
GO
DBCCSHRINKFILE('TEST_Data',20);
如上所示,DBCCSHRINKFILE可以收缩数据库文件,但是DBCCSHRINKDATABASE为什么不行呢?
DBCCSHRINKDATABASE(database_name|database_id|0[,target_percent][,{NOTRUNCATE|TRUNCATEONLY}])[WITHNO_INFOMSGS]
这个是因为DBCCSHRINKDATABASE是数据文件/日志对象的百分比来收缩数据库,并且这个收缩后的值不能小于数据文件/日志文件的最小大小(minimumfilesize).但是DBCCSHRINKFILE收缩时,可以小于数据文件/日志文件的minimumfilesize。官方文档介绍如下:
收缩后的数据库不能小于数据库的最小大小。最小大小是在数据库最初创建时指定的大小,或是使用文件大小更改操作(如DBCCSHRINKFILE或ALTERDATABASE)显式设置的最后大小。例如,如果数据库最初创建时的大小为10MB,后来增长到100MB,则该数据库最小只能收缩到10MB,即使已经删除数据库的所有数据也是如此。
所以上面DBCCSHRINKDATABASE命令不能收缩数据库,因为上图的MimimumSize和CurrentSize大小相同。而使用DBCCSHRINKFILE可以收缩数据库文件.
参考资料:
相关文章推荐
- Cannot execute as the database principal because the principal "guest" does not exist, this type of principal cannot be impersonated, or you do not have permission.
- the message "\$CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop
- 启动tomcat 服务报 The file is absent or does not have execute permission
- Xcode运行报错 The file “xxxx.app” couldn’t be opened because you don’t have permission to view it
- 奇葩问题:This file could not be checked in because the original version of the file on the server was moved or deleted. A new version of this file has been saved to the server, but your check-in comments were not saved
- cannot be resolved to absolute file path because it does not reside in the file system
- Online Music Store: EF 4 Code Only方式出错"Model compatibility cannot be checked because the database does not contain"
- Cannot find bin/catalina.sh The file is absent or does not have execute permission
- Sql 2005 Database diagram support objects cannot be installed because this database does not have a valid owner
- Database diagram support objects cannot be installed because this database does not have a valid owner.
- 启动tomcat 服务报 The file is absent or does not have execute permission
- Some text formatting may have changed in this file because the maximum number of fonts was exceeded解决办法
- Caller does not have enough privilege to set CallerOriginToken to the specified value
- CRM安装问题一:Caller does not have enough privilege to set CallerOriginToken to the specified value
- pid.txt CATALINA_PID was set but the specified file does not exit
- SQL Server 对等复制配置失败后无法删除重建,报错:Cannot execute as the database principal because the principal "dbo" does not exist, this type of principal cannot be im
- 解决Entity Framework Code First 的问题——Model compatibility cannot be checked because the database does not contain model metadata
- TFS2010提示:TF204017 The operation cannot be completed because the user does not have one or more required permissions (Use) for workspace
- Linux下启动启动tomcat 服务器报错 The file is absent or does not have execute permission
- Could not allocate space for object in database because the filegroup is full