Modifications are made to a copy of the page in the buffer cache.Modifications are not written to disk until a checkpoint occurs, or the modification is made to disk when the buffer needs to hold a new page.Pages modified in the buffer cache, but not yet written to disk is called dirty pages.When a modification occurs on a page in the buffer cache, the associated log record is built in the log cache.The log must be written to disk before the dirty page is written to disk.If a dirty page is flushed before the log record is written, the modification made cannot be rolled back if the server fails before the log is written to disk.
T1, T2 and T3.T1 will be written to and filled before moving to T2.When writes happen to T2, and T1 clears, then all new transactions will start again in T1.This is because a T-Log consist of multiple Virtual Log Files which gets filled (and created) sequentially. More on that later.
Microsoft SQL Server Log Management
Microsoft SQL Server: The Transaction Log and why you should care about VLF’s<br />Level 400<br />Presented By:<br />Stephan Lawson<br />SQL DBA<br />
<ul><li>SQL DBA with Nedbank Ltd.</li></ul>Managing large SQL environment.<br />Large scale migrations, consolidated environments.<br />Performance Tuning and Optimization.<br /><ul><li>MCITP: SQL Server 2008
Blogger at lessthandot.com</li></ul>SQLArcher<br />About Me<br />
The transaction log, or T-Log, is a record of all transactions happening to the database. All these transactions are actually first written to the log, and then after a checkpoint, is written to the data file via the lazy writer.<br />Main use:<br /><ul><li>Point in time recovery ( full recovery model).
Every data modification(insert, update, delete) including system SP’s, DDL statements to any table including system tables.
Every extent and page allocation and de-allocation.
Creating or dropping tables and indexes.</li></ul>What is a transaction log?<br />
SQL Server uses a write-ahead log, this guarantees that no data modifications is written to the disk before the associated log record is written to disk. This maintains the ACID properties of a transaction.<br />So this is how it works:<br />How does it work?<br />
Unlike TempDB which benefits from having multiple data files, the T-Log does not; it only serves as redundancy. The T-Log is written to sequentially and in a round-robin fashion.<br />Example; you create 3 T-logs for a database:<br />One or many, does it matter?<br />T1<br />T2<br />T3<br />
The T-Log is one of the things we overlook to optimize. Yes, put the log on separate SAN or SSD’s in a RAID 1+0 or 0+1 and give it a 100MB growth rate because that is better than 1MB. But why does 100MB perform better than 1MB? Do we ever look at how VLF’s affect our performance?<br />Short answer; No.<br />Can the T-Log be optimized?<br />
As previously mentioned, VLF’s is what makes up the T-Log. They are individual Virtual Logs that get created with each auto grow or manual grow. By default, a T-Log will have 2 VLF’s when created. And depending on the auto grow size, it will create a various amount of VLF’s as follows:<br /><ul><li>< 64MB = 4VLF’s
Note that SQL 2005, 2008 and 2008 R2 has a bug where growing the T-Log in increments exactly 4Gb/8GB increments fail. It is best to grow the T-Log by 8000MB. This bug is fixed in SQL 11 which I’ll be using in the demo.</li></ul>VLF’s<br />
So how do we look at the VLF’s? We use the following command:<br />DBCC LOGINFO(DB_NAME)<br />This command is undocumented but is safe to run as it only reads the T-Log. Important columns to look for is the following:<br />FileSize – VLF size in bytes<br />Status – 0 Not in use, 2 In use<br />CreateLSN – This can be used to determine how many VLF’s was created in a log file growth, 4, 8 or 16. This also indicates the Log Sequence Number.<br />VLF Usage<br />
The log file is not Pandora’s Box.<br />Monitoring, and optimizing the log file does have its benefits:<br />Faster query execution.<br />Faster indexing.<br />Summary<br />
The following sites provide useful info on T-Logs and VLF’s:<br />Both Paul and Kimberly has more in-depth articles on T-Log internals.<br />http://www.sqlskills.com/blogs.asp<br />T-Log architecture.<br />http://msdn.microsoft.com/en-us/library/ms179355.aspx<br />Resources<br />