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


Shrink Database


Shrink Database

Author
Message
bitbucket-25253
bitbucket-25253
SSC-Dedicated
SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)

Group: General Forum Members
Points: 30351 Visits: 25280
Comments posted to this topic are about the item Shrink Database

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
malleswarareddy_m
malleswarareddy_m
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3587 Visits: 1189
Great question.Learned new thing today.

Malleswarareddy
I.T.Analyst
MCITP(70-451)
M&M
M&M
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10894 Visits: 3918
Great article by Paul. Good question, like to see more of these.

M&M
hakan.winther
hakan.winther
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3889 Visits: 613
I am surprised that 60% thought it wouldn't increase! Shrinking a databases is like the opposite of defragmentation! I have seen some terrible examples at some clients using "auto shrink" on the databases. Guess what happens to the performance!

Shrinking a database would give you a warning about the fragmentation issues, and auto shrink would send a message to your boss telling him to fire you! Smile

/Håkan Winther
MCITPBigGrinatabase Developer 2008
MCTS: SQL Server 2008, Implementation and Maintenance
MCSE: Data Platform
Toreador
Toreador
SSCertifiable
SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)

Group: General Forum Members
Points: 5436 Visits: 8228
I didn't have the foggiest, so am one of the 60% who guessed wrongly that it wouldn't increase!

I've never had to work with a database that did anything other than grow :-)
James_B
James_B
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1609 Visits: 738
I was expecting the fragmentation to grow on the basis that pages at the end of a database file get moved to empty pages earlier during a shrink.

When i tried this out with a new database (512mb data file and 128mb log file) I got a different fragmentation of 46.875% (2008) 70.3125% (2005) before the table drop and the same after the shrink. I have tried it several times on SQL 2005 (9.00.5057) and SQl 2008 (10.50.2500) and get roughly the same fragmentation percentage. During the shrink i got the warning mesage below.

DBCC SHRINKDATABASE: File ID 1 of database ID 34 was skipped because the file does not have enough free space to reclaim.


I tried running the script with 2500 inserts into FirstTable and got exactly the same frgmentation as the question 39.0625% but still got the same warning when trying to shrink the file.

So the correct answer for me was no change. I guess the real answer is "it depends" on your setup.
hakan.winther
hakan.winther
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3889 Visits: 613
j_baldwinson (8/10/2011)
I was expecting the fragmentation to grow on the basis that pages at the end of a database file get moved to empty pages earlier during a shrink.

When i tried this out with a new database (512mb data file and 128mb log file) I got a different fragmentation of 46.875% (2008) 70.3125% (2005) before the table drop and the same after the shrink. I have tried it several times on SQL 2005 (9.00.5057) and SQl 2008 (10.50.2500) and get roughly the same fragmentation percentage. During the shrink i got the warning mesage below.

DBCC SHRINKDATABASE: File ID 1 of database ID 34 was skipped because the file does not have enough free space to reclaim.


I tried running the script with 2500 inserts into FirstTable and got exactly the same frgmentation as the question 39.0625% but still got the same warning when trying to shrink the file.

So the correct answer for me was no change. I guess the real answer is "it depends" on your setup.


Your database didn't get shrunk because the space for FirstTable didn't get released for some reason. Try to use CHECKPOINT between them and see if you get a different result.

The point with the question is to demonstrate the issue with shrink and why you should avoid it.

/Håkan Winther
MCITPBigGrinatabase Developer 2008
MCTS: SQL Server 2008, Implementation and Maintenance
MCSE: Data Platform
Ninja's_RGR'us
Ninja's_RGR'us
SSC Guru
SSC Guru (133K reputation)SSC Guru (133K reputation)SSC Guru (133K reputation)SSC Guru (133K reputation)SSC Guru (133K reputation)SSC Guru (133K reputation)SSC Guru (133K reputation)SSC Guru (133K reputation)

Group: General Forum Members
Points: 133242 Visits: 9672
Very nice question @bitbucket-25253.


I got it wrong because I couldn't choose between 50% and 90%. I knew the heap writes all over the place and that shrink "usually" drives fragmentation over 90%. However in this case I was struggling with the fact that there's only 2 tables. Given that only 1 table was left I was think that all the page would move to the front an be "somewhat" in order.


Loved this question, just giving you pointers for the next ones :-).
george sibbald
george sibbald
SSC Guru
SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)

Group: General Forum Members
Points: 50504 Visits: 13706
obviously a very worthwhile educational question on the basis that so many people have thought the shrink would have no affect.

now they know!

---------------------------------------------------------------------
mtassin
mtassin
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11806 Visits: 72523
I knew it would screw up the database.... didn't expect 90% but figured what the hey and got it right.

What I found more interesting was being able to predict the initial fragmentation. Is there a magical formula for that somewhere?



--Mark Tassin
MCITP - SQL Server DBA
Proud member of the Anti-RBAR alliance.
For help with Performance click this link
For tips on how to post your problems
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