<?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>FuGeRTech &#187; MDF</title>
	<atom:link href="http://fugertech.com/tag/mdf/feed/" rel="self" type="application/rss+xml" />
	<link>http://fugertech.com</link>
	<description>Enduring, Sustainable Results</description>
	<lastBuildDate>Mon, 10 Jan 2011 23:09:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Dr. TransLog: Or How I Learned to Stop Worrying and Love SQL Server</title>
		<link>http://fugertech.com/2008/09/24/dr-translog-or-how-i-learned-to-stop-worrying-and-love-sql-server/</link>
		<comments>http://fugertech.com/2008/09/24/dr-translog-or-how-i-learned-to-stop-worrying-and-love-sql-server/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 16:15:20 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[LDF]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[MDF]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Microsoft SQL Server 2005]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Transaction Log]]></category>
		<category><![CDATA[WSS 3.0]]></category>

		<guid isPermaLink="false">http://www.fugertech.com/?p=50</guid>
		<description><![CDATA[Preface My current day job is developing SharePoint-based web applications. On Thursday, September 11 (coincidence), the SharePoint site became unresponsive. It was not storing any new data, but viewing existing data was still possible. This was important as I have end-users that rely on reports stored in Document Libraries. The daily reports would not save <a href='http://fugertech.com/2008/09/24/dr-translog-or-how-i-learned-to-stop-worrying-and-love-sql-server/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h2>Preface</h2>
<p>My current day job is developing SharePoint-based web applications. On Thursday, September 11 (coincidence), the SharePoint site became unresponsive. It was not storing any new data, but viewing existing data was still possible. This was important as I have end-users that rely on reports stored in Document Libraries. The daily reports would not save onto the website.</p>
<p>I&#8217;m sure that this article is SQL Server Administration 101 for most folks. For those diving into SharePoint with no DBA, this could be a lifesaver.</p>
<h2>Table of Contents</h2>
<p>Chapter 1: Transaction Log Deletion &#8211; what happens when I lost the WSS_Content transaction log<br />
Chapter 2: The Recovery &#8211; the steps to recovering the corrupt MDF file<br />
Chapter 3: Prevention &#8211; best practices for database and transaction log backup and truncation</p>
<p><span id="more-50"></span></p>
<h2>Chapter 1: Transaction Log Deletion</h2>
<p>After crawling around the servers a bit, I found out it was a disk space issue. Ends up that the Data drive for the SQL server that stores my SharePoint databases was full. I noticed a 136GB transaction log (LDF) file. I have not had formal SQL server training and the bulk of my experience is in the Linux world, so I was unsure of my next steps. Googling around I found people with similar issues and learned about sp_detach_db. I began to scramble as 8am was near and people would be coming into work. The detach was not working quickly enough. I shut down my SQL server processes and deleted the LDF file to start over on the transaction log. Little did I know that I just entered myself into a world of pain.</p>
<p>When the SQL server was brought back online, to my surprise, the WSS_Content database was toast. It would not allow access to it, and said that the database was corrupt. It was not shutdown cleanly&#8230; awesome news&#8230; lesson learned&#8230;</p>
<p>So, my first reaction is to call IT and ask for a restore of that file. More awesome news: &#8220;yea, the backups have been saying they were successful, but that file hasn&#8217;t been backed up&#8230;&#8221; Now I am worrying! I read further on Google results. I see forum replies saying things like, &#8220;well chances are if you lost your LDF file and the MDF won&#8217;t attach, the data is corrupt and you cannot get it back.&#8221;</p>
<p>I spend most of the day trying to find the right solution. Many of the answers on Google got me close, but did not work in the end. I find a piece of software called Stellar Phoenix SQL Database Recovery for $420. I think, well, I&#8217;ll try it and if it doesn&#8217;t work, I&#8217;ll get a refund. First problem I run into is the purchasing of the software. It takes 4 hours and 5 phone calls to get the software installed and the license working. They have a sales website that knows nothing about the software and their support team had me waiting on E-mails that never showed up. Again, lesson learned&#8230;</p>
<p>So, I finally have the software in hand. I rescue the MDF file, but to no avail. It transformed my 25GB MDF file into a 7MB MDF file. I apply for a refund (which is another story altogether). Soon, I learned to stop worrying and love SQL Server.</p>
<h2>Chapter 2: The Recovery</h2>
<p>At this point it is getting late in the evening and I am not getting anywhere. My brain is becoming mush, so I call it a night. The next morning I network around the office to learn of a colleague that is a SQL Server expert. She walks me through these steps and to my avail, the database comes back to life and SharePoint is happy. The icing on the cake is that I lost no data!</p>
<ol>
<li>Make a copy of the MDF file to a remote location just in case.</li>
<li>Rename the MDF file on the SQL server.</li>
<li>Run: <code>CREATE DATABASE WSS_Content</code> (Double check that it puts the MDF and LDF files in the same location as they were before. Add the proper options if need be.)</li>
<li>Shutdown the SQL server.</li>
<li>Copy original database MDF file over the newly created MDF file.</li>
<li>Rename, Move or Delete the newly create LDF file to &#8220;hide&#8221; it from SQL.</li>
<li>Start SQL server.</li>
<li>Run: <code>EXEC('ALTER DATABASE ''[WSS_Content]'' SET EMERGENCY');</code></li>
<li>Run: <code>ALTER DATABASE [WSS_Content] SET SINGLE_USER;</code></li>
<li>Run: <code>DBCC CHECKDB ([WSS_Content], REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS;</code></li>
<li>Run: <code>ALTER DATABASE [WSS_Content] SET MULTI_USER;</code></li>
</ol>
<h2>Chapter 3: Prevention</h2>
<p>At this point, my transaction log would still grow to enormous proportions without the proper practices. My colleague and SQL Server expert showed me how to run backups and truncate the transaction logs daily.</p>
<ul>
<li>Run full database backups that overwrite themselves the next day.
<ul>
<li>Create a job for running full backups as so for each database that needs to be backed up:<br />
<code>BACKUP DATABASE [WSS_Content] TO DISK='C:PATHTOBACKUP[WSS_Content].bak' WITH INIT</code></li>
<li>If the database needs to have the transaction log truncated, run this after the BACKUP DATABASE command:<br />
<code>BACKUP LOG [WSS_Content] TO DISK='C:PATHTOBACKUP[WSS_Content]_LOG.bak'</code></li>
<li>Schedule the job to run once nightly such that it will end prior to any tape backups.</li>
</ul>
</li>
<li>Optional, run transaction log backups every 4 hours to ensure that data from 4 hours ago can be recovered in case of a problem throughout the day.
<ul>
<li>For each database that needs to have the transaction log backed up and truncated run:<br />
<code>BACKUP LOG [WSS_Content] TO DISK='C:PATHTOBACKUP[WSS_Content]_LOG.bak'</code></li>
<li>Schedule the job to run every 4 hours and stop prior to the full database backup above.</li>
</ul>
</li>
</ul>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Ffugertech.com%2F2008%2F09%2F24%2Fdr-translog-or-how-i-learned-to-stop-worrying-and-love-sql-server%2F&amp;title=Dr.%20TransLog%3A%20Or%20How%20I%20Learned%20to%20Stop%20Worrying%20and%20Love%20SQL%20Server" id="wpa2a_2">Share/Save</a></p>]]></content:encoded>
			<wfw:commentRss>http://fugertech.com/2008/09/24/dr-translog-or-how-i-learned-to-stop-worrying-and-love-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

