<?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>log_files - Techyaz.com</title>
	<atom:link href="https://techyaz.com/tag/log_files/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Tips, Tutorials and How-to Topics</description>
	<lastBuildDate>Fri, 01 Jun 2018 12:42:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8</generator>

<image>
	<url>https://techyaz.com/wp-content/uploads/2017/11/cropped-Site-icon-150x150.png</url>
	<title>log_files - Techyaz.com</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Fix Error 1101: Could not allocate a new page for database</title>
		<link>https://techyaz.com/sql-server/troubleshooting/fix-error-1101-could-not-allocate-a-new-page-for-database/</link>
					<comments>https://techyaz.com/sql-server/troubleshooting/fix-error-1101-could-not-allocate-a-new-page-for-database/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Fri, 23 Mar 2018 13:20:48 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Administration]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[autogrow]]></category>
		<category><![CDATA[autogrowth setting]]></category>
		<category><![CDATA[data file autogrow]]></category>
		<category><![CDATA[data_files]]></category>
		<category><![CDATA[database property]]></category>
		<category><![CDATA[log space]]></category>
		<category><![CDATA[log_files]]></category>
		<category><![CDATA[space issues]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=1987</guid>

					<description><![CDATA[<p>We get error 1101 because of space issues. Database engine doesn’t able to allocate new pages to the database because of insufficient disk space. The error details are given below: Error: 1101, Severity: 17, State: 2 Could not allocate a&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/troubleshooting/fix-error-1101-could-not-allocate-a-new-page-for-database/">Fix Error 1101: Could not allocate a new page for database</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>We get error 1101 because of space issues. Database engine doesn’t able to allocate new pages to the database because of insufficient disk space. The error details are given below:</p>
<p><em><span style="color: #ff0000;">Error: 1101, Severity: 17, State: 2</span></em><br />
<em><span style="color: #ff0000;"> Could not allocate a new page for database ‘DBNAME&#8217; because of insufficient disk space in filegroup &#8216;PRIMARY&#8217;. Create the necessary space by dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.</span></em></p>
<p>There is another error 1105 that is also very much like above error code. Error 1105 can also be fixed using same solution given in this article.</p>
<h3><span style="color: #333399;">Error 1101 &#8211; Root Cause</span></h3>
<p>Main reason behind error 1101 or error 1105 is the insufficient disk space in filegroup/files. You might also get this error if your database drives are running out of space. There are multiple reasons that can cause this error to generate. Some of them are given below.</p>
<ul>
<li>You have restricted database maximum file size or put size limits for files.</li>
<li>Database file drives are running out of space.</li>
<li>Autogrowth is not enabled for database files.</li>
</ul>
<h3><span style="color: #333399;">Solutions</span></h3>
<p>To fix this issue we need to make space for database files to grow. Issue might vary depending on the nature of issue mentioned in above section. Sometimes, you might face this issue if maximum size for database files are restricted to some values so whenever database will grow to that point, SQL Server will not allow to allocate any page to that database. Sometimes you might get error 1101 because you don’t have any space on your database drives. Here, I will discuss each case individually and its solution to fix it.</p>
<h5><span style="color: #993300;">Unrestrict or Increase Database File Size Limits</span></h5>
<p>You might have enough space in your database drives but still you can get error 1101 because the maximum file size of database files is limited to some value and that causes not to grow your database beyond that size. You can unrestrict or increase the existing value of maximum file size to some bigger value. We have also an option to set database file size to unlimited size value that means database file will grow till the database file drive limit. Make sure to set appropriate autogrowth size for each database files.</p>
<p>You can set unlimited file size option or increase the value of maximum file size using GUI in SQL Server Management Studio or using ALTER statement.</p>
<ul>
<li>Connect to Database Instance in <strong>SQL Server Management Studio</strong>. Expand <strong>Database</strong> folder.</li>
<li>Right Click on your database and choose <strong>Property window</strong>.</li>
<li>Click on <strong>Files</strong> tab from left side pane in database property window.</li>
<li>Here you can see all database files. Now you can click on three dots given next of database files in “Autogrowth/Maxsize” column. You can see max size is set to a limited value as shown in below screenshot. I have chosen unlimited option and clicked on Ok button.</li>
</ul>
<p><img fetchpriority="high" decoding="async" class="aligncenter wp-image-1991 size-full" src="http://techyaz.com/wp-content/uploads/2018/03/1-SizeLimit-min.jpg" alt="Set Database file size to unlimited" width="394" height="314" srcset="https://techyaz.com/wp-content/uploads/2018/03/1-SizeLimit-min.jpg 394w, https://techyaz.com/wp-content/uploads/2018/03/1-SizeLimit-min-300x239.jpg 300w" sizes="(max-width: 394px) 100vw, 394px" /></p>
<p>Now we will not get any issue if our database drive has enough space.</p>
<h5><span style="color: #993300;">Space in Database Drives</span></h5>
<p>Another possibility for this error is, there might be possibility that your drives on which you have placed your database files are running out of space. If this is the case then you have below 4 options.</p>
<ul>
<li>Add additional database file to different disk where there is enough space.</li>
<li>Move additional/unwanted files from your existing database drives.</li>
<li>Drop/Purge or Move unwanted data (table/indexes)</li>
<li>Add Additional Disk Space</li>
</ul>
<p>Immediate fix of this issue is to add new database file to another drive where you have enough space to run your transactions. You can use below command to add addition database file to another disk.</p>
<pre><strong><span style="color: #0000ff;">USE [master]</span></strong>
<strong><span style="color: #0000ff;">GO</span></strong>
<strong><span style="color: #0000ff;">ALTER DATABASE [DBNAME]</span></strong>
<strong><span style="color: #0000ff;">ADD FILE (NAME = N'NewFileName', FILENAME = N'F:\mssql\data\newdatafile.ndf', SIZE = 100096KB, FILEGROWTH = 10240KB)</span></strong>
<strong><span style="color: #0000ff;">TO FILEGROUP [SECONDARY]</span></strong>
<strong><span style="color: #0000ff;">GO</span></strong></pre>
<p>You can also add new database file in SQL Server Management Studio by launching Database Property Window. Select Files from left side pane and Click on “Add” button showing in below screenshot. Make sure to set autogrowth value carefully for any database file. Also it is recommended to enable IFI – Instant File Initialization to speed up autogrowth process for your databases. Refer to below article to get best value for autogrowth for your database files. You can also read what are the benefits and how to enable IFI &#8211; Instant File Initialization in below article.</p>
<ul>
<li><strong><a href="http://techyaz.com/sql-server/understanding-database-autogrowth-sql-server/" target="_blank" rel="noopener">What Should be the Best Value for database Autogrowth settings?</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/instant-file-initialization-enable-on-sql-server-instance/" target="_blank" rel="noopener">How to Enable Instant File Initialization in SQL Server?</a></strong></li>
</ul>
<p><img decoding="async" class="aligncenter wp-image-1993 size-full" src="http://techyaz.com/wp-content/uploads/2018/03/2-SizeLimit.jpg" alt="Add database file using GUI" width="705" height="633" srcset="https://techyaz.com/wp-content/uploads/2018/03/2-SizeLimit.jpg 705w, https://techyaz.com/wp-content/uploads/2018/03/2-SizeLimit-300x269.jpg 300w" sizes="(max-width: 705px) 100vw, 705px" /></p>
<p>You can also have a look at the existing database drives whether there is any unwanted files or older backup files (*.bak) are not stored. Sometimes we run backups into database drives and forgot to delete or move them. Make sure to drop or move all unwanted files to some other location. Database drives should have only database files.</p>
<p>Final and long-term solution is the data purging. Identify the database objects that are not needed and then plan the data removal or data purging process to make space on your database.</p>
<p>We also have an option to extend the database drives as per the data growth. Make sure to plan this activity carefully before deploying it on production servers.</p>
<h5><span style="color: #993300;">Enable Autogrowth</span></h5>
<p>I have already written an article on Database autogrowth property setting. Read attached article to <a href="http://techyaz.com/sql-server/understanding-database-autogrowth-sql-server/" target="_blank" rel="noopener">find out best value for Autogrowth settings</a>.</p>
<p>You might get error 1101 if you have not enabled authogrowth setting for your database files. You need to enable it by launching database property window. You can click on three dots next to each database files in column “Authogrowth/Maxsize” and click at the enable authogrowth checkbox as showing in below screenshot.</p>
<p><img decoding="async" class="size-full wp-image-1994 aligncenter" src="http://techyaz.com/wp-content/uploads/2018/03/3-Autogrowth-min.jpg" alt="Enable Autogrowth" width="701" height="631" srcset="https://techyaz.com/wp-content/uploads/2018/03/3-Autogrowth-min.jpg 701w, https://techyaz.com/wp-content/uploads/2018/03/3-Autogrowth-min-300x270.jpg 300w" sizes="(max-width: 701px) 100vw, 701px" /></p>
<p>You can also use ALTER statement to enable database autogrowth setting for your database file. Remember, you need to run this ALTER statement for each database file separately.</p>
<p>Run below ALTER command to enable autogrowth for database file.</p>
<pre><span style="color: #008000;"><strong>--Pass logical filename of your database file for under NAME section.</strong></span>
<span style="color: #0000ff;"><strong>ALTER DATABASE [Techyaz] MODIFY FILE ( NAME = N'Techyaz_Data', FILEGROWTH = 10000KB )</strong></span></pre>
<p>Make sure to enable Instant File Initialization to speedup autogrowth operations. Links to enable Instant File Initialization is attached in this article.</p>
<p>If you are facing this issue for tempdb database then you can consider one more option apart from all of the above options. And this option is to restart SQL Server service if it&#8217;s allowed. Keep in mind, SQL Server service restart will cause an outage for few minutes but it will create new tempdb files with initial size and error 1101 will be disappeared. This is not recommended solution because of outage so you should work on long terms solutions.</p>
<p>You can also use above solutions to fix error 1105 that is very much similar to error 1101. I hope you like this article. Please follow our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <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="http://techyaz.com/sql-server/troubleshooting/fix-msg-5144-and-5145-for-long-or-failed-autogrow/" target="_blank" rel="noopener">Fix Error 5144 and Error 5145 for Long or Failed Autogrow of Database Files</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/understanding-database-autogrowth-sql-server/" target="_blank" rel="noopener">Understanding Autogrowth Operation in SQL Server Databases</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/instant-file-initialization-enable-on-sql-server-instance/" target="_blank" rel="noopener">How to Enable IFI &#8211; Instant File Initialization?</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/troubleshooting/manage-transaction-log-file-during-data-load/" target="_blank" rel="noopener">Manage Database Files during huge Data Load</a></strong></li>
</ul>
<p>The post <a href="https://techyaz.com/sql-server/troubleshooting/fix-error-1101-could-not-allocate-a-new-page-for-database/">Fix Error 1101: Could not allocate a new page for database</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/troubleshooting/fix-error-1101-could-not-allocate-a-new-page-for-database/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Fix SQL Server Msg 5144 and 5145 for long or failed autogrow of data and log files</title>
		<link>https://techyaz.com/sql-server/troubleshooting/fix-msg-5144-and-5145-for-long-or-failed-autogrow/</link>
					<comments>https://techyaz.com/sql-server/troubleshooting/fix-msg-5144-and-5145-for-long-or-failed-autogrow/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Wed, 24 Jan 2018 16:19:30 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[autogrow]]></category>
		<category><![CDATA[autogrowth setting]]></category>
		<category><![CDATA[data file autogrow]]></category>
		<category><![CDATA[IFI]]></category>
		<category><![CDATA[Instant File Initialization]]></category>
		<category><![CDATA[log_files]]></category>
		<category><![CDATA[SQL_Error_Code]]></category>
		<category><![CDATA[transaction log]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=1634</guid>

					<description><![CDATA[<p>Whenever you extend the size of your data or log file with a larger value or your database perform autogrow operation to extend its database files with bigger value then SQL Server takes longer time to perform such activities. SQL&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/troubleshooting/fix-msg-5144-and-5145-for-long-or-failed-autogrow/">Fix SQL Server Msg 5144 and 5145 for long or failed autogrow of data and log files</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Whenever you extend the size of your data or log file with a larger value or your database perform autogrow operation to extend its database files with bigger value then SQL Server takes longer time to perform such activities. SQL Server reports these messages 5144 and 5145 in to the Application Event Log and ERRORLOG in case autogrow of a database and/or transaction log file has timed out or has taken a long period of time to complete. The details about such logs are given below:</p>
<p><em><span style="color: #ff0000;">Msg 5144</span></em><br />
<em><span style="color: #ff0000;"> Autogrow of file &#8216;Data or Log file name&#8217; in database &#8216;Database&#8217; was cancelled by user or timed out after &lt;n&gt; milliseconds. Use ALTER DATABASE to set a smaller FILEGROWTH value for this file or to explicitly set a new file size.</span></em></p>
<p>Or you will get below message if autogrow operation or data/log file size increase operation will run for longer duration than expected.</p>
<p><em><span style="color: #ff0000;">Msg 5145</span></em><br />
<em><span style="color: #ff0000;"> Autogrow of file &#8216;Data or Log file name&#8217; in database &#8216;Database&#8217; took &lt;n&gt; milliseconds. Consider using ALTER DATABASE to set a smaller FILEGROWTH for this file.</span></em></p>
<p>Whenever data or log file growth operation is taking lot of time then a wait type <a href="http://techyaz.com/sql-server/reduce-wait-type-preemptive_os_writefilegather/" target="_blank" rel="noopener">PREEMPTIVE_OS_WRITEFILEGATHER</a> will be shown in to SQL Server. If you want to read more about this wait type then click at the attached link.<strong> </strong></p>
<h3><span style="color: #333399;">Root Cause</span></h3>
<p>Data and log file initialization takes lot of time if you have to create large database files or large data or log file growth will be performed. Whenever we allocate or extend space to data or log file, it first fills with zeros. Zeroing operation takes lot of time for bigger size autogrowth operations that causes for longer run to complete. We generally see these messages (5144 or 5145) during either extending the data or transaction log files or during autogrowth operation for data or log files.</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-1637 alignleft" src="http://techyaz.com/wp-content/uploads/2018/01/Fix-msg-5144-5145-min.png" alt="fix msg 5144 and 5145" width="560" height="315" srcset="https://techyaz.com/wp-content/uploads/2018/01/Fix-msg-5144-5145-min.png 560w, https://techyaz.com/wp-content/uploads/2018/01/Fix-msg-5144-5145-min-300x169.png 300w" sizes="auto, (max-width: 560px) 100vw, 560px" /></p>
<p>Microsoft has given a solution named <a href="http://techyaz.com/sql-server/instant-file-initialization-enable-on-sql-server-instance/" target="_blank" rel="noopener">Instant File Initialization</a> to fix the time consuming file size allocation for data files. Once Instant File Initialization will be enabled, your data files size allocation will be done in faster way but unfortunately Instant File Initialization does not work on transaction log files.  <strong>Instant file initialization</strong> reclaims used disk space without filling that space with zeros. Instead, disk content is overwritten as new data is written to the files. Read below section to overcome these error messages.</p>
<h3><span style="color: #333399;">Solution</span></h3>
<p>To avoid these messages 5144 or 5145 to be logged, we should plan file size growth carefully. We should set maximum size of the database so that it could not perform frequent autogrowth operation. We can enable Instant File Initialization feature to speed up the data file size allocation. It is not recommended to rely on autogrowth of files as standard operation for obtaining more space in a file. Rather, you should plan out the maximum size of your database and/or transaction log file and allow autogrowth to occur only in unplanned situations for space. Follow below points to avoid this error.</p>
<ul>
<li>Enable Instant File Initialization to speed up data file size allocation. Read attached article to <a href="http://techyaz.com/sql-server/instant-file-initialization-enable-on-sql-server-instance/" target="_blank" rel="noopener">enable IFI (Instant File Initialization) on your database server</a>.</li>
<li>As IFI (Instant File Initialization) does not work on log files so we need to set log files in smaller chunks to avoid any time out error or longer runs.</li>
<li>Set database size to the maximum size it could be and allow autogrowth settings to occur only in unplanned situations for space.Read attached article to <a href="http://techyaz.com/sql-server/understanding-database-autogrowth-sql-server/" target="_blank" rel="noopener">understand Autogrowth setting and its perfect value for database files.</a></li>
</ul>
<p>I hope you like this article. Please follow our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <a href="https://twitter.com/Tech_yaz">Twitter</a> handle to get latest updates.</p>
<p><span style="color: #800000;"><em><strong>Related Articles:</strong></em></span></p>
<ul>
<li><span style="color: #0000ff;"><strong><a style="color: #0000ff;" href="http://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></span></li>
<li><span style="color: #0000ff;"><strong><a style="color: #0000ff;" href="http://techyaz.com/sql-server/improve-sql-server-bulk-data-import-performance/" target="_blank" rel="noopener">How to Improve Bulk Data Load Performance?</a></strong></span></li>
<li><span style="color: #0000ff;"><strong><a style="color: #0000ff;" href="http://techyaz.com/sql-server/reduce-wait-type-preemptive_os_writefilegather/" target="_blank" rel="noopener">How to Reduce SQL Server Wait type PREEMPTIVE_OS_WRITEFILEGATHER?</a></strong></span></li>
<li><span style="color: #0000ff;"><strong><a style="color: #0000ff;" href="http://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></span></li>
<li><span style="color: #0000ff;"><strong><a style="color: #0000ff;" href="http://techyaz.com/sql-server/troubleshooting/fix-error-3023-error-3013-error-3041/" target="_blank" rel="noopener">Fix Error 3023: Shrink failed for Log file</a></strong></span></li>
</ul>
<p>The post <a href="https://techyaz.com/sql-server/troubleshooting/fix-msg-5144-and-5145-for-long-or-failed-autogrow/">Fix SQL Server Msg 5144 and 5145 for long or failed autogrow of data and log files</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/troubleshooting/fix-msg-5144-and-5145-for-long-or-failed-autogrow/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>4 Different Usages of DBCC SQLPERF in SQL Server</title>
		<link>https://techyaz.com/sql-server/sql-server-dmvs/4-different-usages-dbcc-sqlperf-sql-server/</link>
					<comments>https://techyaz.com/sql-server/sql-server-dmvs/4-different-usages-dbcc-sqlperf-sql-server/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Mon, 08 Jan 2018 11:02:31 +0000</pubDate>
				<category><![CDATA[DBCC & DMVs]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[Wait Types]]></category>
		<category><![CDATA[DBCC]]></category>
		<category><![CDATA[dmv]]></category>
		<category><![CDATA[latches]]></category>
		<category><![CDATA[log space]]></category>
		<category><![CDATA[log_files]]></category>
		<category><![CDATA[transaction log]]></category>
		<category><![CDATA[wait statistics]]></category>
		<category><![CDATA[Waittypes]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=1445</guid>

					<description><![CDATA[<p>DBCC SQLPERF is very useful command that we use to get multiple statistics related information in SQL Server. This command provides transaction log space statistics and wait statistics information at instance level and we also use it to reset wait and&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/sql-server-dmvs/4-different-usages-dbcc-sqlperf-sql-server/">4 Different Usages of DBCC SQLPERF in SQL Server</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>DBCC SQLPERF is very useful command that we use to get multiple statistics related information in SQL Server. This command provides <a href="http://techyaz.com/sql-server/understanding-transaction-log-architecture/" target="_blank" rel="noopener">transaction log</a> space statistics and wait statistics information at instance level and we also use it to reset wait and latch statistics data. We can use DBCC SQLPERF command to do below tasks.</p>
<ol>
<li>Get log space size</li>
<li>View wait statistics data</li>
<li>Clear wait statistics data</li>
<li>Clear latch statistics data</li>
</ol>
<p>Let’s discuss each of above tasks as use cases of DBCC SQLPERF command.</p>
<p><em><strong><span style="color: #800000;">Read More</span></strong></em></p>
<ul>
<li><a href="http://techyaz.com/sql-server/get-total-virtual-log-files/" target="_blank" rel="noopener">How to get total no of VLFs (Virtual Log Files) inside Log file?</a></li>
<li><a href="http://techyaz.com/sql-server/understanding-sql-server-data-files-pages-extents/" target="_blank" rel="noopener">Understanding Data Files, Pages &amp; Extents</a></li>
<li><a href="http://techyaz.com/sql-server/how-to-avoid-page-split-in-sql-server/" target="_blank" rel="noopener">How to Avoid Page Split in SQL Server?</a></li>
</ul>
<h4><span style="color: #333399;">Get Transaction Log space using DBCC SQLPERF</span></h4>
<p>We can get transaction log space utilization details like how large your transaction logs are and what percentage of them is in use by executing dbcc sqlperf command. Run below command to get the log space details of all database hosted your SQL Server Instance.</p>
<div class="codediv">
<pre><strong><span style="color: #008000;">--Get Transaction Log Size Details</span>
<span style="color: #0000ff;">DBCC SQLPERF(logspace)
</span></strong></pre>
</div>
<p>You can see the below screenshot; all the columns are self-explanatory. We can see percent of log space used out of total space allocated to the log file.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1447" src="http://techyaz.com/wp-content/uploads/2018/01/1-Check-log-space.jpg" alt="Check Log space utilization using dbcc sqlperf" width="417" height="236" srcset="https://techyaz.com/wp-content/uploads/2018/01/1-Check-log-space.jpg 417w, https://techyaz.com/wp-content/uploads/2018/01/1-Check-log-space-300x170.jpg 300w" sizes="auto, (max-width: 417px) 100vw, 417px" /></p>
<h4><span style="color: #333399;">View and Clear Wait Statistics Data</span></h4>
<p>We can get wait statistics data using dbcc sqlperf command as well. We used to get these details using dbcc sqlperf command in older version of SQL Server instances. Although, you can still get wait statistics data using this command in current versions of SQL Server but now there is a better way to get such details using DMV <strong>sys.dm_os_wait_stats</strong>.  Here, I will show you wait stats data using DMV only. Run below commands to get wait statistics details of your SQL Server instance.</p>
<div class="codediv">
<pre><strong><span style="color: #008000;">--Get wait Statistics using DBCC command.</span>
DBCC SQLPERF(waitstats)

<span style="color: #008000;">--Get Wait Statistics using DMV sys.dm_os_wait_stats</span>
SELECT * FROM sys.dm_os_wait_stats
Order by wait_time_ms desc
</strong></pre>
</div>
<p>You can see the details about all wait types on your SQL Server instance. You can also see the total wait time in milliseconds. These information is very important to deal with performance issues but details like total wait time, total waiting tasks count are not the real-time values. These values are accumulated since last SQL Server service start or last time wait stats was reset using dbcc sqlperf command. It is highly recommended to not clear wait stats data until it is required to do that otherwise you will lose valuable information about wait statistics. Read attached article about <a href="http://techyaz.com/sql-server/sql-server-dmvs/clear-wait-statistics-data-sql-server/" target="_blank" rel="noopener">why should you not clear wait statistics data stored in DMV sys.dm_os_wait_stats</a>.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1448" src="http://techyaz.com/wp-content/uploads/2018/01/2-sys.dm_os_wait_stats.jpg" alt="View Wait stats data using DMV" width="643" height="300" srcset="https://techyaz.com/wp-content/uploads/2018/01/2-sys.dm_os_wait_stats.jpg 643w, https://techyaz.com/wp-content/uploads/2018/01/2-sys.dm_os_wait_stats-300x140.jpg 300w" sizes="auto, (max-width: 643px) 100vw, 643px" /></p>
<p>If you want to get the correct waiting task counts or waiting time then you need to clear the wait statistics data using dbcc sqlperf command. Here, I will show you the difference after clearing the wait stats. Run below command to clear all wait stats data on your SQL Server Instance.</p>
<div class="codediv">
<pre><strong>DBCC SQLPERF(“sys.dm_os_wait_stats”, CLEAR)
</strong></pre>
</div>
<p>You can see I have successfully ran this command in below screenshot.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1449" src="http://techyaz.com/wp-content/uploads/2018/01/3-Clear-buffer-for-wait-stats.jpg" alt="clear wait stats" width="689" height="121" srcset="https://techyaz.com/wp-content/uploads/2018/01/3-Clear-buffer-for-wait-stats.jpg 689w, https://techyaz.com/wp-content/uploads/2018/01/3-Clear-buffer-for-wait-stats-300x53.jpg 300w" sizes="auto, (max-width: 689px) 100vw, 689px" /></p>
<p>Now we will again run same command to get the wait statistics data. I ran it and I get below data that is showing different than the one showing before clearing wait stats. This way you can better analyze your database performance and waiting tasks and time to reach on any conclusion.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1450" src="http://techyaz.com/wp-content/uploads/2018/01/4-Check-wait-stats-after-clearning-buffer.jpg" alt="Check wait stats after clearing its buffer" width="804" height="283" srcset="https://techyaz.com/wp-content/uploads/2018/01/4-Check-wait-stats-after-clearning-buffer.jpg 804w, https://techyaz.com/wp-content/uploads/2018/01/4-Check-wait-stats-after-clearning-buffer-300x106.jpg 300w, https://techyaz.com/wp-content/uploads/2018/01/4-Check-wait-stats-after-clearning-buffer-768x270.jpg 768w" sizes="auto, (max-width: 804px) 100vw, 804px" /></p>
<p>&nbsp;</p>
<h4><span style="color: #333399;">Clear Latch Statistics Data</span></h4>
<p>I described about clearing wait stats data in above section. Here, I will show you how to clear latch statistics data. <b>Latches</b> are locks for RAM memory structures to prevent concurrent access and ensure serial execution of kernel code. You can run SQL command to check current latch statistics data.</p>
<div class="codediv">
<pre><span style="color: #008000;"><span style="color: #008000;"><b>--Get latch statistics data</b></span></span><b>
SELECT * FROM sys.dm_os_latch_stats
ORDER BY wait_time_ms desc
</b></pre>
</div>
<p>You can see current latch statistics details that is also not showing only real time value but it is accumulated data since last SQL Server service restarted or last time latch wait statistics was reset/cleared.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1451" src="http://techyaz.com/wp-content/uploads/2018/01/5-Check-Latch.jpg" alt="Get Latch Statistics Data" width="678" height="217" srcset="https://techyaz.com/wp-content/uploads/2018/01/5-Check-Latch.jpg 678w, https://techyaz.com/wp-content/uploads/2018/01/5-Check-Latch-300x96.jpg 300w" sizes="auto, (max-width: 678px) 100vw, 678px" /></p>
<p>&nbsp;</p>
<p>Now we will clear these latch statistics data to get real time value of latch details. Run below dbcc sqlperf command to clear the latch statistics.</p>
<div class="codediv">
<pre><strong>DBCC SQLPERF(“sys.dm_os_latch_stats”, CLEAR)
</strong></pre>
</div>
<p>You can see we have successfully executed above command on our SQL Server Instance.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1452" src="http://techyaz.com/wp-content/uploads/2018/01/6-Clear-stored-latch-details.jpg" alt="Clear Latch Statistics Data" width="722" height="121" srcset="https://techyaz.com/wp-content/uploads/2018/01/6-Clear-stored-latch-details.jpg 722w, https://techyaz.com/wp-content/uploads/2018/01/6-Clear-stored-latch-details-300x50.jpg 300w" sizes="auto, (max-width: 722px) 100vw, 722px" /></p>
<p>Now go ahead and run same SQL command to get the latch statistics again. You can see now there is no waiting requests on our SQL Server Instance and you are getting real time value about latches.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1453" src="http://techyaz.com/wp-content/uploads/2018/01/7-check-latch-details-after-clearning-buffer.jpg" alt="latch details after cleaning its buffer data " width="677" height="197" srcset="https://techyaz.com/wp-content/uploads/2018/01/7-check-latch-details-after-clearning-buffer.jpg 677w, https://techyaz.com/wp-content/uploads/2018/01/7-check-latch-details-after-clearning-buffer-300x87.jpg 300w" sizes="auto, (max-width: 677px) 100vw, 677px" /></p>
<p><em><strong><span style="color: #800000;">Related Articles</span></strong></em></p>
<ul>
<li><a href="http://techyaz.com/sql-server/sql-server-dmvs/clear-wait-statistics-data-sql-server/" target="_blank" rel="noopener">Should We Clear Wait Stats Data from DMV sys.dm_os_wait_stats?</a></li>
<li><a href="http://techyaz.com/sql-server/backupbuffer-wait-type/" target="_blank" rel="noopener">How to Fix BACKUPBUFFER Wait Type?</a></li>
<li><a href="http://techyaz.com/sql-server/improve-sql-server-bulk-data-import-performance/" target="_blank" rel="noopener">How to Improve Bulk Data Load Performance?</a></li>
</ul>
<p>These are the 4 use cases of DBCC SQLPERF command that we use during different database activities. I hope you like this article. Please follow our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <a href="https://twitter.com/Tech_yaz">Twitter </a>handle to get latest updates.</p>
<p>The post <a href="https://techyaz.com/sql-server/sql-server-dmvs/4-different-usages-dbcc-sqlperf-sql-server/">4 Different Usages of DBCC SQLPERF in SQL Server</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/sql-server-dmvs/4-different-usages-dbcc-sqlperf-sql-server/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Improve SQL Server Bulk Data Import Performance?</title>
		<link>https://techyaz.com/sql-server/performance-tuning/improve-sql-server-bulk-data-import-performance/</link>
					<comments>https://techyaz.com/sql-server/performance-tuning/improve-sql-server-bulk-data-import-performance/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Wed, 08 Nov 2017 07:24:07 +0000</pubDate>
				<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Administration]]></category>
		<category><![CDATA[Auto shrink]]></category>
		<category><![CDATA[autogrow]]></category>
		<category><![CDATA[autogrowth setting]]></category>
		<category><![CDATA[Autoshrink]]></category>
		<category><![CDATA[batch size]]></category>
		<category><![CDATA[bulk data load]]></category>
		<category><![CDATA[bulk import]]></category>
		<category><![CDATA[bulk import performance]]></category>
		<category><![CDATA[bulk insert]]></category>
		<category><![CDATA[data file]]></category>
		<category><![CDATA[data file autogrow]]></category>
		<category><![CDATA[data load]]></category>
		<category><![CDATA[database property]]></category>
		<category><![CDATA[HowTO]]></category>
		<category><![CDATA[IFI]]></category>
		<category><![CDATA[Instant File Initialization]]></category>
		<category><![CDATA[log_files]]></category>
		<category><![CDATA[maxdop]]></category>
		<category><![CDATA[performance tuning]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=1108</guid>

					<description><![CDATA[<p>I am working on a project where we are migrating Oracle databases to SQL Server for SAP applications. We are using SAP migration tools to migrate these databases and we are not using SSMA for Oracle in this migration. These&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/performance-tuning/improve-sql-server-bulk-data-import-performance/">How to Improve SQL Server Bulk Data Import Performance?</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I am working on a project where we are migrating Oracle databases to SQL Server for SAP applications. We are using SAP migration tools to migrate these databases and we are not using SSMA for Oracle in this migration. These databases were very big in size so we faced some performance issues during data load. Here I will explain how to avoid such performance issues and speed up SQL Server Bulk Data Import Performance.</p>
<p>Let me first give you some background about SAP migration tool like how it works. SAP Migration tool first captures every related information along with data and creates an export file that needs to be copied to the target location or server and then we perform bulk data import with the help of SAP migration tool. Bulk data import or data load will be done locally and not over network.</p>
<p>When we ran SAP migration tools to capture all details, a dump file was created that we have copied to the SQL Server box. We had approx. 900GB of data that needs to be loaded into SQL Server database. When we performed SQL Server data load using SAP migration tools with standard settings, it took around 14 hrs. to complete the bulk data import.  As 14 hrs. was very long time so we decided to work on reducing the total time taken by import process.</p>
<p>We made some changes from both sides application as well as SQL Server database side. SQL Server data load time has reduced drastically to around little more than 6 hours post these change implementations. Here, I am explaining each parameter that we have configured from database side just for this bulk data import.</p>
<p><span style="color: #800000;"><strong>NOTE:</strong> </span>Make sure to revert these changes as per your application/vendor best practices post this bulk data import for OLTP/normal operations. We are changing value considering Data Load only.</p>
<p><img loading="lazy" decoding="async" class="alignleft wp-image-1109 size-medium" src="http://techyaz.com/wp-content/uploads/2017/11/Speed-up-bulk-data-Import-300x169.jpg" alt="Speed up bulk data Import" width="300" height="169" srcset="https://techyaz.com/wp-content/uploads/2017/11/Speed-up-bulk-data-Import-300x169.jpg 300w, https://techyaz.com/wp-content/uploads/2017/11/Speed-up-bulk-data-Import-768x432.jpg 768w, https://techyaz.com/wp-content/uploads/2017/11/Speed-up-bulk-data-Import-1024x576.jpg 1024w, https://techyaz.com/wp-content/uploads/2017/11/Speed-up-bulk-data-Import.jpg 1280w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>It is important to understand the factors that affect bulk data import performance. To speed up the data load, you need to look into below configuration options from DBA standpoint.</p>
<h5><span style="color: #000080;"><strong>Auto Grow</strong></span></h5>
<p><strong> </strong>Autogrow settings can be used to automate SQL Server database file growth. This is very useful property but this can degrade your bulk import performance or data load operations. Read attached article to<strong> <a href="https://techyaz.com/sql-server/understanding-database-autogrowth-sql-server/" target="_blank" rel="noopener">understand SQL Server Autogrow setting</a> </strong>in detail.</p>
<p>Autogrow setting increment must be large enough to avoid the performance penalties.  If you set default or small value during bulk import or data load, database engine will have to perform data file autogrow operation every time the file will be filled with data till maximum size limit. More autogrow operation will take more resources like IO, CPU etc and time to complete the data load transaction.</p>
<p>The exact value for this setting should be based on data growth. You should not be left autogrow in percentage value rather you should use some value in MBs. A general rule of thumb is to set your autogrow setting to about one-eighth the size of the file. Please read attached article to understand <strong><a href="https://techyaz.com/sql-server/troubleshooting/manage-transaction-log-file-during-data-load/" target="_blank" rel="noopener">how to manage transaction log files during huge data load</a>.</strong></p>
<p>I would suggest keeping database size as much as you are expecting your database will grow to avoid autogrow operation. If you are aware that your database size will be 900 GB post data load, you should set your database size to 900 GB before starting the data load. This will improve the bulk import performance. Make sure to enable IFI (Instant File Initialization) for your SQL Server instance to reduce total time SQL Server takes to set the database size.</p>
<h5><span style="color: #000080;"><strong>Instant File Initialization</strong></span></h5>
<p>As I suggested in above point, Turn IFI (Instant File Initialization) ON to speed up AutoGrow process. If you set a considerable large value to autogrow settings, it will take some time to increase the size by zeroing the disk address. IFI speeds up this process and allow us to create enormous size of data files in quick way. Read attached article to learn more about<strong> <a href="https://techyaz.com/sql-server/instant-file-initialization-enable-on-sql-server-instance/" target="_blank" rel="noopener">IFI (Instant File Initialization) and how it will speed up autogrow or data load operation</a></strong>. You will also learn how to enable IFI for your SQL Server instance in this attached article.</p>
<h5><span style="color: #000080;"><strong>Auto Shrink</strong></span></h5>
<p>AutoShrink is very costly operation that should be always OFF even during your daily and normal operations. Turn it OFF immediately. Make sure your disk has enough space to sustain during bulk operations or data load. Repeatedly shrinking and growing the data files will cause file-system level fragmentation, which can slow down performance. It also takes lot of CPU and IO. Read attached article to know<strong> <a href="https://techyaz.com/sql-server/always-turn-off-database-auto-shrink/" target="_blank" rel="noopener">why you should always keep Auto_Shrink off</a>.</strong></p>
<h5><span style="color: #000080;"><strong>Reduce Logging</strong></span></h5>
<p>Change <strong><a href="https://techyaz.com/sql-server/understanding-sql-server-recovery-model/" target="_blank" rel="noopener">recovery model</a></strong> to SIMPLE or BULK-LOGGED to reduce the logging operations. The simple recovery model minimally logs most bulk operations. For a database under the full recovery model, all row-insert operations that are performed during bulk import are fully logged in the transaction log.</p>
<p>For large data imports, this can cause the transaction log to fill rapidly. For bulk-import operations, minimal logging is more efficient than full logging and reduces the possibility that a bulk-import operation will fill the log space. To minimally log a bulk-import operation on a database that normally uses the full recovery model, you can first switch the database to the bulk-logged recovery model. After bulk importing the data, switch the recovery model back to the full recovery model.</p>
<h5><span style="color: #000080;"><strong>Auto_Update_Statistics</strong></span></h5>
<p>Auto_Update_Statistics is very useful property that should be set to ON during normal business operations but here I would suggest turning it off during huge data load or bulk import operations. Updating the statistics also takes resources from the system. This can lead to performance issues when you are doing bulk data. It’s important to keep up-to-date statistics for the optimizer to use, but here we will turn it off and once data load or bulk data inserts will be performed, we will again enable it.</p>
<h5><span style="color: #000080;"><strong>Auto_Create_Statistics</strong></span></h5>
<p>This should be OFF because creating statistics also takes resources from the system that can degrade the overall bulk import performance. Make sure to enable it post data load or bulk inserts operation.</p>
<h5><span style="color: #000080;"><strong>Parallelism – MAXDOP</strong></span></h5>
<p>SAP suggests setting MAXDOP value to 1 during normal business operation so we had this value during first data load that took around 14 hrs. We had assigned half of the CPU cores for the parallel processes during data load and bulk import operations. I believe MAXDOP has contributed significant role in reducing total data load time. Make sure to revert this change to its original value as per your application best practices.</p>
<p>You can change MAXDOP settings either using <strong>sp_configure</strong> command or using GUI in SSMS by launching SQL Server Instance property window.</p>
<h5><span style="color: #000080;"><strong>Using Batches</strong></span></h5>
<p>Make sure to use an optimum batch size that will increase the bulk data import performance. Importing a large set of data as a single batch can be problematic, so bcp and BULK INSERT let you import data in a series of batches, each of which is smaller than the data file. Each batch is imported and logged in a separate transaction, and after a given transaction is committed, the rows imported by that transaction are committed. If the operation fails, only rows imported from the current batch are rolled back, and you can resume importing data starting at the beginning of the failed batch rather than at the beginning of the data file.</p>
<p>I hope you like this article. Please follow us our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <a href="https://twitter.com/Tech_yaz">Twitter </a>handle to get latest updates.</p>
<p>The post <a href="https://techyaz.com/sql-server/performance-tuning/improve-sql-server-bulk-data-import-performance/">How to Improve SQL Server Bulk Data Import Performance?</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/performance-tuning/improve-sql-server-bulk-data-import-performance/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Understanding SQL Server Recovery Model</title>
		<link>https://techyaz.com/sql-server/backup-recovery/understanding-sql-server-recovery-model/</link>
					<comments>https://techyaz.com/sql-server/backup-recovery/understanding-sql-server-recovery-model/#comments</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Sat, 09 Sep 2017 12:00:07 +0000</pubDate>
				<category><![CDATA[Backup & Recovery]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Administration]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[bulk-logged]]></category>
		<category><![CDATA[checkpoints]]></category>
		<category><![CDATA[full]]></category>
		<category><![CDATA[log_files]]></category>
		<category><![CDATA[recovery]]></category>
		<category><![CDATA[Recovery Model]]></category>
		<category><![CDATA[simple]]></category>
		<category><![CDATA[transaction log]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=829</guid>

					<description><![CDATA[<p>A Recovery Model is a database property that designed to control transaction log maintenance. SQL Server Recovery Model does not define how transactions will be logged but they define how transaction logs will be managed in the transaction log file.&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/backup-recovery/understanding-sql-server-recovery-model/">Understanding SQL Server Recovery Model</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A Recovery Model is a database property that designed to control transaction log maintenance. SQL Server Recovery Model does not define how transactions will be logged but they define how transaction logs will be managed in the <a href="https://techyaz.com/sql-server/understanding-transaction-log-architecture/" target="_blank" rel="noopener">transaction log file</a>. There are three types of recovery models in SQL Server:</p>
<ul>
<li>Simple</li>
<li>Full</li>
<li>Bulk-Logged</li>
</ul>
<h3><span style="color: #000080;">Simple Recovery Model</span></h3>
<p>Simple recovery model is used for databases that are not critical or the database is static and data is not changing. We generally use SIMPLE model for lower life cycle databases. Main reason for this is point in time recovery is not possible because transaction log backup is not allowed in this recovery model and database engine automatically clears transactional logs during checkpoint operation. If you want to <a href="https://techyaz.com/sql-server/checkpoint/" target="_blank" rel="noopener">understand checkpoint operation</a>, you should read attached article.</p>
<p>A common <strong>myth</strong> is that when a database is configured in Simple recovery model then transactions will not be logged in transaction log files. This is not true and <strong>every transaction is logged to the transaction log file</strong>. Only difference is that, when that <strong>transactions will complete</strong> and data is written to disk all <strong>logs will flush</strong> and be available to log another transaction in same log file. This way you can also deal with the space issue.</p>
<p>Log Shipping, <a href="https://techyaz.com/sql-server/alwayson-availability-group/" target="_blank" rel="noopener">AlwaysOn Availability group</a> and <a href="https://techyaz.com/sql-server/point-in-time-recovery/" target="_blank" rel="noopener">Point-in-Time Restores</a> are not possible in this SIMPLE model because transaction log backups are not allowed in this recovery model. We can recover any database that are running in SIMPLE model till last full or differential backups only. Run below command if you want to view or change the recovery model of the database.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span class="kwrd" style="color: blue;"><span style="color: #008000;">--Check the Recovery Model of the database YourDB_Name
<span style="color: #0000ff;">SELECT name, recovery_model_desc  
   FROM sys.databases  
      WHERE name = 'YOURDB_NAME' ;  
GO</span>
--Change Recovery Model to SIMPLE</span>
ALTER DATABASE DBNAME SET RECOVERY SIMPLE
GO
</span></strong></pre>
<h3><span style="color: #000080;">Full Recovery Model</span></h3>
<p><a href="https://techyaz.com/sql-server/point-in-time-recovery/" target="_blank" rel="noopener">Point in time recovery</a> is possible in full recovery model that is why we use this recovery model for all production and critical databases. Every transactions that are logged in this recovery model can be backed up. Transaction log backup will capture all the logs and clears all the inactive portions of the transaction log file.  You can handle your <a href="https://techyaz.com/sql-server/get-total-virtual-log-files/" target="_blank" rel="noopener">log file space management</a> by scheduling frequent transaction log backups.</p>
<p>You can also clear the transaction logs from log files by switching the recovery model from Full to Simple but this is never recommended for any production database. If you change the SQL Server recovery model from Full to Simple, logs will be flushed from log file without getting captured into transaction log backup. That will break the log sequence and you will end up losing the point in time recovery for your database. That is why switching recovery model from full to simple is not recommended for production database.</p>
<p>As transaction log backups are allowed in this recovery model so you can recover your database till point in time and there will be no data loss in this recovery model.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span class="kwrd" style="color: blue;"><span style="color: #008000;">--Change SQL Server Recovery Model to FULL</span>
ALTER DATABASE DBNAME SET RECOVERY FULL
GO
</span></strong></pre>
<h3><span style="color: #000080;">Bulk-Logged Recovery Model</span></h3>
<p>Bulk-logged recovery model works similar to Full recovery model except few exceptions during bulk operations. You can use this recovery model if you have to run BULK operations on your database. Bulk-logged recovery model minimally logged such bulk operations to reduce the transaction log space.</p>
<p>Point in time recovery is not possible if you have performed any bulk operation during that time due to the nature of minimally logged operation. If you haven&#8217;t performed any bulk operation then point in time recovery can be achieved. Microsoft does not suggest to run any database in bulk-logged recovery model if you don&#8217;t have to run any bulk operations.</p>
<p>Best practice is that you change a database recovery model to the bulk-logged immediately before running bulk operations and restore it back to the full recovery model when those operations complete. Also you should run a log backup before switching to bulk-logged recovery model and again take the log backup once you return back to full recovery model post completing bulk operation. Your backup strategy remains the same and it will not break your log sequence. Run below command to change the recovery model to bulk-logged.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span class="kwrd" style="color: blue;"><span style="color: #008000;">--Change Recovery Model to BULK-Logged</span>
ALTER DATABASE DBNAME SET RECOVERY FULL
GO
</span></strong></pre>
<h3><span style="color: #000080;">Change Recovery Model using GUI</span></h3>
<ol>
<li>Connect to SQL Server Instance. in Object Explorer, click the server name to expand the server tree.</li>
<li>Expand <strong>Databases</strong> folder and click on the database for which either you want to change the recovery model of view the recovery model.</li>
<li>Right-click on that database, and then click <strong>Properties</strong>, which opens the <strong>Database Properties</strong> dialog box.</li>
<li>In the <strong>Select a page</strong> pane, click <strong>Options</strong>.</li>
<li>The current recovery model is displayed in the <strong>Recovery model</strong> list box.</li>
<li>Optionally, to change the recovery model select a different model list. The choices are <strong>Full</strong>, <strong>Bulk-logged</strong>, or <strong>Simple</strong>.</li>
<li>Click <strong>OK</strong>.</li>
</ol>
<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>The post <a href="https://techyaz.com/sql-server/backup-recovery/understanding-sql-server-recovery-model/">Understanding SQL Server Recovery Model</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/backup-recovery/understanding-sql-server-recovery-model/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<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 loading="lazy" 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="auto, (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 loading="lazy" 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="auto, (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 loading="lazy" 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="auto, (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>
		<item>
		<title>Understanding SQL Server Transaction Log File Architecture</title>
		<link>https://techyaz.com/sql-server/understanding-transaction-log-architecture/</link>
					<comments>https://techyaz.com/sql-server/understanding-transaction-log-architecture/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Mon, 24 Jul 2017 12:35:30 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[log_files]]></category>
		<category><![CDATA[SQL_Server_Architecture]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=265</guid>

					<description><![CDATA[<p>Today, i will talk about SQL Server Transaction Log File Architecture. As we know, every database must have at least one transaction log file (Tlog file) that captures everything happens on database to maintain data integrity of the database. Logically,&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/understanding-transaction-log-architecture/">Understanding SQL Server Transaction Log File Architecture</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Today, i will talk about SQL Server Transaction Log File Architecture. As we know, every database must have at least one transaction log file (Tlog file) that captures everything happens on database to maintain data integrity of the database. Logically, SQL Server transaction log file is a series of log records whereas physically these log records stored in this transaction log file that are placed on OS drive.  I will discuss about the SQL Server transaction log file architecture in this article. Let us start with logical architecture of Tlog file followed by the physical architecture.</p>
<p><em><strong><span style="color: #800000;">Related Articles:</span></strong></em></p>
<ul>
<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/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">What is the best value for database file autogrowth?</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/what-should-be-the-best-value-for-fill-factor-in-sql-server/" target="_blank" rel="noopener">What is the Suitable Value for Fill Factor?</a></strong></li>
</ul>
<h3><span style="color: #000080;">Logical Architecture</span></h3>
<p>To understand SQL Server Transaction Log File Architecture, we need to start with basics. As we know transaction log file is mandatory database file for a database. Every database must have at least one transaction log file. SQL Server uses transaction log file to capture log records that guarantee the data integrity of the database and for data recovery.</p>
<p>Logically, SQL Server transaction log is a string of log records. Each log record is identified by a <strong>log sequence number (LSN)</strong>. Each new log record is written with the incremental LSN that means a new log record will be assigned a LSN that is higher than the LSN of the record before it. Log records are stored in a serial sequence as they are created.</p>
<h3><span style="color: #000080;"><strong>Operations that recorded in the Transaction Log File</strong></span></h3>
<p>There are many types of operations recorded in Tlog files. These operations include:</p>
<ol>
<li>The start and end of each transaction.</li>
<li>Every data modification (insert, update, or delete). This includes changes by system stored procedures or data definition language (DDL) statements to any table, including system tables.</li>
<li>Every extent and page allocation or deallocation.</li>
<li>Creating or dropping a table or index.</li>
<li>Rollback operations. Each transaction reserves space on the transaction log to make sure that enough log space exists to support a rollback that is caused by either an explicit rollback statement or if an error is encountered. This reserved space is freed when the transaction is completed.</li>
</ol>
<p>The section of the log file from the first log record that must be present for a successful database-wide rollback to the last-written log record is called the active part of the log, or the active log. This is the section of the log required to do a full recovery of the database. You can not truncate any part of active log.<strong> </strong></p>
<h3><span style="color: #000080;">Physical Architecture</span></h3>
<p>As we know, a series of log records stores in transaction log file. These log files store physically on OS drive/disk along with <a href="https://techyaz.com/sql-server/understanding-sql-server-data-files-pages-extents/" target="_blank" rel="noopener">SQL Server data files.</a> Each transaction log file internally divided into a number of <strong>virtual log files</strong>. <a href="https://techyaz.com/sql-server/get-total-virtual-log-files/" target="_blank" rel="noopener"><strong>Virtual log files</strong></a> have no fixed size, and there is no fixed number of virtual log files for a physical log file.  The size or number of virtual log files cannot be configured by administrators. You can get <a href="https://techyaz.com/sql-server/get-total-virtual-log-files/" target="_blank" rel="noopener">total count of virtual log files</a> or vlfs in a SQL Server database log file/s in attached link. Here, i have explained in detail about how to track virtual log files.</p>
<p>The Database Engine chooses the size of the virtual log files dynamically while it 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.</p>
<p>If we define small Tlog file size along with small growth increment then it will cause performance issue to your system because whenever log file needs more room, it will increase log file size frequently due to small size of growth increment so it will create lot of virtual log files as well. This will affect performance of backup and restore operation along with database startup performance.</p>
<p><strong>Microsoft recommends</strong> that we should assign log files a size value close to the final size required, and also have a relatively large growth increment value.</p>
<h3><span style="color: #000080;">How Transactions Log File works?</span></h3>
<p>The transaction log is a wrap-around file. Let us demonstrate it using a scenario given in <a href="https://msdn.microsoft.com/en-us/library/ms345419.aspx">Microsoft Book Online.</a></p>
<p>Consider a database with one physical log file divided into four virtual log files. When the database is created, the logical log file begins at the start of the physical log file. New log records are added at the end of the logical log and expand toward the end of the physical log. Log truncation frees any virtual logs whose records all appear in front of the minimum recovery log sequence number (MinLSN). The MinLSN is the log sequence number of the oldest log record that is required for a successful database-wide rollback.</p>
<p>When the end of the logical log reaches the end of the physical log file, the new log records wrap around to the start of the physical log file.</p>
<p>This cycle repeats endlessly, as long as the end of the logical log never reaches the beginning of the logical log. If the old log records are truncated frequently enough to always leave sufficient room for all the new log records created through the next <a href="https://techyaz.com/sql-server/checkpoint/" target="_blank" rel="noopener">checkpoint</a>, the log never fills. However, if the end of the logical log does reach the start of the logical log, one of two things occurs:</p>
<ol>
<li>If the FILEGROWTH setting is enabled for the log and space is available on the disk, the file is extended by the amount specified in growth_increment and the new log records are added to the extension.</li>
<li>If the FILEGROWTH setting is not enabled, or the disk that is holding the log file has less free space than the amount specified in growth_increment, a 9002 error is generated.</li>
</ol>
<p>If the log contains multiple physical log files, the logical log will move through all the physical log files before it wraps back to the start of the first physical tlog file.</p>
<p>You can follow attached link to understand <a href="https://techyaz.com/sql-server/understanding-sql-server-data-files-pages-extents/" target="_blank" rel="noopener">SQL Server data files, Pages &amp; Extents.</a>  I hope you like this article. Here i have described SQL Server Transaction Log File Architecture that will help you to understand SQL Server database system. 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><em><strong><span style="color: #800000;">Read More:</span></strong></em></p>
<ul>
<li><strong><a href="https://techyaz.com/sql-server/avoid-database-shrink-operation/" target="_blank" rel="noopener">Understanding Database Shrink Operation and Why Should We Avoid It?</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/how-to-avoid-page-split-in-sql-server/" target="_blank" rel="noopener">How to Avoid Page Split in SQL Server?</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/troubleshooting/fix-msg-5144-and-5145-for-long-or-failed-autogrow/" target="_blank" rel="noopener">Fix SQl Server Error 5144 and 5145 for long and failed Autogrow of data and log file</a></strong></li>
</ul>
<p>The post <a href="https://techyaz.com/sql-server/understanding-transaction-log-architecture/">Understanding SQL Server Transaction Log File Architecture</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/understanding-transaction-log-architecture/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
