ousoonerjoe
Programmer
Using SQL 2008 R2.
A couple of months ago, we turned on CDC on some select tables. The following week, we had to turn off the Index Rebuild process of the weekly maintenance job due to the fact that CDC blocks the dropping of the Primary Key and caused the maintenance job to fail (which also happened to include the Full Backup process). Skip ahead to today and now we are getting reports of major slow downs. After checking the index fragmentation rates, some were showing 100% fragmentation. I found the following script to rebuild the indexes using DBCC DBREINDEX to get around the CDC issue:
Once that finished, I ran the following against a couple of tables to see how well it defragged the indexes. I noticed that there were 3 levels to each index. Level 1 was defragged, but 2 and 3 were not. What are the levels and does one need to be concerned with them regarding defraging?
--------------------------------------------------
Stubbornness is a virtue -- if you are right. --Chuck Noll
--------------------------------------------------
A couple of months ago, we turned on CDC on some select tables. The following week, we had to turn off the Index Rebuild process of the weekly maintenance job due to the fact that CDC blocks the dropping of the Primary Key and caused the maintenance job to fail (which also happened to include the Full Backup process). Skip ahead to today and now we are getting reports of major slow downs. After checking the index fragmentation rates, some were showing 100% fragmentation. I found the following script to rebuild the indexes using DBCC DBREINDEX to get around the CDC issue:
Code:
DECLARE @TableName varchar(255);
DECLARE TableCursor CURSOR FOR
SELECT table_name FROM information_schema.tables
WHERE table_type = 'base table'
AND Table_Schema = 'dbo'
ORDER BY Table_Name;
OPEN TableCursor;
FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
DBCC DBREINDEX(@TableName,' ',90);
PRINT @TableName + ' - Completed.';
FETCH NEXT FROM TableCursor INTO @TableName;
END
CLOSE TableCursor;
DEALLOCATE TableCursor;
Code:
SELECT i.name, ips.*
FROM sys.dm_db_index_physical_stats(DB_ID(N'DbName'), OBJECT_ID(N'TableName'), NULL, NULL, 'DETAILED') ips
--INNER JOIN sys.objects o ON ips.object_id = o.object_id
INNER JOIN sys.indexes i ON ips.object_id = i.object_id AND ips.index_id = i.index_id;
--------------------------------------------------
Stubbornness is a virtue -- if you are right. --Chuck Noll
--------------------------------------------------