DBAtlas · 데이터베이스 운영 아틀라스

인덱스 단편화 확인

SQL Server유지보수

명령어

SELECT OBJECT_SCHEMA_NAME(ips.object_id) AS schema_name,
       OBJECT_NAME(ips.object_id)        AS table_name,
       i.name                            AS index_name,
       ips.index_type_desc,
       ROUND(ips.avg_fragmentation_in_percent,1) AS frag_pct,
       ips.page_count
FROM   sys.dm_db_index_physical_stats(DB_ID(N'Customer'), NULL, NULL, NULL, 'LIMITED') ips
  JOIN sys.indexes i
    ON i.object_id = ips.object_id AND i.index_id = ips.index_id
WHERE  ips.avg_fragmentation_in_percent > 10
  AND  ips.page_count > 1000
ORDER BY ips.avg_fragmentation_in_percent DESC;

하는 일

인덱스의 단편화 비율과 페이지 수를 나열한다. rebuild/reorganize 결정의 근거가 된다.

사용 시점

유지보수 전에 어떤 인덱스를 처리할지 결정하기 위해.

주의

작은 인덱스(< 1000 페이지)에서는 단편화가 무의미하므로 필터링된다. 'DETAILED' 모드는 더 정확하지만 비용이 매우 크며 보통 'LIMITED'로 충분하다. 조회 전용이며 위험 없음.

DBAtlas에서 열기 →

관련 항목