views:

472

answers:

8

My log file in SQL Server used up all the space on my disk. I run full backups every night, but the log file keeps growing. What can I do?

A: 

Delete the log file?

Edit: Apparently deleting the log file is bad, it's just just a log to SQL server. I'm leaving this up to reiterate what not to do.

Grant
Deleting the log file would be really bad for a sql server...It contains the information to recover from a hard error.
Andrew Rollings
A: 

You could use some kind of log-rotation, and keep only log of a fixed amount of time, say the last 7 days. This should be more than enough. Or you could reset the log every night, because you should have it in your backup.

Ulf
+3  A: 

On most busy systems, you need to look at scheduling log backups throughout the day, and then your nightly full backup. This is pretty common practice.

Anthony
+1  A: 

You have to backup up your logs as well as the main database

DJ
A: 

This should shrink it:

dbcc shrinkfile('databasename_log', 0)
ScottN
A: 

try this:

dump transaction <dbname> with no_log

and then shrink the logfile by setting the autoshrink option in the sql server settings or by.

I think you can use dbcc to shrink it too, but i dont remember the syntax.

Allan Simonsen
+3  A: 

Hi,

If you have a job scheduled to conduct full backups this is good and should be your starting point however, you also need to be carrying out regular transaction log backups.

Backing up the transaction log causes the space to be relcaimed. Once you have defined your regular transaction log backup schedule, you will likely be in a potition to consider shrinking the transaction log to a more apporpriate size. As it will no longer be growing indefinately.

The backup strategy for full recovery consists of:

* Database backups.

* Differential backups (optional).

* Transaction log backups.

I suggest you consult the following Microsoft reference.

http://msdn.microsoft.com/en-us/library/aa173551(SQL.80).aspx

John Sansom
+4  A: 

In some cases you might find the the logfile will not properly truncate even though a log backup is run. You can do a backup with TRUNCATE_ONLY to check it. When you run this it should truncate the transaction log:

BACKUP LOG dbname WITH TRUNCATE_ONLY

The cause of this problem is an open transaction in an earlier part of the log. SQL will not truncate the log past this transaction, potentially causing a large, ever increasing log. You need to find out which transactions are left open and why. You can monitor your log space with:

DBCC SQLPERF (LOGSPACE)

Information on long running transactions can be found using:

DBCC OPENTRAN

Or:

select * from sys.dm_tran_database_transactions
badbod99
Hi, keep in mind that using the WITH TRUNCATE_ONLY option will not actually backup the transaction log. You will loose the ability to restore to a point in time and so should immediately follow up this action with a full backup, once transaction log issues are of course resolved.
John Sansom