简体   繁体   English

SQL Server 数据库不会收缩

[英]SQL Server database won't shrink

I have a 31 GB database I got from a customer for a project.我有一个 31 GB 的数据库,我从客户那里获得了一个项目。 I'm coding and keeping the database in a 80GB Win7 VM.我正在编写代码并将数据库保存在 80GB 的 Win7 VM 中。 I got the db file and imported the database from that, and found that the space was being eaten up mostly by one table, with 240,000 images.我得到了 db 文件并从中导入了数据库,发现空间大部分被一张桌子吃掉了,有 240,000 张图像。 I dropped most of those rows and now have 29,000MB available.我删除了其中的大部分行,现在有 29,000MB 可用。 I can't perform lots of functions because the drive is down to it's last few GB, and there are still a lot of records to modify (I'm changing a data type in several tables, but keep getting a active_transaction error).我无法执行很多功能,因为驱动器已降至最后几 GB,而且仍有大量记录需要修改(我正在更改多个表中的数据类型,但不断收到 active_transaction 错误)。 It's not shrinking via DBCC_SHRINKDATABASE(0) or Tasks > Shrink > Database or Files.它不会通过DBCC_SHRINKDATABASE(0)Tasks > Shrink > Database或文件进行Tasks > Shrink > Database It only shrinks to the size of the database when I first got it, it seems.当我第一次得到它时,它似乎只会缩小到数据库的大小。 How do I get it to release that space?我如何让它释放那个空间? If I can', can I export what data is still there to a smaller database, and then restore from that?如果可以,我可以将仍然存在的数据导出到较小的数据库,然后从中恢复吗?

Running SQL Server 2012 and Management Studio.运行 SQL Server 2012 和 Management Studio。

Thanks,谢谢,

Tony托尼

You cannot dbcc shrinkdatabase below the initial size setting.您不能将dbcc shrinkdatabase低于初始大小设置。 If the initial size of your database is set to 50GB -- the MDF will always be at least 50GB, even if 29GB is free/available.如果您的数据库的初始大小设置为 50GB——MDF 将始终至少为 50GB,即使 29GB 是免费/可用的。

If you do in fact have free space, you can lower the initial size setting to a more reasonable value - but if the MDF will simply auto-grow again, this is not advised, as it incurs a high overhead.如果您确实有可用空间,则可以将初始大小设置降低到更合理的值 - 但如果 MDF 将再次自动增长,则不建议这样做,因为它会导致高开销。

To do this you would use dbcc shrinkfile .为此,您将使用dbcc shrinkfile

Please see here for more information.请参阅此处了解更多信息。

This page describes how to make SQL server backups.本页介绍如何进行 SQL 服务器备份。 https://msdn.microsoft.com/en-us/library/ms186865(v=sql.110).aspx https://msdn.microsoft.com/en-us/library/ms186865(v=sql.110).aspx

If you haven't done so already, you will need to take a full backup before you can do a transaction log backup.如果您还没有这样做,则需要先进行完整备份,然后才能进行事务日志备份。

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

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