Sql-server – How to shrink a SQL Server Log file with Mirroring enabled

sql-server

I have several databases for my applications that use SQL Server 2005 mirroring to keep a nice copy of the data somewhere else. Works like a charm, however, the log file just seems to be growing and growing, one is at 15GB for a 3GB database.

Normally, I can just shrink it – however an error pops up that this specifically cannot be done. But, it seems eventually if unchecked would just expand to use all the space on the drive.

I see that I can set a maximum file size for the log file, is that the answer here? Will the log just roll when it hits the max, or will the DB just stop functioning?

Thanks

Best Solution

We ran into the same issue after switching from log shipping to mirroring. You have to create a job that regularly backs up the transaction log (every 15 or 30 minutes or so) to keep the log size from getting out of hand.

If it is already out of hand, run BACKUP LOG TO DISK = 'Nul', then run a DBCC SHRINKFILE command. Then you can get your job set up.

Note that The 'Nul' is not a misspelling, it is an old DOS trick that behaves as if you are writing a file, but really just dumps the information off into the ether so it doesn't take up space on the machine.

Also, your log will grow until you run out of space, then the whole thing stops working. Your app will receive an error that the transaction log is full.

EDIT: David correctly pointed out that this action will break the log chain and reduce the ability to recover from failure. Be sure to use the backup log to 'nul' command as a last resort. If you have space on the drive, you should take a proper log backup and setup your log backup plan. Make sure you also include regular full backups and a cleanup task to remove old files.