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


Shrink all databases


Shrink all databases

Author
Message
skra
skra
Right there with Babe
Right there with Babe (722 reputation)Right there with Babe (722 reputation)Right there with Babe (722 reputation)Right there with Babe (722 reputation)Right there with Babe (722 reputation)Right there with Babe (722 reputation)Right there with Babe (722 reputation)Right there with Babe (722 reputation)

Group: General Forum Members
Points: 722 Visits: 228
Comments posted to this topic are about the item Shrink all databases
Gé Brander
Gé Brander
SSC Veteran
SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)

Group: General Forum Members
Points: 233 Visits: 56
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.



frankjustme2004
frankjustme2004
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 57
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.
Gonzalo-603688
Gonzalo-603688
Valued Member
Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)

Group: General Forum Members
Points: 74 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
Paul Randal
Paul Randal
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2511 Visits: 1715
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
Daan Stam
Daan Stam
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 44
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.
Gonzalo-603688
Gonzalo-603688
Valued Member
Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)

Group: General Forum Members
Points: 74 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
Gé Brander
Gé Brander
SSC Veteran
SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)

Group: General Forum Members
Points: 233 Visits: 56
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...



tomeh52-508672
tomeh52-508672
SSC-Enthusiastic
SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)

Group: General Forum Members
Points: 150 Visits: 129
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
Rich.Gamble
Rich.Gamble
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 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.
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