<?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>Edwin M SarmientoShrink transaction log &#8211; Edwin M Sarmiento</title>
	<atom:link href="https://www.edwinmsarmiento.com/category/shrink-transaction-log/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.edwinmsarmiento.com</link>
	<description>Intentional Excellence</description>
	<lastBuildDate>Mon, 13 Apr 2026 21:00:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">84283043</site>		<item>
		<title>How to immediately shrink the SQL Server log files</title>
		<link>https://www.edwinmsarmiento.com/how-to-immediately-shrink-the-sql-server-log-files/</link>
		<comments>https://www.edwinmsarmiento.com/how-to-immediately-shrink-the-sql-server-log-files/#respond</comments>
		<pubDate>Tue, 10 Mar 2009 06:23:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[Shrink transaction log]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2009/03/10/how-to-immediately-shrink-the-sql-server-log-files</guid>

				<description><![CDATA[NOTE: I don&#8217;t really recommend shrinking database files unless it is really necessary. Have you ever wanted to shrink your log files but couldn&#8217;t do it no matter how hard you try? While I and the majority of SQL Server DBAs would not recommend shrinking the transaction log (or any data file in your database), [&#8230;]]]></description>
					<content:encoded><![CDATA[<p><strong>NOTE:</strong> I don&#8217;t really recommend shrinking database files unless it is really necessary.</p>
<p><span style="font-family:arial;">Have you ever wanted to shrink your log files but couldn&#8217;t do it no matter how hard you try? While I and the majority of SQL Server DBAs would not recommend shrinking the transaction log (or any </span><span style="font-family:arial;">data file in your database), you&#8217;ll end up doing it one way or another due to emergency situations. Here&#8217;s what you&#8217;ll probably end up doing as defined in this <a href="http://support.microsoft.com/kb/907511">Microsoft KB</a> article:</span></p>
<ul>
<li>Backup the transaction log. This will truncate the log</li>
<li>Shrink the log file</li>
</ul>
<p><span style="font-family:arial;">Pretty simple, right? Well, there are times when this might not work because SQL Server does not shrink the log immediately. The DBCC SHRINKFILE operation occurs only at checkpoints or transaction log backups. SQL Server divides each physical log file internally into a number of virtual log files (VLFs), which make up the transaction log. This <a href="http://msdn.microsoft.com/en-us/library/aa933049(SQL.80).aspx">MSDN article</a> describes virtual log files in SQL Server. <a href="http://www.karaszi.com/SQLServer/info_dont_shrink.asp">SQL Server MVP Tibor Karaszi</a> highlights why you would not want to shrink your log files. This <a href="http://johnnynine.com/blog/HowToImmediatelyShrinkSqlServerLogFilesLDFFiles.aspx">blog by Johnny Hughes</a> has a script that lets you do this task.</span></p>
<p><span style="font-size:130%;"><span style="font-family:courier new;font-size:85%;color:blue;"><strong><em>USE </em></strong></span><span style="font-size:85%;"><strong><em><span style="font-family:courier new;"><span style="color:black;">databaseName<br />
GO</span></span></em></strong></span></span></p>
<p><span style="color:blue;">DBCC </span><span style="color:black;">shrinkfile</span><span style="color:gray;">(&lt;</span><span style="color:black;">file_id</span><span style="color:gray;">&gt;,</span><span style="color:black;">NOTRUNCATE</span><span style="font-size:85%;"><strong><em><span style="font-family:courier new;"><span style="color:gray;">)<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">shrinkfile</span><span style="color:gray;">(&lt;</span><span style="color:black;">file_id</span><span style="color:gray;">&gt;</span><span style="color:black;">TRUNCATEONLY</span></span></em></strong></span><span style="font-size:85%;"><strong><em><span style="font-family:courier new;"><span style="color:gray;">)</span></span></em></strong></span></p>
<p><span style="color:blue;">CREATE TABLE </span><span style="color:black;">t1 </span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:black;">1 </span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">4000</span><span style="font-family:courier new;font-size:85%;color:gray;"><strong><em>))<br />
</em></strong></span><span style="font-size:85%;"><strong><em><span style="font-family:courier new;"><span style="color:black;">GO</span></span></em></strong></span></p>
<p><span style="color:blue;">DECLARE </span><span style="color:#434343;">@i </span><span style="font-size:85%;"><strong><em><span style="font-family:courier new;"><span style="color:blue;">INT<br />
SELECT </span><span style="color:#434343;">@i </span><span style="color:blue;">= </span></span></em></strong></span><span style="font-size:85%;"><strong><em><span style="font-family:courier new;"><span style="color:black;">0<br />
</span><span style="color:blue;">WHILE </span><span style="color:gray;">(</span><span style="color:black;">1 </span><span style="color:blue;">= </span><span style="color:black;">1</span></span></em></strong></span><span style="font-family:courier new;font-size:85%;color:gray;"><strong><em>)</em></strong></span></p>
<p><span style="font-size:85%;"><strong><em><span style="font-family:courier new;"><span style="color:blue;">BEGIN<br />
WHILE </span><span style="color:gray;">(</span><span style="color:#434343;">@i </span><span style="color:gray;">&lt; </span><span style="color:black;">100</span></span></em></strong></span><span style="font-family:courier new;font-size:85%;color:gray;"><strong><em>)<br />
</em></strong></span><span style="font-size:85%;"><strong><em><span style="font-family:courier new;"><span style="color:blue;">BEGIN<br />
INSERT INTO </span><span style="color:black;">t1 </span><span style="color:blue;">VALUES </span><span style="color:gray;">(</span><span style="color:red;">&#8216;a&#8217;</span></span></em></strong></span><span style="font-size:85%;"><strong><em><span style="font-family:courier new;"><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@i </span><span style="color:blue;">= </span><span style="color:#434343;">@i </span><span style="color:gray;">+</span></span></em></strong></span><span style="font-family:courier new;font-size:85%;color:black;"><strong><em>1<br />
</em></strong></span><span style="font-family:courier new;font-size:85%;color:blue;"><strong><em>END</em></strong></span></p>
<p>TRUNCATE TABLE <span style="font-size:85%;"><strong><em><span style="font-family:courier new;"><span style="color:black;">t1</span></span></em></strong></span></p>
<p><span style="color:blue;">BACKUP </span><span style="color:magenta;">LOG </span><span style="color:black;">databaseName </span><span style="color:blue;">WITH </span><span style="font-family:courier new;font-size:85%;color:black;"><strong><em>TRUNCATE_ONLY<br />
</em></strong></span><span style="color:blue;"><strong><em><span style="font-family:courier new;"><span style="font-size:85%;">END</span> </span></em></strong></span></p>
<p>&nbsp;</p>
<div class="blogger-post-footer"><img decoding="async" src="" alt="" width="1" height="1" /></div>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/how-to-immediately-shrink-the-sql-server-log-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">168</post-id>	</item>
	</channel>
</rss>