How to rebuild SQL Server indexes of Archive Server for MDaemon database.

KB51272

Ultimo aggiornamento: 20 February 2012

Rebuilding SQL Server indexes

3.2.3

Excessive indexes fragmentation in the Archive Server for MDaemon (ASM) database may cause performance degradation of  searches or in the navigation through the web interface. If database type is SQL Server, you can try to see if rebuilding database indexes gets performance to a "normal" level.



You can proceed in this way:

  1. Access to SQL by the SQL Server Management Studio
  2. Perform a backup of ASM database (as precaution)
  3. Open the SQL Query executor
  4. Copy and run following T-SQL code (this code assumes that ASM database is called asm_db (default name)):

USE asm_db
GO

Print 'Selecting Index Fragmentation in the database.'

SELECT
  DB_NAME(DPS.DATABASE_ID) AS [DatabaseName]
 ,OBJECT_NAME(DPS.OBJECT_ID) AS TableName
 ,SI.NAME AS IndexName
 ,DPS.INDEX_TYPE_DESC AS IndexType
 ,DPS.AVG_FRAGMENTATION_IN_PERCENT AS AvgPageFragmentation
 ,DPS.PAGE_COUNT AS PageCounts
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL , NULL, NULL) DPS –N'LIMITED') DPS
INNER JOIN sysindexes SI
    ON DPS.OBJECT_ID = SI.ID
    AND DPS.INDEX_ID = SI.INDID
ORDER BY DPS.avg_fragmentation_in_percent DESC
GO
EXEC sp_MSforeachtable @command1="print 'Rebuilding indexes for ?' ALTER INDEX ALL ON ? REBUILD WITH (FILLFACTOR = 90)"
GO
SELECT
  DB_NAME(DPS.DATABASE_ID) AS [DatabaseName]
 ,OBJECT_NAME(DPS.OBJECT_ID) AS TableName
 ,SI.NAME AS IndexName
 ,DPS.INDEX_TYPE_DESC AS IndexType
 ,DPS.AVG_FRAGMENTATION_IN_PERCENT AS AvgPageFragmentation
 ,DPS.PAGE_COUNT AS PageCounts
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL , NULL, NULL) DPS –N'LIMITED') DPS
INNER JOIN sysindexes SI
    ON DPS.OBJECT_ID = SI.ID
    AND DPS.INDEX_ID = SI.INDID
ORDER BY DPS.avg_fragmentation_in_percent DESC
GO