简体   繁体   English

如果我收缩它,数据库(SQL Server 2005)的性能是否会降低?

[英]Does performance of a database (SQL Server 2005) decrease if I shrink it?

Does performance of a database (SQL Server 2005) decrease if I shrink it? 如果我收缩它,数据库(SQL Server 2005)的性能是否会降低?

What exactly happen to the mdf and ldf files when shrink is applied (Internals???) 应用缩小时mdf和ldf文件究竟发生了什么(Internals ???)

When shrinking a database it will consume resources to shrink the DB. 缩小数据库时,它将消耗资源来缩小数据库。 Where it runs into issues is when the DB needs to grow again, and assuming you have auto grow set, it will consume more resources to auto grow. 遇到问题的地方是数据库需要再次增长,并且假设您已经设置了自动增长,它将消耗更多资源来自动增长。 Constant auto shrink (or shrink as part of maintenance plan) will cause physical disk fragmentation. 恒定的自动收缩(或作为维护计划的一部分收缩)将导致物理磁盘碎片。

If you have auto grow enabled and it is set to the default of 1MB then constant auto grows will consume a lot of resources. 如果启用了自动增长并将其设置为默认值1MB,则常量自动增长将消耗大量资源。

It is best practice to size your database to a size that is suitable, expected initial size plus expected growth over a period (month, year, whatever period you see fit). 最佳做法是将数据库的大小调整为合适的大小,预期的初始大小加上一段时间(月,年,您认为合适的任何时期)的预期增长。 You should not use auto shrink or use shrink as part of a maintenance program. 您不应使用自动收缩或使用收缩作为维护程序的一部分。

You should also set your auto grow to MB (not a % of the database as when auto growing it needs to calculate the % first, then grow the database). 您还应将自动增长设置为MB(不是数据库的百分比,因为自动增长时需要首先计算%,然后增长数据库)。 You should also set the auto grow to a reasonable amount to ensure that it isnt going to be growing every 10 mins, try and aim for 1 or two growths a day. 您还应该将自动增长设置为合理的数量,以确保它不会每10分钟增长一次,并尝试每天增加1或2个增长。

You should also look at setting Instant Initialisation for your SQL Server. 您还应该考虑为SQL Server设置即时初始化。

Good luck, 祝好运,

Matt 马特

It's important to understand that when you shrink a database, the pages are re-arranged. 了解缩小数据库时,重要的是要重新排列页面。 Pages on the end of the data file are moved to open space in the beginning of the file, with no regard to fragmentation. 数据文件末尾的页面将移动到文件开头的开放空间,而不考虑碎片。

A clustered index determines the physical order of data in a table. 聚簇索引确定表中数据的物理顺序。 So, imagine that you just created a clustered index, which would have re-ordered the data in that table, physically. 因此,假设您刚刚创建了一个聚簇索引,它会在物理上重新排序该表中的数据。 Well, then when you execute a shrink command, the data that had just been neatly ordered during the creation of the clustered index will now potentially be out of order, which will affect SQL's ability to make efficient use of it. 那么,当你执行一个收缩命令时,在创建聚簇索引期间刚刚整齐排序的数据现在可能会出现故障,这将影响SQL有效使用它的能力。

So, any time you do a shrink operation you have the potential of impacting performance for all subsequent queries. 因此,无论何时进行缩减操作,都有可能影响所有后续查询的性能。 However, if you re-do your clustered indexes / primary keys after the shrink, you are helping to defragment much of the fragmentation that you may have introduced during the shrink operation. 但是,如果在收缩后重新执行聚簇索引/主键,则有助于对收缩操作期间可能引入的大部分碎片进行碎片整理。 If performance is critical but you are also forced to do shrinks regularly, then in an ideal world you'd want to re-do your indexes after each shrink operation. 如果性能至关重要,但您也不得不经常收缩,那么在理想的世界中,您需要在每次收缩操作后重新执行索引。

Yes it could affect performance a bit. 是的它可能会影响性能。 When a database is in operation it doesn't care to much about its diskspace usage, more about efficient data retrieval/persistance. 当数据库运行时,它并不关心其磁盘空间的使用,更多关于有效的数据检索/持久性。

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

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