Home → Resources → Articles

How To Shrink or Clear Out Large SQL Server Log Files

(Microsoft SQL Server) by Jason Skowronek on 04/06/2010

First, let me preface this article for all you SQL Server DBAs reading this, in no way am I recommending that the following procedure be used in a production (or development depending on your restoration policy) environment unless you know what you are doing, and are aware of the repercussions to clearing the transaction logs. If not, feel free to read Aaron Bertrand's post on the topic. The main purpose of this article is for those that are in the same situation I often find myself, quickly configured databases in a development environment that do NOT require transactions NOR restoration to any other point other than the last FULL database backup (*.bak).

Now, on to the article...

While migrating our development database server environment, I was reminded how huge SQL Server transaction log files can get. Of course in a development environment, transaction logs are may be irrelevant, so prior to migrating it is always best to truncate the log files as not to move GIGs of log files. These are the ways I am aware of to do such a thing.

First, perform a FULL DB BACKUP of the database (yes, seems redundant, but you will be glad if something fails and you don't lose a days worth of work.)

Update: I've been getting so much flak from people in the community using truncate_only, I have decided to scratch it out. Continue to the recommended method below.

You can use the following SQL command to backup the log file while truncating the existing logs (note: this is deprecated in 2008):

backup log [dbname] with truncate_only
go

dbcc shrinkdatabase ([dbname], 10, truncateonly)
go

OR

You can do the same through SQL Server Management Studio:

  1. Right click the database to be "shrunk" | Properties
  2. Under Select a page click Options
  3. Change Recovery Model to Simple | Ok
  4. Right click the database | Tasks | Shrink | Database | Ok
  5. Make sure to set the recovery mode back to Full (or not, depending on your needs)
  6. Done!

Obviously if you are in a production environment, you probably want to actually backup your logs before you truncate.

Comments (1)

Aaron Bertrand

4/7/2010 1:30:52 AM
This is such a bad idea, unless you really don't care about recoverability (I highly doubt that even your development environment's stability is "irrelevant"). I hope you take a backup immediately after doing this, size your log appropriately so you don't have to do it again, and rub a rabbit's foot the whole time. In any case, before you do this, please read the following (and follow the links therein, and read those too!): http://sqlblog.com/blogs/aaron_bertrand/archive/2009/07/27/oh-the-horror-please-stop-telling-people-they-should-shrink-their-log-files.aspx Also note that WITH TRUNCATE_ONLY will no longer work in SQL Server 2008, so you'll need to find a different way to hold your database precariously at the edge of a cliff.
Leave a comment
Name *
Email *
Homepage
Comment

Recommend

 

Nero Sale 150x150 

UltraEdit

SkoNet provides comprehensive digital consulting services such as: web development, applications development, database design and architecture, business process management, customer relationship management, and many others that help businesses of every size, industry, and geography meet the complex challenge of managing and sharing information on the web. Our skills and expertise in online systems allow us to help customers build applications ranging from simple, single-page web sites to robust enterprise systems.

Online Backup, Ektron Consulting, Ektron Programmer, Ektron Developer, Ektron Partner Utah, Ektron Partner, Ektron Architect, Ektron Hosting, Salesforce.com Consultant Utah, Salesforce.com Partner Utah, Salesforce.com Partner, Salesforce.com Programmer, Salesforce.com Architect, Salesforce.com APEX Programmer