积极答复者
sql server索引碎片的问题

问题
-
sql server如果只对日志文件进行压缩,而不对数据文件进行压缩,那也会产生索引碎片吗?
- 已移动 Sheng Jiang 蒋晟 2012年11月27日 19:35 (发件人:一般性问题讨论区)
答案
-
你好,
如果只对日志文件压缩的话, 不会对索引碎片数有影响。 但你再次向该数据库存在索引的表插入数据时, 就会增加碎片。
-- Name of the Database and Size SELECT name, (size*8) Size_KB FROM sys.database_files GO -- Check Fragmentations in the database SELECT avg_fragmentation_in_percent, fragment_count FROM sys.dm_db_index_physical_stats (DB_ID(), null, NULL, NULL, 'LIMITED') GO SELECT object_name(object_id),index_id,avg_fragmentation_in_percent,avg_page_space_used_in_percent FROM sys.dm_db_index_physical_stats (DB_ID(), null, NULL, NULL, 'DETAILED') where avg_fragmentation_in_percent>10 AND avg_page_space_used_in_percent<75 GO -- Shrink the log file DBCC SHRINKFILE (database_log, 1); GO -- Name of the Database and Size SELECT name, (size*8) Size_KB FROM sys.database_files GO -- Check Fragmentations in the database SELECT avg_fragmentation_in_percent, fragment_count FROM sys.dm_db_index_physical_stats (DB_ID(), null, NULL, NULL, 'LIMITED') GO SELECT object_name(object_id),index_id,avg_fragmentation_in_percent,avg_page_space_used_in_percent FROM sys.dm_db_index_physical_stats (DB_ID(), null, NULL, NULL, 'DETAILED') where avg_fragmentation_in_percent>10 AND avg_page_space_used_in_percent<75 GO
Best Regards,
立刻免费下载TechNet论坛好帮手
- 已编辑 Molly Chen_Moderator 2012年11月28日 6:27
- 已标记为答案 Molly Chen_Moderator 2012年12月3日 2:39
-
sql server如果只对日志文件进行压缩,而不对数据文件进行压缩,那也会产生索引碎片吗?
It will not cause table fragmentation but shrinking log file has performance hit due to disk io, and sql will expand log file again when needed that has performance hit too.- 已标记为答案 Molly Chen_Moderator 2012年12月3日 2:39
全部回复
-
你好,
如果只对日志文件压缩的话, 不会对索引碎片数有影响。 但你再次向该数据库存在索引的表插入数据时, 就会增加碎片。
-- Name of the Database and Size SELECT name, (size*8) Size_KB FROM sys.database_files GO -- Check Fragmentations in the database SELECT avg_fragmentation_in_percent, fragment_count FROM sys.dm_db_index_physical_stats (DB_ID(), null, NULL, NULL, 'LIMITED') GO SELECT object_name(object_id),index_id,avg_fragmentation_in_percent,avg_page_space_used_in_percent FROM sys.dm_db_index_physical_stats (DB_ID(), null, NULL, NULL, 'DETAILED') where avg_fragmentation_in_percent>10 AND avg_page_space_used_in_percent<75 GO -- Shrink the log file DBCC SHRINKFILE (database_log, 1); GO -- Name of the Database and Size SELECT name, (size*8) Size_KB FROM sys.database_files GO -- Check Fragmentations in the database SELECT avg_fragmentation_in_percent, fragment_count FROM sys.dm_db_index_physical_stats (DB_ID(), null, NULL, NULL, 'LIMITED') GO SELECT object_name(object_id),index_id,avg_fragmentation_in_percent,avg_page_space_used_in_percent FROM sys.dm_db_index_physical_stats (DB_ID(), null, NULL, NULL, 'DETAILED') where avg_fragmentation_in_percent>10 AND avg_page_space_used_in_percent<75 GO
Best Regards,
立刻免费下载TechNet论坛好帮手
- 已编辑 Molly Chen_Moderator 2012年11月28日 6:27
- 已标记为答案 Molly Chen_Moderator 2012年12月3日 2:39
-
sql server如果只对日志文件进行压缩,而不对数据文件进行压缩,那也会产生索引碎片吗?
It will not cause table fragmentation but shrinking log file has performance hit due to disk io, and sql will expand log file again when needed that has performance hit too.- 已标记为答案 Molly Chen_Moderator 2012年12月3日 2:39