Subscribe to Windows IT Pro
September 18, 2009 12:00 AM

The Great Debate: Should You Shrink Databases?

Let us know what you think
SQL Server Pro
InstantDoc ID #102796
Rating: (2)

Just like the debate over whether the chicken or the egg came first, the debate over whether you should or shouldn't shrink databases is still going strong. This debate took center stage when the Reader to Reader article "Utilities Assess Data-File Usage and Provide Commands So You Can Do Something About It" was published. In this article, David Paul Giroux discussed how to use two T-SQL utilities (Candidate Commands and Candidate Commands Plus) to manage the size of data files. These utilities provide not only information about disk and data-file usage but also commands you can use to shrink or grow the size of data files.

In response to "Utilities Assess Data-File Usage and Provide Commands So You Can Do Something About It", readers shared their views on the practice of shrinking databases in the article's reader comment area, on SQL Server Magazine's Twitter page, and in their own blogs. We want to share some of those comments with you in hope of getting a discussion going on whether shrinking databases is acceptable, and if so, when it's okay to do so. If you'd like to share your thoughts, click the View Reader Comments link at the top of the page, scroll up, and enter your comments in the text box.

Really Dangerous Advice
Reader jsegarra was the first to comment on the article. Believing that shrinking databases isn't a good idea, he commented:

"I'm sorry but you really shouldn't be shrinking databases in the first place. No offense."

Brent Ozar (brento) echoed that sentiment when he wrote,

"This is really, really, REALLY dangerous advice that can cause performance problems. I responded to it in full here: http://www.brentozar.com/archive/2009/08/stop-shrinking-your-database-files-seriously-now/"

Note that the item Ozar is referencing is his blog, "Stop Shrinking Your Database Files. Seriously. Now." In that blog, he writes,

"Don't shrink your database files just to free up drive space. Stop. It's an unbelievably, disgustingly, repulsively bad idea. Your disk drive space is for files, not for ornamentation. You don't get bonused based on the amount of free space on your drives. Empty files don't take longer to back up. And so help me, if you find yourself shrinking databases so often that you have to automate it, you need to cut up your DBA card and reconsider your choice of career."

Ozar's blog also includes links to other posts about the topic of shrinking databases, including Paul Randal's blog post "Why you should not shrink your data files".

The Script is Just a Tool
When readers' comments started streaming in, we asked Giroux for his thoughts. He wrote:

"The script is a tool. The script does not make any changes. The article is narrow in scope and gives NO ADVICE. The article is not in regards to file management and does not attempt to be all encompassing. There are countless articles regarding file management, I don't desire to write another one. No DBA should attempt to read one single article on one single issue and expect his/her training to be complete. Learn file management elsewhere. As Paul Randal states in his post 'Why you should not shrink your data files': 'Bottom line - TRY TO AVOID running data file shrink at all costs!' (I added the emphasis on 'try to avoid'.) If the competent DBA decides a file needs to be shrunk OR GROWN, this script can assist the DBA."

"I created this script because of one particular server that had 24 databases and no free disk space. One of the databases ran out of database free space. I could not unilaterally truncate tables, or move databases to a different server or add physical drives. The only thing I could do instantly was rob Peter to pay Paul. Yes. I shrunk the file of Database A so I could increase the file for Database B. That gave me time to THEN come up with a long term solution."

Related Content:

ARTICLE TOOLS

Comments
  • jeffrey
    3 years ago
    Nov 16, 2009

    I believe for those against shrinking db, it is mainly because of concerns for bad performance thereafter. However on the other hand, there are tons of BUSINESS reasons that shrinking a db is a must due to various factors including the potential bug(s) of SQL Server itself. I have experienced quite a few scenarios requiring do db data file shrinking in the last two years. The mostly complicated one will take me too much time to describe here but I'll just use a very simple one here, before SQL 2K5, in each of our DBs, we have a secondary file that stores BLOB columns, after upgrading to SQL 2K5, we decide to partition a few big tables with BLOB columns and put these tables on different data files other than the secondary file, and as such, the secondary file, about 1TB in size, has a "hole" of about 800GB, which we believe within the next two years will not be filled up, so what did we do? Shrink it !

    For those who have never experienced shrinking a db data file, I would say it is a pity that your DBA life is not complete to some extent because shrinking a db file is not as easy as just type in dbcc shrinkfile, you also need to monitor whether your shrinking file process will cause any harm (like blocking etc) to your production.

    In the end, I think MS should revisit their dbcc shrinkfile / shrinkdb algorithm to ensure after shrinking db/file, there is no performance sacrifice.
    To those who need to shrink db / file, I'd say go ahead with careful planning and as a DBA, business continuity should always override performance concerns (which can always be tuned / improved later on, such as reindex, or index reorganization after shrinking etc)

  • Richard
    3 years ago
    Oct 26, 2009

    I must say that I'm with David Paul Giroux and Bill McEvoy on this one.
    We all aspire to have perfectly-sized batabases held on exactly the right amount of disk space including an amount for planned growth and/or contingency. However, in day to day running, situations sometimes arise when you either have to shrink a tlog to buy yourself some time to implement a long-term solution or allow an application to grind to a halt.
    Not necessarily poor planning, just s**t happens.

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.