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

Shrink all databases Expand / Collapse
Author
Message
Posted Monday, January 21, 2008 10:15 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Thursday, February 06, 2014 4:51 AM
Points: 711, Visits: 214
Comments posted to this topic are about the item Shrink all databases
Post #445560
Posted Monday, March 17, 2008 2:17 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, June 13, 2011 11:45 AM
Points: 221, Visits: 55
Thanks for the script, but I cannot think of any normal DBA use for it. It is not recommended to shrink all of the databases on a time to time basis. This because of the fragmentation you get on your filesystem. It is recommended to disable the shrink option and size your databases before you place them on the server. Fragmentation will make your server slower.


Post #470121
Posted Monday, March 17, 2008 6:35 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, March 20, 2013 10:58 AM
Points: 4, Visits: 54
The problem that I have is the logfile growing out of control.

I like the script but I found that the shrink (from the GUI) didn't work unless you shrink file as opposed to database. Also when you shrink file you must shrink the log file.

I still can not fathom why MS has changed the shrink so that you must be in simple mode to shrink the logfile. I am used to Oracle, NZ, and TD where this problem just doesn't exist.
Post #470179
Posted Monday, March 17, 2008 6:37 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, November 30, 2010 11:03 AM
Points: 70, Visits: 31
Hi,

I think that's the issue isn't only the usefulness of the script. The script itself it's ugly :p

Actually, you should be getting first the recovery mode of the DB and after the shrink, you should set it again to the original mode. Also, there is a undocummented SP to LOOP over the DBs.

SP_MSForEachDB

Identically to that, there is another to loop through the tables on the current DB:

SP_MSForEachTable

Both of them have a LOT of useful parameters. Take a look at them.

Cheers,
Gonzalo
Post #470182
Posted Monday, March 17, 2008 7:20 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 2:09 PM
Points: 2,035, Visits: 1,655
One more thing that's wrong with this - switching to SIMPLE breaks the log backup chain so you lose the ability to do point-in-time recovery. I have no idea why the script needs to switch to SIMPLE - the shrink (although completely not recommended) will work fine in FULL as well - if the author was trying to prevent log files growing, he just needed to mention taking log backups rather than taking the drastic mode of switching to SIMPLE. No enterprise in their right mind is going to use SIMPLE...

Paul Randal
CEO, SQLskills.com: Check out SQLskills online training!
Blog:www.SQLskills.com/blogs/paul Twitter: @PaulRandal
SQL MVP, Microsoft RD, Contributing Editor of TechNet Magazine
Author of DBCC CHECKDB/repair (and other Storage Engine) code of SQL Server 2005
Post #470213
Posted Monday, March 17, 2008 8:39 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, May 28, 2013 2:51 AM
Points: 6, Visits: 43
Strange that this script is mentioned in the newsletter.
The editor should not has permitted this script since it's a bad bad bad practice.
Post #470279
Posted Monday, March 17, 2008 8:08 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, November 30, 2010 11:03 AM
Points: 70, Visits: 31
That's true, scheduled or regular shrink is a bad practice, in paper.

Sometimes there isn't enough time to fix the App and we need to solve things on the run. Change an app architecture could take months... sometimes a DBA must bend some "best practices" to keep things smooth enouth for the business.

Cheers,
Gonzalo
Post #470604
Posted Tuesday, March 18, 2008 1:05 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, June 13, 2011 11:45 AM
Points: 221, Visits: 55
gonzaloaguilar (3/17/2008)
That's true, scheduled or regular shrink is a bad practice, in paper.

Sometimes there isn't enough time to fix the App and we need to solve things on the run. Change an app architecture could take months... sometimes a DBA must bend some "best practices" to keep things smooth enough for the business.

Cheers,
Gonzalo

I agree with your point, but therefore shrinking all databases is not a good solution. You should then, and only if no other options are available, shrink only those databases that are giving trouble. If all databases are having trouble... Very bad design of all the databases...



Post #470662
Posted Wednesday, March 19, 2008 10:37 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 9:47 AM
Points: 150, Visits: 122
While shrinking each database in a production environment wouldn't be recommended, this does come in handy if you need to rein in your DBs on local or dev. Who here hasn’t had several runaway logs after some over eager developers were done with a particular server???

This sets the backup point on the logs so they can be shrunk. It then returns both the log and data files to their original sizes if possible.


DECLARE @cmd1 varchar(2000),
@cmd2 varchar(2000)

SET @cmd1 = 'BACKUP LOG [?] WITH NO_Log'
SET @cmd2 = 'DBCC SHRINKDATABASE ([?],TRUNCATEONLY)'

EXEC sp_msforeachdb @command1 = @cmd1,
@command2 = @cmd2
Post #471713
Posted Wednesday, March 07, 2012 7:10 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, May 18, 2012 7:50 AM
Points: 5, Visits: 98
I agree with most, if not all on this topic. I made it as far as "changes all databases' recovery mode to simple" and quit reading further.
Post #1262961
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse