tags:

views:

349

answers:

3

I have ran a defrag report on a SQL server and the mdf file for the database is being reported as 99% fragmented. I asked a colleague and they said this may be normal as it just the way that type of file works internally.

Is it an issue and would running a disk defrag for this file improve DB performance? It is a pain to because it requires a lot of space on disk as it is a huge file so I want to be sure whether it is necessary.

Update

Another linked question leading on from the answers. How would a RAID striped configuration affect this. If the data is striped over multiple disks would defragmentation be less of an issue?

+2  A: 

Short answer is yes a defrag would help.

Clustered indexes try to organize the index such that only sequential reads will be required. This is great if the .MDF is contiguous on disk. Not so much if the file is spread out all over the disk.

Also even though SQL allocates in 8K blocks having to move the disk head all over the place leads to much slower access times. You really want the file contiguous.

+3  A: 

As long as you have determined that, in fact, you have a database response problem this would be a good candidate for improvement. Presumably you've at least determined that there is a problem to be solved, and that it's in the database. (i.e. you've tested queries which are slower than you would like; or you see locks; etc.).

Otherwise it starts to look like guessing and trying. Caching naturally compensates for a lot of this depending on your query patterns.

le dorfier
+1 From Me, le dorfier
Mark Brittingham
Yes, seeing we are seeing locks and slow running queries.Could you expand on what you mean by caching compensating, if you have a spare moment, would like to learn what you mean by that.
Jimmymcnulty
The database loads data from disk into memory when it queries, and holds that data available in memory (cache) until it needs to use it for other purposes (usually on a FIFO basis). Many usage patterns query a subset of the data frequently, so it's likely to be already loaded.
le dorfier
If so, fragmentation isn't as much an issue because it's not actually hitting the disk that often. (Another option for dealing with this is adding RAM - probably your most likely helpful hardware improvement.)
le dorfier
Thanks for the excellent explanation, le dorfier. Get what you mean now!
Jimmymcnulty
A: 

A good way to avoid this is to not rely on autogrow. Give the MDF room to breath.

jms