August 9, 2010 at 8:37 am
can any one provide sql script for shrink db by small increment
August 9, 2010 at 8:41 am
(as posted over at SQLTeam)
Why do you want to shrink? Databases tend to grow as more data gets put in them. It's in their nature.
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
August 9, 2010 at 9:00 am
we have a PROD DB which is about 300Gig, however we are only using 50%.
Shrinking the DB will probably have some slight benefit to our backup process, but more importantly will make it easier to restore the DB on local servers
we need a script that will shrink a small amount of the DB, and schedule it to run every night so that we can see period decreases in size
August 9, 2010 at 9:05 am
Shrinking will do nothing for your backups. Backups only back up used space, not empty space.
If you're going to shrink, do a once-off shrink, then rebuild all your indexes to fix what the shrink did to them. Shrinking a little every night is a really bad idea. You'll be causing massive index fragmentation every time, necessitating an index rebuild of every index every night.
What I would suggest is a once-off shrink, shrink the DB to about 10% free, then leave it.
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
August 9, 2010 at 9:09 am
I tend to agree with Gail, but I'd look over the last few backups. How large are they? How much are they growing? Each one should be in the 150GB range, but how much change is there? I try to grow databases only every few months, so I'd figure out how much space you need for the next xx months, leave that free, and then shrink to that level.
As Gail mentioned, shrink once, not regularly.
August 9, 2010 at 9:18 am
we want to shrink it down from it's enormous size now
i understand it will grow again
we need to look at those numbers and start to pre-grow the file
we have scheduled maintenance for defragging both at the db and disk (o/s) level
August 9, 2010 at 9:26 am
Use DBCC SHRINKFILE to reduce the size of the file. You need to leave free space immediately, as you want to reindex your tables as the shrink will fragment the indexes.
Grow periodically, in big chunks.
August 9, 2010 at 9:42 am
dba_neo (8/9/2010)
we want to shrink it down from it's enormous size now
Do a once-off shrinkfile and shrink it down to around 170GB.
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
August 9, 2010 at 9:44 am
thanks,but we need script to shrink it every night in small shunks as we already have a reorg/rebuild job running every night
August 9, 2010 at 9:46 am
Why do you think you need to shrink every night? I'd submit to you that you don't, and that you don't really understand the implications of doing that. you're also wasting resources.
August 9, 2010 at 10:17 am
Why? What does shrinking in small chunks each day give you that a once off shrink doesn't? (other than a massive waste of time and resources)
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
August 9, 2010 at 10:22 am
dba_neo (8/9/2010)
thanks,but we need script to shrink it every night in small shunks as we already have a reorg/rebuild job running every night
Isn't that also a waste of resources to do every night ?
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply