Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Shrink Database


Shrink Database

Author
Message
bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)

Group: General Forum Members
Points: 7147 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
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

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

Malleswarareddy
I.T.Analyst
MCITP(70-451)
M&M
M&M
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

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

M&M
hakan.winther
hakan.winther
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2792 Visits: 605
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
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2619 Visits: 8073
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
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1235 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
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2792 Visits: 605
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
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25707 Visits: 9671
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
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 9008 Visits: 13687
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
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4567 Visits: 72513
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