![]() |
|
|
|
By: Thomas LaRock | Read Comments (7) | Related Tips: 1 | 2 | 3 | 4 | More > Policy Based Management |
Problem
SQL Server splits your physical transaction log file into logical chucks, called virtual log files (VLF). While your transaction log file may look like one file, logically it is fragmented and the level of fragmentation can result in performance degradation. You can take action to correct the situation, but first you need to know if the situation exists In this tip I will walk you through how to identify this issue.
Solution
You can use Policy Based Management (PBM) to determine which databases currently have extensive VLF fragmentation. The creation of a policy will allow for you to quickly and easily scan all databases in your enterprise.
Inside of SSMS, navigate to the policies folder, right-click, and select 'New Policy...'.

In the name field enter in 'T-Log VLF Check Policy', then click on the arrow in the Check condition dropdown and select 'New condition...':

In the name field enter 'T-Log VLF Check Condition'. For the Facet select 'Database', then click on the ellipses next to the 'Field' dropdown.

Here is where the magic will happen. Cut and paste the following code into the 'Cell value':
ExecuteSql('Numeric', '
create table #tmp (FileID varchar(3), FileSize numeric(20,0),
StartOffset bigint, FSeqNo bigint, Status char(1),
Parity varchar(4), CreateLSN numeric(25,0))
insert into #tmp
EXEC (''dbcc loginfo'')
select COUNT(*) from #tmp
drop table #tmp
')
|
Click 'OK'

Then set the Value field to be 50, the Operator to be less than or equal to, and click OK again.

Make certain the check box for every database is enabled, and click OK again.

Your policy is created, next up is to evaluate, right click on the policy and select Evaluate:


Click Evaluate, then Run if you get prompted (again) about your policy containing a script. Any databases with more than 50 VLF’s will be flagged.
Result
Here is a screenshot of a sample result set returned by the policy.

Next Steps
| Tuesday, February 09, 2010 - 2:48:48 PM - shamri | Read The Tip |
|
Hi, There is a difference between managing the VLFs in SQL 2000 and SQL2005+, and the article seems to confond the two. In SQL 2000, it's more important to have reduce the number of the VLFs, but in SQL2005+ it seems that the problem of high number of VLFs was resolved by putting, maybe always, the active VLFs on the TOP of the log file. I hope that will help to better understand the problem of high number of VLFs in SQL2000 and SQL2005+ Soufiane Hamri.
|
|
| Tuesday, February 09, 2010 - 3:44:31 PM - dhay1999 | Read The Tip |
|
Thanks Mr LaRock! Who knew that logfiles can get fragmented! Imagine my suprise when a number of my databases had in a few cases thousands of VLFs, most in the hundreds. This hack will generate the needed script to "defragment" your log files. This assumes all databases are in simple mode, each database has only one log file. It has been tested on sql 2000 sp4. Open to suggestions/improvements! create table #tmp1 ( create table #tmp2 ( Create table #tmp3 ( insert into #tmp1
delete from #tmp3 where usage<>'log only' select drop table #tmp1
|
|
| Tuesday, February 09, 2010 - 4:01:36 PM - shamri | Read The Tip |
|
Hi, What if the script was applyed to SQL2005+ databases? Can the VLFs really be fragmented within the log file? Thanks in advance for your response, if any? Soufiane. |
|
| Tuesday, February 09, 2010 - 4:32:14 PM - dhay1999 | Read The Tip |
|
Soufiane, Since the post centered on SQL 2008 and policy based management, my answer would be yes, it would apply to SQL 2005 as well. I don't have any sql 2005 boxes to test my script on, but it is based in part on Kimberly Trip's blog post that Mr. LaRock linked to at the bottom of his post. Not that the top of her post it says to read it carefully! As always test it on development servers. If you think it's an issue and the technical advice given in these posts is over your head it might be worth your while to get an expert to come in for a day and help. Kimberly's post: http://www.sqlskills.com/BLOGS/KIMBERLY/post/8-Steps-to-better-Transaction-Log-throughput.aspx
|
|
| Tuesday, February 09, 2010 - 4:53:22 PM - shamri | Read The Tip |
|
Hi, Thanks for your response, but you know that the article of M. Kimberlly is based on SQL2000. The management of the VLFs is different in SQL2005+. I read this article from Microsoft: http://support.microsoft.com/kb/907511 Have a nice day. Soufiane.
|
|
| Tuesday, February 09, 2010 - 5:56:21 PM - dhay1999 | Read The Tip |
|
Thanks! Good luck then, seems like you have it covered. |
|
| Monday, April 30, 2012 - 9:41:25 AM - alzdba | Read The Tip |
|
FYI with sql2012 the layout of the result set of DBCC loginfo changed. create table #tmp ( RecoveryUnitId bigint /* new with SQL2012 */
|
|
|
privacy | disclaimer | copyright | advertise | about authors | contribute | feedback | giveaways | user groups Some names and products listed are the registered trademarks of their respective owners. Edgewood Solutions LLC | MSSharePointTips.com | MSSQLTips.com |