Monday, July 10, 2017

Issue with ePo database indexes before upgrade to ePO 5.9

When you upgrade ePO server to version 5.9, you may have the following warning:

"ePo database indexes are fragmented. Rebuild the index before upgrading"

To resolve this problem open SQL management studio and run this query on your ePO database to extract all index with a percentage of fragmentation greater than 30% :

SELECT OBJECT_NAME(ind.OBJECT_ID) AS TableName,
ind.name AS IndexName, indexstats.index_type_desc AS IndexType,
indexstats.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) indexstats
INNER JOIN sys.indexes ind
ON ind.object_id = indexstats.object_id
AND ind.index_id = indexstats.index_id
WHERE indexstats.avg_fragmentation_in_percent > 30
ORDER BY indexstats.avg_fragmentation_in_percent DES

In order to reduce fragmentation we will have to rebuild the indexes, so run this query to rebuild index

Declare @TBname nvarchar(255),
        @SQL nvarchar(max)

select @TBname = min(TABLE_NAME) from INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'

while @TBname is not null

BEGIN
    set @SQL='ALTER INDEX ALL ON [' + @TBname + '] REBUILD;'
    --print @SQL
    EXEC SP_EXECUTESQL @SQL
    select @TBname = min(TABLE_NAME) from INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' and TABLE_NAME > @TBname        
END

Now you can restart the upgrade wizard without index problem.

No comments:

Post a Comment