Sql-server – Transaction log backup file larger than expected

backupsql serversql-server-2008-r2

I've recently taken over a SQL Server database that didn't have any transaction log backup routine running for at least 2 years. The first log backup was very large (3.8 gb on a 1.14 gb database) as you would predict, however subsequent log backups are still larger than I would have expected (somewhere in the region of 3 mb).

I also restored the database to a QA and ran several sequential log backups without there being any activity on the database and the log file backups were still ~3 mb.

What would account for the size and consistency of the transaction log backups with nominal activity on the database itself?

EDIT:

Here is the script we're using to run the TLOG backups, this is being executed every 10 minutes:

BACKUP LOG [mydatabase] 
TO  DISK = @fullpath 
WITH  RETAINDAYS = 2
    , NOFORMAT
    , NOINIT
    , NAME = @bckName
    , SKIP
    , REWIND
    , NOUNLOAD
    , STATS = 10;

Best Answer

Having spent some time looking at this in more detail it would appear that the unusually large transaction log backups are due to excessive internal fragmentation of the transaction log itself. This is due to unrestricted autogrowth of the transaction log over a long period of time.

The following excerpt from a SQLSkills.com article more precisely defines the problem

Often, when transaction logs are not pre-allocated and/or when there's been a lot of autogrowths, the transaction log can become internally fragmented. Internally your transaction logs are broken down into smaller more granular chunks called VLFs (Virtual Log Files). The size and number of VLFs you'll have depends largely on the size that the chunk is when it's added to you transaction log. If you add a new chunk to the transaction log which is 20MB (through autogrowth or through manual growth) then the number of VLFs that are added is 4. If you add a chunk which is greater than 64MB but less than or equal to 1GB, you'll add 8 VLFs. If you add more than 1GB then you'll add 16VLFs. In general, most transaction logs will only have 20 or 30 VLFs – even 50 could be reasonable depending on the total size of the transaction log. However, in many cases what happens is that excessive autogrowths can cause an excessive number of VLFs to be added – sometimes resulting in hundreds of VLFs. Having an excessive number of VLFs can negatively impact all transaction log related activities and you may even see degradation in performance when transaction log backups occur. To see how many VLFs you have solely look at the number of rows returned by DBCC LOGINFO. The number of rows returned equals the number of VLFs your transaction log file has. If you have more than 50, I would recommend fixing it and adjusting your autogrowth so that it doesn't occur as fequently. To get rid of all of the execessive VLFs, follow these easy steps to shrink off the fragmented chunk and add a new, clean chunk to your transaction log.

On this particular database it turns out we had 3011 VLFs, some degree over the recommended limit of 50 :)

We are now working through the steps in the above guide to reduce the number of internal VLFs. The QA database has been shrunk and the start size set to 2.5 gb, we now have 23 internal VLFs. So the resulting TLOG backup is in the region of 128 kb.