Microsoft SQL Server: The Transaction Log and why you should care about VLF’s<br />Level 400<br />Presented By:<br />Steph...
<ul><li>SQL DBA with Nedbank Ltd.</li></ul>Managing large SQL environment.<br />Large scale migrations, consolidated envir...
Blogger at lessthandot.com</li></ul>SQLArcher<br />About Me<br />
<ul><li>What is a transaction log?
One or many, does it make a difference?
Can the T-Log be optimized? Diving into the colourful world of Virtual Log Files.
Demo
Resources/Links</li></ul>Overview:<br />
The transaction log, or T-Log, is a record of all transactions happening to the database. All these transactions are actua...
Start and end of each transaction.
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...
Unlike TempDB which benefits from having multiple data files, the T-Log does not; it only serves as redundancy. The T-Log ...
Upcoming SlideShare
Loading in...5
×

Microsoft SQL Server Log Management

1,229
-1

Published on

A deep dive into Virtual Log Files that make up a SQL Server log file. It also shows the effects of auto growth and the size of the individual VLF\'s on performance.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,229
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • 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

    1. 1. 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 />
    2. 2. <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
    3. 3. Blogger at lessthandot.com</li></ul>SQLArcher<br />About Me<br />
    4. 4. <ul><li>What is a transaction log?
    5. 5. One or many, does it make a difference?
    6. 6. Can the T-Log be optimized? Diving into the colourful world of Virtual Log Files.
    7. 7. Demo
    8. 8. Resources/Links</li></ul>Overview:<br />
    9. 9. 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).
    10. 10. Start and end of each transaction.
    11. 11. Every data modification(insert, update, delete) including system SP’s, DDL statements to any table including system tables.
    12. 12. Every extent and page allocation and de-allocation.
    13. 13. Creating or dropping tables and indexes.</li></ul>What is a transaction log?<br />
    14. 14. 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 />
    15. 15. 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 />
    16. 16. 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 />
    17. 17. Deep Diving into VLF’s<br />
    18. 18. 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
    19. 19. >= 64MB < 1GB = 8 VLF’s
    20. 20. > 1GB = 16VLF’s
    21. 21. 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 />
    22. 22. VLF’s (continued)<br />
    23. 23. 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 />
    24. 24. Live Demo<br />
    25. 25. Comparison<br />
    26. 26. 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 />
    27. 27. 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 />
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×