SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Is it advisable to shrink the data file?


Is it advisable to shrink the data file?

Author
Message
jeet_personal
jeet_personal
Old Hand
Old Hand (351 reputation)Old Hand (351 reputation)Old Hand (351 reputation)Old Hand (351 reputation)Old Hand (351 reputation)Old Hand (351 reputation)Old Hand (351 reputation)Old Hand (351 reputation)

Group: General Forum Members
Points: 351 Visits: 96
Hi

Is it advisable to shrink .mdf file of a database? What are the advantage and disadvantage of this?
GilaMonster
GilaMonster
SSC Guru
SSC Guru (548K reputation)SSC Guru (548K reputation)SSC Guru (548K reputation)SSC Guru (548K reputation)SSC Guru (548K reputation)SSC Guru (548K reputation)SSC Guru (548K reputation)SSC Guru (548K reputation)

Group: General Forum Members
Points: 548925 Visits: 47741
It is not.

Shrinking causes massive fragmentation and will just result in the data file growing again next time data gets added. When that happens, the entire system will slow down as the file is expanded. Also repeated shrinks and grows will cause fragmentation at the file-system level, which is hard to fix.

See - http://sqlinthewild.co.za/index.php/2007/09/08/shrinking-databases/

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Alberto dbLearner
Alberto dbLearner
Right there with Babe
Right there with Babe (791 reputation)Right there with Babe (791 reputation)Right there with Babe (791 reputation)Right there with Babe (791 reputation)Right there with Babe (791 reputation)Right there with Babe (791 reputation)Right there with Babe (791 reputation)Right there with Babe (791 reputation)

Group: General Forum Members
Points: 791 Visits: 233
Gail, what happens when, after monitoring your data growth for years, you discover that it only fills a little percentage of the datafile, and you are getting short of disk space? In that case, isn't it better to release some space to the file system?

Alberto
Tim Walker.
Tim Walker.
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2857 Visits: 1007
Gails advice here is correct most of the time. In NORMAL use a database stabalises at a particular size.

HOWEVER if you know your database is normally 50% fulll at 1GB and you took exceptional action that took it to 10GB, and you now have 50% of 1GB again you should shrink back to 1GB.

This should remove any O/S fragmentation created above 1GB.

Tim

.
george sibbald
george sibbald
SSC Guru
SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)

Group: General Forum Members
Points: 58480 Visits: 13706
If I may jump in and deprive Gail of a point...............(She's got plenty)

If your database data file is obviously way over sized and you you know you will never need the file that size and besides you need the disk space, then yes, as Tim says, that is an occasion when you can shrink the file. Of course if you do, don't shrink the file down to its minimum possible and immediately follow it with a reindex.

An option is to use the truncateonly option of dbcc shrinkfile (don't use shrink database). This does not move data about and just trims the file to the last used extent. Depending where this extent is it might recover no space, about what you wanted, or more than you wanted. If more than you wanted increase the file again manually to the desired size. For a large database this method can be much quicker and less intrusive.

---------------------------------------------------------------------
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search