<?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>Denish Patel &#187; mssql server</title>
	<atom:link href="http://www.pateldenish.com/category/mssql-server/feed" rel="self" type="application/rss+xml" />
	<link>http://www.pateldenish.com</link>
	<description>my thoughts ....</description>
	<lastBuildDate>Wed, 22 May 2013 20:32:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>&#8220;Shrink&#8221; MS SQL Server transaction logfile</title>
		<link>http://www.pateldenish.com/2011/12/shrink-ms-sql-server-transaction-logfile.html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=shrink-ms-sql-server-transaction-logfile</link>
		<comments>http://www.pateldenish.com/2011/12/shrink-ms-sql-server-transaction-logfile.html#comments</comments>
		<pubDate>Tue, 06 Dec 2011 21:03:00 +0000</pubDate>
		<dc:creator>Denish Patel</dc:creator>
				<category><![CDATA[mssql server]]></category>

		<guid isPermaLink="false">http://denishjpatel.wordpress.com/2011/12/06/shrink-ms-sql-server-transaction-logfile</guid>
		<description><![CDATA[&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Microsoft SQL Server transactions log file &#8220;too large&#8221; is common problem. We need to manually shrink the transaction log file as one time operation and after that setting up proper recovery policy and/or keeping mirror server available all the &#8230; <a href="http://www.pateldenish.com/2011/12/shrink-ms-sql-server-transaction-logfile.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div dir="ltr" style="text-align:left;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft SQL Server transactions log file &#8220;too large&#8221; is common problem. We need  to manually shrink the transaction log file as one time operation and  after that setting up proper recovery policy and/or keeping mirror  server available all the time , we could&nbsp; avoid&nbsp; infinite growth of  transactions log in future.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Transaction log file growth is dependent on one of the following Recovery method used for the instance:<br />&nbsp;1. Simple<br />&nbsp;2. Full<br />&nbsp;3. Bulk-Logged</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If your database is in the Simple recovery mode, then the transaction  log is truncated of inactive transaction after the checkpoint process  occurs.&nbsp; The checkpoint process writes all modified data pages from  memory to disk.&nbsp; When the checkpoint is performed, the inactive portion  of the transaction log is marked as reusable. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQL Server 2005 databases are set to the Full  recovery model by default.&nbsp; With the Full or Bulk-Logged recovery mode, inactive transactions remain  in the transaction log file until after a Checkpoint&nbsp;is processed&nbsp;and  a&nbsp;transaction log backup is made.&nbsp; It&#8217;s important to note that a full backup does not  remove inactive transactions from the transaction log.&nbsp; If&nbsp; database recovery model is set to <b>Full</b> or <b>Bulk-Logged</b>, then it  is absolutely IMPORTANT that we make transaction log backups to go along  with&nbsp; full backups because full backup<b> does not</b> remove inactive transactions from the transaction log. The <b>transaction log backup</b>  performs a truncation of the inactive portion of the transaction log  and allow them to used for future transactions. Note that truncation of  log file <b>does not&nbsp; shrink</b> already bloated log file that&#8217;s the  operation we have to do manually one time&nbsp; and if we set proper  procedure in future, we could avoid unnecessary growth of log file. Other factors affecting transaction log to grow are:
<ol style="text-align:left;">
<li>Replicated mirrored server falls behind master server</li>
<li>Long running transactions</li>
</ol>
<p>To solve #1:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Database mirroring is uses transaction logs for replication in  that it requires that the transactions remain in the log until the  record has been written to disk on the mirror server. If the mirror  server&nbsp; falls behind the master server , the amount  of active log space will grow. In this case, you might need to stop  database mirroring, take a log backup that truncates the log, apply that  log backup to the mirror database and restart mirroring.</p>
<p>To solve #2: ( it&#8217;s non-issue for most of the OLTP servers) :<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If there are open transactions, DBCC OPENTRAN will provide a  session_id or SPID of the connection that has the transaction open.&nbsp; You  can pass this session_id to sp_who2 to determine which user has the  connection open.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Following queries can be ued to detemine recovery model and transaction log truncation interval:</p>
<p>SELECT name, recovery_model_desc&nbsp; FROM sys.databases;</p>
<pre>master SIMPLE<br />tempdb SIMPLE<br />model FULL<br />msdb SIMPLE<br />ReportServer SIMPLE<br />ReportServerTempDB SIMPLE<br />PRODUCTION_DB FULL</pre>
<p>SELECT name, log_reuse_wait_desc FROM sys.databases;</p>
<pre>master ACTIVE_TRANSACTION<br />tempdb ACTIVE_TRANSACTION<br />model NOTHING<br />msdb NOTHING<br />ReportServer NOTHING<br />ReportServerTempDB NOTHING<br />PRODUCTION_DB LOG_BACKUP</pre>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Results from above queries reveals that PRODUCTION_DB database is setup for FULL database  backup and transaction log will not be truncated until LOG_BACKUP.&nbsp; Make sure that you take full  backup followed by log backup that will make transactions log file&#8217;s  inactive blocks to be available for re-write and prevent from growing  further. Keep in mind that it will not shrink transaction log file . To  shrink the transaction log file you can follow steps described in <a href="http://support.microsoft.com/kb/907511/%20%20"> official docs</a>&nbsp; OR following is the  simple example of identifying and shrinking log file after taking log file backup:</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT name FROM sys.database_files WHERE type_desc = ‘LOG’</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Once I have log file name, I can use the DBCC command to shrink the file. In the following command I try to shrink my log file down to 1GB.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DBCC SHRINKFILE (’PRODUCTION_DB_log.log’, 1000)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Run the shrink command couple of times during the off-peak hours. Also, please&nbsp; make  sure that your databases are NOT set to auto-shrink. Auto-shrink  database might encounter performance problems.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Hopefully, it will help you next time you come across transaction log file &#8220;too large&#8221; issue on MS SQL server installation.</p></div>
<div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1537186761127784971-1370078045458400924?l=slowquery.blogspot.com' alt='' /></div>
]]></content:encoded>
			<wfw:commentRss>http://www.pateldenish.com/2011/12/shrink-ms-sql-server-transaction-logfile.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
