【问题标题】:SQL Server - Rebuild indexes beyond specific fragmentation thresholdSQL Server - 重建超出特定碎片阈值的索引
【发布时间】:2015-02-18 21:37:15
【问题描述】:

我想设置一个夜间脚本来重建所有碎片超过 30% 的索引。你能帮忙吗?

谢谢!

【问题讨论】:

标签: sql .net sql-server performance


【解决方案1】:

您可以使用Ola Hallengren's index maintenance solution。如果您只想重建索引,则可以这样配置dbo.IndexOptimize 过程:

CREATE PROCEDURE [dbo].[IndexOptimize]
@Databases nvarchar(max),
@FragmentationLow nvarchar(max) = NULL,
@FragmentationMedium nvarchar(max) = NULL,
@FragmentationHigh nvarchar(max) = 'INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',
@FragmentationLevel1 int = 5,
@FragmentationLevel2 int = 30, 
...

这些值具有以下含义:

  1. 当碎片率高于 30%(参数@FragmentationLevel2)时被认为是高。
  2. 当索引的碎片很高时,SQL Server 使用以下操作(参数@FragmentationHigh):INDEX_REBUILD_ONLINE 如果可用(企业版),否则使用INDEX_REBUILD_OFFLINE

参考资料:

Documentation: SQL Server Index and Statistics Maintenance

SQLBits presentation: Inside Ola Hallengrens Maintenance Solution

Tweaking the Defaults for Ola Hallengren’s Maintenance Scripts

Automate and Improve Your Database Maintenance Using Ola Hallengren's Free Script - section IndexOptimize Stored Procedure

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    相关资源
    最近更新 更多