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 12»»

script to shrink db Expand / Collapse
Author
Message
Posted Monday, August 9, 2010 8:37 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, October 21, 2010 1:18 PM
Points: 71, Visits: 380
can any one provide sql script for shrink db by small increment
Post #965997
Posted Monday, August 9, 2010 8:41 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 3:37 PM
Points: 40,210, Visits: 36,619
(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 2008, MVP
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

Post #966002
Posted Monday, August 9, 2010 9:00 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, October 21, 2010 1:18 PM
Points: 71, Visits: 380
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

Post #966024
Posted Monday, August 9, 2010 9:05 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 3:37 PM
Points: 40,210, Visits: 36,619
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 2008, MVP
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

Post #966027
Posted Monday, August 9, 2010 9:09 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 4:00 PM
Points: 31,181, Visits: 15,627
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.







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #966032
Posted Monday, August 9, 2010 9:18 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, October 21, 2010 1:18 PM
Points: 71, Visits: 380
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
Post #966039
Posted Monday, August 9, 2010 9:26 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 4:00 PM
Points: 31,181, Visits: 15,627
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.







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #966043
Posted Monday, August 9, 2010 9:42 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 3:37 PM
Points: 40,210, Visits: 36,619
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 2008, MVP
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

Post #966053
Posted Monday, August 9, 2010 9:44 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, October 21, 2010 1:18 PM
Points: 71, Visits: 380
thanks,but we need script to shrink it every night in small shunks as we already have a reorg/rebuild job running every night
Post #966055
Posted Monday, August 9, 2010 9:46 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 4:00 PM
Points: 31,181, Visits: 15,627
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.






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #966058
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse