The Curious Case of: the un-droppable transaction log file

Question: I had to add a second log file to my database because the log file ran out of space and I was unable to perform a transaction log backup. Now I can’t drop the second log file. Can you help?

Answer: Adding a second transaction log file temporarily is quite acceptable when the log file runs out of space. If the log cannot be cleared (usually by a transaction log backup) then the alternatives really come down to adding another log file or switching to the simple recovery model (and breaking the log backup chain).

Once the crisis has passed, the second log file should be removed again. In this case, when the ALTER DATABASE was issued to drop the second log file, the error returned was:

  1.     Msg 5042, Level 16, State 2, Line 1
  2.     The file 'DBMaint2008_log2' cannot be removed because it is not empty.

Looking at log_reuse_wait_desc in sys.databases to see why the log cannot be cleared shows NOTHING.

So how can this be? Well, it could be that the currently active VLF (Virtual Log File) happens to be in the second file – there always has to be at least one active VLF. Looking at DBCC LOGINFO to see the VLF status shows the following:

FileId FileSize StartOffset FSeqNo Status Parity CreateLSN
------ -------- ----------- ------ ------ ------ ---------
2      1245184  8192        25     2      64     0
3      1245184  8192        0      0      0      0

Ah – this is the problem! The log files each only have a single VLF, and the entire log must always have at least two VLFs. This means the second log file cannot be dropped as that would leave the entire log with only a single VLF.

The trick here is to grow the first log file so that it has more than one VLF and then the second log file will be able to be dropped. If you want to know what all the DBCC LOGINFO output means, see my blog post.

But how did the database get into this state in the first place? Turns out that it’s pretty simple to engineer this case and it involves shrinking each log file when they have VLFs larger than 1MB. The script below will produce the one-VLF-per-file case I’ve described here:

  1.     USE MASTER;
  2.     GO
  4.     IF DATABASEPROPERTYEX ('DBMaint2008', 'Version') > 0
  5.         DROP DATABASE DBMaint2008;
  8.         NAME = 'DBMaint2008_data',
  9.         FILENAME = N'D:\SQLskills\DBMaint2008_data.mdf')
  10.     LOG ON (
  11.         NAME = 'DBMaint2008_log',
  12.         FILENAME = N'D:\SQLskills\DBMaint2008_log.ldf',
  13.         SIZE = 5MB,
  14.         FILEGROWTH = 1MB);
  15.     GO
  17.     ALTER DATABASE DBMaint2008
  18.     ADD LOG FILE (
  19.         NAME = 'DBMaint2008_log2',
  20.         FILENAME = N'D:\SQLskills\DBMaint2008_log2.ldf',
  21.         SIZE = 5MB,
  22.         FILEGROWTH = 1MB);
  23.     GO
  25.     USE DBMaint2008;
  26.     GO
  27.     SET NOCOUNT ON;
  28.     GO
  30.     DBCC SHRINKFILE (2, 1);
  31.     GO
  33.     DBCC SHRINKFILE (3, 1);
  34.     GO
  36.     DBCC LOGINFO (DBMaint2008);
  37.     GO


Please or Register to post comments.

What's SQL Server Questions Answered?

Practical tips and answers to many of your questions about SQL Server including database management and performance issues.


Paul S. Randal

Paul Randal worked on Microsoft's SQL Server team for nine years in development and management roles, writing many of the DBCC commands. Randal was ultimately responsible for SQL Server 2008'...

Kimberly L. Tripp

Kimberly L. Tripp has been working with SQL Server since 1990, and she’s worked as a consultant, trainer, speaker, and writer specializing in core SQL Server performance tuning and availability...
Blog Archive

Sponsored Introduction Continue on to (or wait seconds) ×