Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12345»»»

Shrink Database Expand / Collapse
Author
Message
Posted Tuesday, August 09, 2011 8:23 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 12:37 PM
Points: 5,471, Visits: 23,521
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
Post #1157383
Posted Tuesday, August 09, 2011 11:06 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, March 12, 2014 3:59 AM
Points: 1,938, Visits: 1,149
Great question.Learned new thing today.

Malleswarareddy
I.T.Analyst
MCITP(70-451)
Post #1157409
Posted Wednesday, August 10, 2011 1:05 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, April 14, 2014 5:49 PM
Points: 2,263, Visits: 3,758
Great article by Paul. Good question, like to see more of these.

Mohammed Moinudheen
Post #1157427
Posted Wednesday, August 10, 2011 2:12 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, April 03, 2014 3:33 PM
Points: 2,526, Visits: 530
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! :)


/Håkan Winther
MCITP:Database Developer 2008
MCTS: SQL Server 2008, Implementation and Maintenance
Post #1157447
Posted Wednesday, August 10, 2011 2:50 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: 2 days ago @ 7:26 AM
Points: 1,658, Visits: 6,002
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
Post #1157462
Posted Wednesday, August 10, 2011 4:11 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 7:31 AM
Points: 1,185, Visits: 673
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.
Post #1157502
Posted Wednesday, August 10, 2011 5:24 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, April 03, 2014 3:33 PM
Points: 2,526, Visits: 530
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
MCITP:Database Developer 2008
MCTS: SQL Server 2008, Implementation and Maintenance
Post #1157522
Posted Wednesday, August 10, 2011 6:08 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Thursday, January 16, 2014 12:03 PM
Points: 21,376, Visits: 9,594
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 .
Post #1157545
Posted Wednesday, August 10, 2011 6:36 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:46 PM
Points: 5,849, Visits: 12,585
obviously a very worthwhile educational question on the basis that so many people have thought the shrink would have no affect.

now they know!


---------------------------------------------------------------------

Post #1157567
Posted Wednesday, August 10, 2011 7:03 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 12:05 PM
Points: 3,569, Visits: 72,411
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
Post #1157580
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse