Shrink all databases

  • Comments posted to this topic are about the item Shrink all databases

  • 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.

  • 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.

  • 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

  • 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

  • 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.

  • 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

  • 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...

  • 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

  • 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.

  • This is a forum and all comments are welcomed.

    However, the forum readers, both new and experienced, need to take things with a grain of salt - meaning research, possibly vet, and then test, before actual usage.

    As for this post, well, I had a good "guffaw" ...

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

  • Thanks for the script.

  • You're welcome 🙂

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply