<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>vlf - Techyaz.com</title>
	<atom:link href="https://techyaz.com/tag/vlf/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Tips, Tutorials and How-to Topics</description>
	<lastBuildDate>Sun, 06 May 2018 10:20:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>

<image>
	<url>https://techyaz.com/wp-content/uploads/2017/11/cropped-Site-icon-150x150.png</url>
	<title>vlf - Techyaz.com</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Get Total Number of Virtual Log Files inside SQL Server Database Log Files?</title>
		<link>https://techyaz.com/sql-server/sql-server-administration/get-total-virtual-log-files/</link>
					<comments>https://techyaz.com/sql-server/sql-server-administration/get-total-virtual-log-files/#comments</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Fri, 28 Jul 2017 10:28:42 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Administration]]></category>
		<category><![CDATA[checkpoints]]></category>
		<category><![CDATA[log_files]]></category>
		<category><![CDATA[SQL_Server_Architecture]]></category>
		<category><![CDATA[vlf]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=285</guid>

					<description><![CDATA[<p>Today, i am going to discuss about virtual log files in SQL Server and query to find number of virtual log files present in transaction log files. Related Articles: Why Should You Always Turn Off Database Auto Shrink Property? Understand&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/sql-server-administration/get-total-virtual-log-files/">How to Get Total Number of Virtual Log Files inside SQL Server Database Log Files?</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Today, i am going to discuss about virtual log files in SQL Server and query to find number of virtual log files present in transaction log files.</p>
<p><span style="color: #800000;"><em><strong>Related Articles:</strong></em></span></p>
<ul>
<li><strong><a href="https://techyaz.com/sql-server/always-turn-off-database-auto-shrink/" target="_blank" rel="noopener">Why Should You Always Turn Off Database Auto Shrink Property?</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/understanding-database-autogrowth-sql-server/" target="_blank" rel="noopener">Understand the Best Value for Database File Autogrowth Setting</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/checkpoint/" target="_blank" rel="noopener">What is Checkpoint Process in SQL Server?</a></strong></li>
</ul>
<h3><span style="color: #000080;"><strong>Virtual Log File</strong></span></h3>
<p>As we know <a href="https://techyaz.com/sql-server/understanding-transaction-log-architecture/" target="_blank" rel="noopener"><strong>Transaction Log Files</strong></a> internally divided in to small virtual log files. Virtual Log Files also referred as VLF/VLFs. The size or number of virtual log files cannot be configured by administrators but it can be affected by number of reasons.</p>
<p>One of the reason is creating or extending log files. The size of the virtual files after a log file has been extended is the sum of the size of the existing log and the size of the new file increment. Here I will show you how VLFs will be increase when we add a new log file or increase the size of transaction log file.</p>
<p>Having large no. of virtual log files are not a good sign and can affect the performance of backup, restore and database startups. Large numbers means close to thousand or more than thousand vlfs. You will not see any visible impact if you have approx. few hundred vlfs.  I would suggest you to read <a href="https://techyaz.com/sql-server/understanding-transaction-log-architecture/" target="_blank" rel="noopener"><strong>Transaction Log File Architecture</strong></a> to understand more about this.</p>
<p>We can reduce the number of virtual log files by either Backup the Transaction Log of the database or by shrinking the Transaction Log as much as possible using DBCC SHRINKFILE.  Make sure to do this exercise during a maintenance window.</p>
<h3><span style="color: #000080;"><strong>How to Find Total Number of Virtual Log Files?</strong></span></h3>
<p>Now, I will explain how to get total number of virtual log files (VLF/VLFs) for each database on your SQL Server instance. Microsoft has introduced new DMF to monitor, alert, and avert potential transaction log issues in SQL Server 2017. Earlier we were using DBCC LOGINFO to get such information but now we can get in depth information to deal with transaction log queries with the help of this DMF.</p>
<p>The new DMF is <strong>sys.dm_db_log_info</strong> that will returns VLF information of the transaction log files.  If we will specify NULL or DEFAULT value, it will return VLF information of the current database. The built-in function DB_ID can also be specified to get details of a particular database. The sys.dm_db_log_info DMF replaces the DBCC LOGINFO statement from earlier versions.</p>
<p>Below script will show you <strong>total no. of virtual log Files for all databases</strong> hosted on a SQL Server Instance.</p>
<div class="codediv">
<pre><strong><span style="color: #0000ff;">SELECT name, count(d.database_id) as "Total_VLF_Count" from sys.databases sd
cross apply sys.dm_db_log_info(sd.database_id) d
group by name
</span></strong></pre>
</div>
<p><img fetchpriority="high" decoding="async" class="aligncenter size-full wp-image-290" src="http://techyaz.com/wp-content/uploads/2017/07/1-total-no-of-vlfs-for-all-db.jpg" alt="total no of vlfs for all db" width="783" height="294" srcset="https://techyaz.com/wp-content/uploads/2017/07/1-total-no-of-vlfs-for-all-db.jpg 783w, https://techyaz.com/wp-content/uploads/2017/07/1-total-no-of-vlfs-for-all-db-300x113.jpg 300w, https://techyaz.com/wp-content/uploads/2017/07/1-total-no-of-vlfs-for-all-db-768x288.jpg 768w" sizes="(max-width: 783px) 100vw, 783px" /></p>
<p>We can see the total no. of VLFs in each database. Now we can create a new database and check the VLF count. I have created a new database “Techyaz” and see the database file details.</p>
<div class="codediv">
<pre><strong><span style="color: #0000ff;">Create database Techyaz
GO
sp_helpdb techyaz
</span></strong></pre>
</div>
<p><img decoding="async" class="aligncenter size-full wp-image-291" src="http://techyaz.com/wp-content/uploads/2017/07/2-create-db-techyaz-sp_helpdb.jpg" alt="Create db and check files" width="906" height="397" srcset="https://techyaz.com/wp-content/uploads/2017/07/2-create-db-techyaz-sp_helpdb.jpg 906w, https://techyaz.com/wp-content/uploads/2017/07/2-create-db-techyaz-sp_helpdb-300x131.jpg 300w, https://techyaz.com/wp-content/uploads/2017/07/2-create-db-techyaz-sp_helpdb-768x337.jpg 768w" sizes="(max-width: 906px) 100vw, 906px" /></p>
<p>Now again check the total no. of VLFs by running same command which I have executed in step 1. We can see total no. of vlfs are 4 for techyaz database.</p>
<p><img decoding="async" class="aligncenter size-full wp-image-292" src="http://techyaz.com/wp-content/uploads/2017/07/3-total-vlfs-apost-techyaz-dbcreation.jpg" alt="total vlf count post techyaz db creation" width="758" height="329" srcset="https://techyaz.com/wp-content/uploads/2017/07/3-total-vlfs-apost-techyaz-dbcreation.jpg 758w, https://techyaz.com/wp-content/uploads/2017/07/3-total-vlfs-apost-techyaz-dbcreation-300x130.jpg 300w" sizes="(max-width: 758px) 100vw, 758px" /></p>
<p>Now I will increase the size of the log file and see the impact of vlf count. Run below command to increase the size of log file.</p>
<div class="codediv">
<pre><strong><span style="color: #0000ff;">USE master;
GO
ALTER DATABASE Techyaz
MODIFY FILE
(NAME = techyaz_log,
SIZE = 15MB);
</span></strong></pre>
</div>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-293" src="http://techyaz.com/wp-content/uploads/2017/07/4-Increase-file-size-of-techyaz.jpg" alt="Increase the file size by 15 MB" width="472" height="275" srcset="https://techyaz.com/wp-content/uploads/2017/07/4-Increase-file-size-of-techyaz.jpg 472w, https://techyaz.com/wp-content/uploads/2017/07/4-Increase-file-size-of-techyaz-300x175.jpg 300w" sizes="auto, (max-width: 472px) 100vw, 472px" /></p>
<p>Now again see the no. of vlfs for each database and here we can see, total no. of vlfs have been increase to 8 now.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-294" src="http://techyaz.com/wp-content/uploads/2017/07/5-total-vlfs-post-size-increase.jpg" alt="total vlfs post increasing the size of log file" width="759" height="339" srcset="https://techyaz.com/wp-content/uploads/2017/07/5-total-vlfs-post-size-increase.jpg 759w, https://techyaz.com/wp-content/uploads/2017/07/5-total-vlfs-post-size-increase-300x134.jpg 300w" sizes="auto, (max-width: 759px) 100vw, 759px" /></p>
<p>Similarly we can notice the impact of vlf if we add another log file on this database. Run below command to add a log file to the database Techyaz. I kept the size of this log file is 5MB.</p>
<div class="codediv">
<pre><strong><span style="color: #0000ff;">ALTER DATABASE Techyaz
ADD LOG FILE 
(
    NAME = techyaz_log3,
    FILENAME = '/var/opt/mssql/data/Techyaz_log3.ldf',
    SIZE = 5MB,
    MAXSIZE = 100MB,
    FILEGROWTH = 5MB
)
</span></strong></pre>
</div>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-295" src="http://techyaz.com/wp-content/uploads/2017/07/6-add-log-file-to-techyaz.jpg" alt="Add Log File to techyaz db" width="800" height="318" srcset="https://techyaz.com/wp-content/uploads/2017/07/6-add-log-file-to-techyaz.jpg 800w, https://techyaz.com/wp-content/uploads/2017/07/6-add-log-file-to-techyaz-300x119.jpg 300w, https://techyaz.com/wp-content/uploads/2017/07/6-add-log-file-to-techyaz-768x305.jpg 768w" sizes="auto, (max-width: 800px) 100vw, 800px" /></p>
<p>Check and verify the newly added log file by running sp_helpdb command.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-296" src="http://techyaz.com/wp-content/uploads/2017/07/7-sp_helpdb-techyaz.jpg" alt="check and verify newly added files" width="908" height="330" srcset="https://techyaz.com/wp-content/uploads/2017/07/7-sp_helpdb-techyaz.jpg 908w, https://techyaz.com/wp-content/uploads/2017/07/7-sp_helpdb-techyaz-300x109.jpg 300w, https://techyaz.com/wp-content/uploads/2017/07/7-sp_helpdb-techyaz-768x279.jpg 768w" sizes="auto, (max-width: 908px) 100vw, 908px" /></p>
<p>Check again the total vlf count for this database. Here we can see the total no of vlfs are now 12 in this database. So it is proved that vlf counts are increased if we increase the size of log file as well as we add another log file to the database.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-297" src="http://techyaz.com/wp-content/uploads/2017/07/8-total-vlfs-post-file-addition.jpg" alt="Total VLF post adding log file" width="893" height="329" srcset="https://techyaz.com/wp-content/uploads/2017/07/8-total-vlfs-post-file-addition.jpg 893w, https://techyaz.com/wp-content/uploads/2017/07/8-total-vlfs-post-file-addition-300x111.jpg 300w, https://techyaz.com/wp-content/uploads/2017/07/8-total-vlfs-post-file-addition-768x283.jpg 768w" sizes="auto, (max-width: 893px) 100vw, 893px" /></p>
<p>This DMF is also useful in getting filtered output like which database have a specified no of vlf counts and what all databases that have less or more no of vlf counts of a specified value.</p>
<p>Run below command to get the name of databases which has more than 10 virtual log files. You can change the 10 value to 100 or 1000 or 10000. It is up to your requirement.</p>
<div class="codediv">
<pre><strong><span style="color: #0000ff;">SELECT name, count(d.database_id) as "Total_VLF_Count" from sys.databases sd
cross apply sys.dm_db_log_info(sd.database_id) d
group by name
having count(d.database_id)&gt;10
</span></strong></pre>
</div>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-298" src="http://techyaz.com/wp-content/uploads/2017/07/9-db-having-total-vlf-more-than10.jpg" alt="Databases that have more VLFs than specified value" width="797" height="306" srcset="https://techyaz.com/wp-content/uploads/2017/07/9-db-having-total-vlf-more-than10.jpg 797w, https://techyaz.com/wp-content/uploads/2017/07/9-db-having-total-vlf-more-than10-300x115.jpg 300w, https://techyaz.com/wp-content/uploads/2017/07/9-db-having-total-vlf-more-than10-768x295.jpg 768w" sizes="auto, (max-width: 797px) 100vw, 797px" /></p>
<p>We can see only one database has more than 10 vlfs that is techyaz which we just created. Similarly we can check about the db names which has less than 10 VLFs by running same command, just change the condition of greater than to less than.</p>
<div class="codediv">
<pre><strong><span style="color: #0000ff;">SELECT name, count(d.database_id) as "Total_VLF_Count" from sys.databases sd
cross apply sys.dm_db_log_info(sd.database_id) d
group by name
having count(d.database_id)&lt;10
</span></strong></pre>
</div>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-299" src="http://techyaz.com/wp-content/uploads/2017/07/10-db-having-total-vlf-less-than10.jpg" alt="DBs having less than 10 VLFs" width="789" height="386" srcset="https://techyaz.com/wp-content/uploads/2017/07/10-db-having-total-vlf-less-than10.jpg 789w, https://techyaz.com/wp-content/uploads/2017/07/10-db-having-total-vlf-less-than10-300x147.jpg 300w, https://techyaz.com/wp-content/uploads/2017/07/10-db-having-total-vlf-less-than10-768x376.jpg 768w" sizes="auto, (max-width: 789px) 100vw, 789px" /></p>
<p>Below is the view of all columns we can see of this DMF. This is very useful DMF and we can get all information as given below. I ran this command for database Techyaz. We can get the db id of this database from step 2 that is 6. We can also see one row for each VLF in the output as this database has 12 VLF so there are 12 rows here along with the details of each VLF.</p>
<div class="codediv">
<pre><strong><span style="color: #0000ff;">SELECT * from sys.dm_db_log_info(6)
</span></strong></pre>
</div>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-300" src="http://techyaz.com/wp-content/uploads/2017/07/11-sp_dm_db_log_info.jpg" alt="sys.dm_db_log_info output" width="1316" height="449" srcset="https://techyaz.com/wp-content/uploads/2017/07/11-sp_dm_db_log_info.jpg 1316w, https://techyaz.com/wp-content/uploads/2017/07/11-sp_dm_db_log_info-300x102.jpg 300w, https://techyaz.com/wp-content/uploads/2017/07/11-sp_dm_db_log_info-768x262.jpg 768w, https://techyaz.com/wp-content/uploads/2017/07/11-sp_dm_db_log_info-1024x349.jpg 1024w" sizes="auto, (max-width: 1316px) 100vw, 1316px" /></p>
<p>We can focus on two columns i.e. <strong>vlf_active</strong> which is 1 for first vlf and 0 for all that means it indicates whether VLF is in use or not. 0 means vlf is not in use and 1 means vlf is active so we can see only one vlf is active for this database.</p>
<p>Another is <strong>vlf_status</strong>, it indicate status of the VLF. Possible values include</p>
<p>0 &#8211; vlf is inactive<br />
1 &#8211; vlf is initialized but unused<br />
2 &#8211; vlf is active.</p>
<p>As we know this DMV is the replacement of DBCC LOGINFO so we can compare the output of both. Now run DBCC LOGINFO as see the details for database Techyaz.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-301" src="http://techyaz.com/wp-content/uploads/2017/07/12-dbcc-loginfo.jpg" alt="DBCC LOGINFO output" width="806" height="455" srcset="https://techyaz.com/wp-content/uploads/2017/07/12-dbcc-loginfo.jpg 806w, https://techyaz.com/wp-content/uploads/2017/07/12-dbcc-loginfo-300x169.jpg 300w, https://techyaz.com/wp-content/uploads/2017/07/12-dbcc-loginfo-768x434.jpg 768w" sizes="auto, (max-width: 806px) 100vw, 806px" /></p>
<p>I hope you like this article. Please follow us on our <a href="https://www.facebook.com/Techyaz/">facebook page</a> and on <a href="https://twitter.com/Tech_yaz">Twitter </a>handle to get latest updates.</p>
<p><span style="color: #800000;"><em><strong>Read More:</strong></em></span></p>
<ul>
<li><strong><a href="https://techyaz.com/interview-questions/sql-server-interview-questions-answers-architecture/" target="_blank" rel="noopener">SQL Server Architecture Interview Questions &amp; Answers</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/troubleshooting/manage-transaction-log-file-during-data-load/" target="_blank" rel="noopener">Manage Transaction Log File during Data Load</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/improve-sql-server-bulk-data-import-performance/" target="_blank" rel="noopener">How to Improve Bulk Data Load Performance?</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/troubleshooting/fix-error-1105/" target="_blank" rel="noopener">Fix SQL Server Error 1105: Could Not Allocate Space for Object in Database because the Filegroup is Full</a></strong></li>
</ul>
<p>&nbsp;</p>
<p>The post <a href="https://techyaz.com/sql-server/sql-server-administration/get-total-virtual-log-files/">How to Get Total Number of Virtual Log Files inside SQL Server Database Log Files?</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/sql-server-administration/get-total-virtual-log-files/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
