<?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>SQL Slayer &#187; Snapshot</title>
	<atom:link href="http://www.sqlslayer.com/wp/tag/snapshot/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sqlslayer.com/wp</link>
	<description>Making SQL do what we want it to do.</description>
	<lastBuildDate>Mon, 12 Dec 2011 13:53:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>DBCC CHECKDB with readonly filegroups</title>
		<link>http://www.sqlslayer.com/wp/2009/10/07/dbcc-checkdb-with-readonly-filegroups/</link>
		<comments>http://www.sqlslayer.com/wp/2009/10/07/dbcc-checkdb-with-readonly-filegroups/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 19:20:08 +0000</pubDate>
		<dc:creator>mstanford</dc:creator>
				<category><![CDATA[DBCC]]></category>
		<category><![CDATA[CHECKDB]]></category>
		<category><![CDATA[Integrity]]></category>
		<category><![CDATA[Mainteancne]]></category>
		<category><![CDATA[Snapshot]]></category>

		<guid isPermaLink="false">http://www.sqlslayer.com/wp/?p=83</guid>
		<description><![CDATA[<p>I can&#8217;t believe this.  I&#8217;ve got a large (2+ TB) database that I want to do daily integrity checks on.  Because it is so big, I was using PHYSICAL_ONLY.  Here&#8217;s the command:

DBCC CHECKDB(BigDB) WITH PHYSICAL_ONLY, TABLERESULTS, NO_INFOMSGS, ALL_ERRORMSGS

I very quickly get this error:</p>

Msg 5030, Level 16, State 12, Line 1 The database [...]]]></description>
			<content:encoded><![CDATA[<p>I can&#8217;t believe this.  I&#8217;ve got a large (2+ TB) database that I want to do daily integrity checks on.  Because it is so big, I was using PHYSICAL_ONLY.  Here&#8217;s the command:<br />
<code><br />
DBCC CHECKDB(BigDB) WITH PHYSICAL_ONLY, TABLERESULTS, NO_INFOMSGS, ALL_ERRORMSGS<br />
</code><br />
I very quickly get this error:</p>
<pre>
Msg 5030, Level 16, State 12, Line 1 The database could not be exclusively locked to perform the operation.
Msg 7926, Level 16, State 1, Line 1
Check statement aborted. The database could not be checked as a database snapshot could not be created and the database or table could not be locked. See Books Online for details of when this behavior is expected and what workarounds exist. Also see previous errors for more details.
</pre>
<p>After a quick google search I found <a href="http://support.microsoft.com/kb/928518">this</a> KB article that explains the issue.  Evidently DBCC CHECKDB doesn&#8217;t work against databases that contain filegroups that are flagged as read-only.  Wow.</p>
<p>The recommend work around is to take a snapshot of the database, check the snapshot, and then drop the snapshot.  This is what I thought DBCC CHECKDB does internally anyways!  Oh well, this isn&#8217;t the strangest thing I&#8217;ve ever heard of coming from Microsoft.</p>
<p>Here&#8217;s what I came up with as a workaround:<br />
<code><br />
DECLARE<br />
	@SnapName	NVARCHAR(128)<br />
	,@SQL		NVARCHAR(4000)</p>
<p>EXEC admin.dbo.SnapshotDB 'BigDB', @SnapName OUTPUT</p>
<p>BEGIN TRY<br />
	SET @SQL = 'DBCC CHECKDB(' + @SnapName + ') WITH PHYSICAL_ONLY, TABLERESULTS, NO_INFOMSGS, ALL_ERRORMSGS'<br />
	EXEC(@SQL)<br />
	SET @SQL = 'DROP DATABASE [' + @SnapName + ']'<br />
	EXEC(@SQL)<br />
END TRY<br />
BEGIN CATCH<br />
	SET @SQL = 'DROP DATABASE [' + @SnapName + ']'<br />
	EXEC(@SQL)<br />
	RAISERROR('DBCC CHECKDB failed on BigDB.  Panic.',16,2)<br />
END CATCH<br />
</code></p>
<p>Strange stuff.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sqlslayer.com/wp/2009/10/07/dbcc-checkdb-with-readonly-filegroups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

