Dennis van der Stelt

If you have one problem and use cache to solve it, you now have two problems.

Community

Email Notifications

News

  • Addicted to Refactor! Pro

I read...

I Use...

Tags

Recent Posts

Archives

Blog Subscription Form

  • Email Notifications
    Go

Shrink your SQL 2005 transaction logfiles

This might come in handy for some of you, as it did for me. I normally don't have problems with large transaction logfiles, but on our acceptance machine we have mirrored the production database. As it's replicated, the databases are installed multiple times on the machine. In theory it'd be best to have them on multiple machines (to mirror production exactly), but we chose multiple SQL Server 2005 instances.

When the transaction logfiles are growing they take up a huge amount of diskspace. So in our script to restore the environment, we've included a few T-SQL statements to set the recovery model to simple and shrink the transaction logfiles immediately. Here's the code, it might come in handy when you've got a database on your own machine as well.

USE [master]
GO
ALTER DATABASE [YourDatabase] SET RECOVERY SIMPLE WITH NO_WAIT
GO
USE [YourDatabase]
GO
DBCC SHRINKFILE (YourDatabase_log, 10)
GO

You don't want to set the recovery model to simple on critical databases! If you're not sure, just don't change the recovery model. Transactional replication uses the transaction log and if the service agent stops, all transactions are stored in the log to be synced later.

Comments

Mike Glaser said:

Nice SQL statement

For Additional info about Shrinking a SQL Server log

check my blog http://bloggingabout.net/blogs/mglaser/archive/2007/01/12/sql-server-tip-shrinking-a-sql-server-log.aspx

# March 1, 2007 12:25 PM

Brian Sutherland said:

Worked a treat, thanks.

# September 17, 2007 2:36 AM

Craig Updegrave said:

I am a student intern trying to learn the world of sql database administration and space issues seem to come up frequently.  This is a different method than I had been shown before to backup the log with no truncate then use dbcc shrinkfile.  Very interesting, thanks!

# September 11, 2008 5:46 PM

SK said:

It really worked.. Thanks a lot

# August 28, 2009 12:12 AM

Gajji said:

Thanks a lot...it was really helpful

# September 7, 2009 2:21 PM

cwilson said:

Thank you very much!  Worked perfectly.

# April 6, 2010 3:51 PM

Yvonne Overduin said:

Thank you very much!  Worked perfectly.

# June 1, 2010 2:29 PM

RH said:

Thanks worked a treat :-)

# August 18, 2010 4:21 PM

Vishal said:

Neat Trick, thanks Dennis

# September 15, 2010 9:08 AM

Ehab said:

it worked with me too, many thanks

# November 29, 2010 6:45 AM

ColdFusion Developer said:

Is there a way to loop through all active databases and shrink all the log files on the server? This would be great as a part of the maintenance plan.

# February 23, 2011 8:13 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Please add 7 and 3 and type the answer here: