<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Esoteric : SQL Architecture</title><link>http://blogs.msdn.com/arvindsh/archive/tags/SQL+Architecture/default.aspx</link><description>Tags: SQL Architecture</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Some notes on database snapshots</title><link>http://blogs.msdn.com/arvindsh/archive/2008/12/31/some-notes-on-database-snapshots.aspx</link><pubDate>Wed, 31 Dec 2008 10:29:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9258192</guid><dc:creator>arvindsh</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/arvindsh/comments/9258192.aspx</comments><wfw:commentRss>http://blogs.msdn.com/arvindsh/commentrss.aspx?PostID=9258192</wfw:commentRss><description>&lt;p&gt;&lt;strong&gt;Overview&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;I recently conducted some tests to double check the exact behavior of database snapshots when:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Snapshots are created on volumes which are much smaller than the actual database size&lt;/li&gt; &lt;li&gt;Metadata-only operations such as DROP TABLE are executed&lt;/li&gt; &lt;li&gt;DDL operations execute on the main database and the snapshot runs out of disk space&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Here is my testing methodology and the customary summary of observations.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Scenario&lt;/strong&gt;&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Drive C: contains the original data file for database TestSS. Data file size = 1.95GB &lt;/li&gt; &lt;li&gt;TestSS.dbo.T1 is a table which contains 1GB of data &lt;/li&gt; &lt;li&gt;TestSS_1 is a snapshot which was created on TestSS after the 1GB data insert was completed.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;strong&gt;Test Case A: Can we create a snapshot on volume smaller than the database size?&lt;/strong&gt;&lt;/p&gt; &lt;ol&gt; &lt;li&gt;The snapshot TestSS_1 was created on volume T: which is 10MB in size.&lt;/li&gt; &lt;li&gt;Size on disk for snapshot at creation = 192KB&lt;/li&gt; &lt;li&gt;&lt;u&gt;The snapshot creation succeeded without any errors.&lt;/u&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;If you are curious as to what I mean by 'size on disk', please refer to this snapshot:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/arvindsh/WindowsLiveWriter/Somenotesondatabasesnapshots_B574/image_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="484" alt="image" src="http://blogs.msdn.com/blogfiles/arvindsh/WindowsLiveWriter/Somenotesondatabasesnapshots_B574/image_thumb.png" width="357" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;It is a property of the &lt;a href="http://msdn.microsoft.com/en-us/library/ms175823.aspx"&gt;NTFS sparse file&lt;/a&gt; that the actual space occupied on disk is much lesser initially than the 'Size' which is displayed for that file in Explorer.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Test Case B: Metadata-only operations and snapshot files&lt;/strong&gt;&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Next, I executed a DROP TABLE T1 on TestSS, which &lt;u&gt;returned immediately without any errors&lt;/u&gt;. At this time the snapshot did not have a large ‘on disk size’ – just 1.48MB&lt;/li&gt; &lt;li&gt;At this time the data is accessible through the snapshot just fine. If you do a select count(1) from testSS..T1 it fails (as expected). So the main operation (DROP TABLE) worked just fine.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;How is this possible? It turns out that certain operations such as TRUNCATE TABLE, DROP TABLE etc. &lt;a href="http://blogs.msdn.com/sqlserverstorageengine/archive/2006/06/24/645803.aspx"&gt;directly operate on the IAM chain&lt;/a&gt; and possibly other internal allocation pages to efficiently 'clean up' data and metadata. In such cases the copy-on-write to the snapshot is deferred till such time that the actual data page and extent are touched.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Test Case 3: What effect does failure to write to the snapshot have on the main database?&lt;/strong&gt;&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Next, I reverted the database TestSS to the snapshot TestSS_1 and then dropped the TestSS_1 snapshot. How do you revert a database to a snapshot? You use the RESTORE DATABASE ... command like this: &lt;em&gt;RESTORE DATABASE TestSS FROM DATABASE_SNAPSHOT &lt;b&gt;=&lt;/b&gt; TestSS_1&lt;/em&gt;&lt;/li&gt; &lt;li&gt;I recreated TestSS_1 immediately using the &lt;em&gt;CREATE DATABASE ... AS SNAPSHOT ... &lt;/em&gt;&lt;/li&gt; &lt;li&gt;Next, I executed &lt;em&gt;DELETE T1&lt;/em&gt; to force a logged data operation and it executed for some time before finally returning these errors:&lt;/li&gt;&lt;/ol&gt; &lt;blockquote&gt; &lt;p&gt;Msg 5128, Level 17, State 2, Line 1 &lt;p&gt;Write to sparse file 't:\Data\testss_1.ss' failed due to lack of disk space. &lt;p&gt;Msg 5128, Level 17, State 2, Line 1 &lt;p&gt;Write to sparse file 't:\Data\testss_1.ss' failed due to lack of disk space. &lt;p&gt;Msg 5128, Level 17, State 2, Line 1 &lt;p&gt;Write to sparse file 't:\Data\testss_1.ss' failed due to lack of disk space.&lt;/p&gt;&lt;/blockquote&gt; &lt;blockquote&gt; &lt;p&gt;&lt;u&gt;Though, interestingly the main DELETE did not fail; all rows from the table T1 have been deleted.&lt;/u&gt; It is by-design that any failures to write to the snapshot are not going to affect the primary operation on the database. &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;So in conclusion this is what we can learn from the above. Most of it is logical when you think about it, but it is better to be sure than to guess!&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Database snapshots can most definitely be created on volumes which are much smaller than the original database size&lt;/li&gt; &lt;li&gt;Metadata only operations initially do not affect the snapshot. Only when the underlying pages are really 'cleaned up' by subsequent system processes, will the copy of the affected pages be moved into the database snapshot's sparse file&lt;/li&gt; &lt;li&gt;Failures to write to the snapshot will never affect the original database on which the DDL is being executed&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;strong&gt;Additional Reading&lt;/strong&gt;&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Please also refer to the excellent white paper on &lt;a href="http://download.microsoft.com/download/d/9/4/d948f981-926e-40fa-a026-5bfcf076d9b9/DBSnapshotPerf.docx"&gt;Database Snapshots Performance Considerations Under IO Intensive Workloads&lt;/a&gt; for some more information on snapshots and their effect on performance.&lt;/li&gt; &lt;li&gt;Paul Randal's blogs about &lt;a href="http://www.sqlskills.com/blogs/paul/category/Database-Snapshots.aspx"&gt;snapshots&lt;/a&gt;.&lt;/li&gt; &lt;li&gt;Good information on snapshot internals is at the &lt;a href="http://sqlcat.com/technicalnotes/archive/2007/09/11/querying-a-database-snapshot.aspx"&gt;SQL CAT Team website&lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9258192" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/arvindsh/archive/tags/SQL+Architecture/default.aspx">SQL Architecture</category></item><item><title>Resources from TechEd sessions</title><link>http://blogs.msdn.com/arvindsh/archive/2006/06/15/631799.aspx</link><pubDate>Thu, 15 Jun 2006 06:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:631799</guid><dc:creator>arvindsh</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/arvindsh/comments/631799.aspx</comments><wfw:commentRss>http://blogs.msdn.com/arvindsh/commentrss.aspx?PostID=631799</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Arial size=2&gt;Several attendees have asked for the resources section from our presentations at TechEd India. Enjoy!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;&lt;STRONG&gt;Blogs&lt;BR&gt;&lt;/STRONG&gt;SQLCAT: &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/sqlcat"&gt;&lt;FONT face=Arial size=2&gt;http://blogs.msdn.com/sqlcat&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Arial size=2&gt; &lt;BR&gt;WINCAT: &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/wincat"&gt;&lt;FONT face=Arial size=2&gt;http://blogs.msdn.com/wincat&lt;/FONT&gt;&lt;/A&gt;&lt;BR&gt;&lt;FONT face=Arial size=2&gt;Slava Oks’ blog: &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/slavao"&gt;&lt;FONT face=Arial size=2&gt;http://blogs.msdn.com/slavao&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;&lt;STRONG&gt;Product Feedback&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face=Arial size=2&gt;&lt;STRONG&gt;&lt;BR&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;A href="http://lab.msdn.microsoft.com/productfeedback/"&gt;&lt;FONT face=Arial size=2&gt;http://lab.msdn.microsoft.com/productfeedback/&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;&lt;STRONG&gt;External Links:&lt;BR&gt;&lt;/STRONG&gt;NUMA FAQ: &lt;/FONT&gt;&lt;A href="http://lse.sourceforge.net/numa/faq"&gt;&lt;FONT face=Arial size=2&gt;http://lse.sourceforge.net/numa/faq&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;&lt;STRONG&gt;Books:&lt;BR&gt;&lt;/STRONG&gt;Inside Microsoft SQL Server 2005: Query Processing and Optimization (Volume 3)&lt;BR&gt;The Guru's Guide to SQL Server Architecture and Internals (SQL Server 2000)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;&lt;STRONG&gt;SQL Server 2005 – Operations&amp;nbsp;&lt;BR&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;A href="http://www.microsoft.com/technet/prodtechnol/sql/2005/library/operations.mspx"&gt;&lt;FONT face=Arial size=2&gt;http://www.microsoft.com/technet/prodtechnol/sql/2005/library/operations.mspx&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;&lt;STRONG&gt;Whitepapers&lt;BR&gt;&lt;/STRONG&gt;Troubleshooting Performance Problems in SQL Server 2005 &lt;/FONT&gt;&lt;A href="http://www.microsoft.com/technet/prodtechnol/sql/2005/tsprfprb.mspx"&gt;&lt;FONT face=Arial size=2&gt;(http://www.microsoft.com/technet/prodtechnol/sql/2005/tsprfprb.mspx&lt;/FONT&gt;&lt;/A&gt;)&lt;BR&gt;&lt;FONT face=Arial size=2&gt;Batch Compilation, Recompilation, and Plan Caching Issues in SQL Server 2005(&lt;/FONT&gt;&lt;A href="http://www.microsoft.com/technet/prodtechnol/sql/2005/recomp.mspx"&gt;&lt;FONT face=Arial size=2&gt;http://www.microsoft.com/technet/prodtechnol/sql/2005/recomp.mspx&lt;/FONT&gt;&lt;/A&gt;)&lt;BR&gt;&lt;FONT face=Arial size=2&gt;Statistics Used by the Query Optimizer in SQL Server 2005 (&lt;/FONT&gt;&lt;A href="http://www.microsoft.com/technet/prodtechnol/sql/2005/qrystats.mspx"&gt;&lt;FONT face=Arial size=2&gt;http://www.microsoft.com/technet/prodtechnol/sql/2005/qrystats.mspx&lt;/FONT&gt;&lt;/A&gt;)&lt;FONT face=Arial size=2&gt;&lt;BR&gt;SQL Server 2000 I/O Basics (&lt;/FONT&gt;&lt;A href="http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/sqlIObasics.mspx"&gt;&lt;FONT face=Arial size=2&gt;http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/sqlIObasics.mspx&lt;/FONT&gt;&lt;/A&gt;)&lt;FONT face=Arial size=2&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face=Arial size=2&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;&lt;STRONG&gt;Webcasts&lt;BR&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face=Arial size=2&gt;Troubleshooting Performance Problems In SQL Server 2005 (&lt;/FONT&gt;&lt;A href="http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?EventID=1032275646&amp;amp;EventCategory=5&amp;amp;culture=en-US&amp;amp;CountryCode=US"&gt;&lt;FONT face=Arial size=2&gt;http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?EventID=1032275646&amp;amp;EventCategory=5&amp;amp;culture=en-US&amp;amp;CountryCode=US&lt;/FONT&gt;&lt;/A&gt;)&lt;FONT face=Arial size=2&gt;&lt;BR&gt;Performance Diagnosis in SQL Server 2005 (&lt;/FONT&gt;&lt;A href="http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?EventID=1032275586&amp;amp;EventCategory=5&amp;amp;culture=en-US&amp;amp;CountryCode=US"&gt;&lt;FONT face=Arial size=2&gt;http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?EventID=1032275586&amp;amp;EventCategory=5&amp;amp;culture=en-US&amp;amp;CountryCode=US&lt;/FONT&gt;&lt;/A&gt;)&lt;FONT face=Arial size=2&gt;&lt;BR&gt;Supportability features for SQL Server 2005&lt;BR&gt;&lt;/FONT&gt;(&lt;A href="http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?EventID=1032275593&amp;amp;EventCategory=5&amp;amp;culture=en-US&amp;amp;CountryCode=US"&gt;&lt;FONT face=Arial size=2&gt;http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?EventID=1032275593&amp;amp;EventCategory=5&amp;amp;culture=en-US&amp;amp;CountryCode=US&lt;/FONT&gt;&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;&lt;STRONG&gt;PASS 2005 PSS Service Center Labs&lt;BR&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=9b8098a7-e75f-462a-b296-e80199c9f323&amp;amp;displaylang=en"&gt;&lt;FONT face=Arial size=2&gt;http://www.microsoft.com/downloads/details.aspx?FamilyID=9b8098a7-e75f-462a-b296-e80199c9f323&amp;amp;displaylang=en&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=631799" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/arvindsh/archive/tags/SQL+Architecture/default.aspx">SQL Architecture</category><category domain="http://blogs.msdn.com/arvindsh/archive/tags/SQL+General/default.aspx">SQL General</category></item><item><title>Database Snapshots</title><link>http://blogs.msdn.com/arvindsh/archive/2006/06/07/620232.aspx</link><pubDate>Wed, 07 Jun 2006 07:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:620232</guid><dc:creator>arvindsh</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/arvindsh/comments/620232.aspx</comments><wfw:commentRss>http://blogs.msdn.com/arvindsh/commentrss.aspx?PostID=620232</wfw:commentRss><description>&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana"&gt;DB Snapshots are a very useful new feature in SQL Server 2005 Enterprise Edition. They provide us the ability to preserve a consistent picture of the database as it was at a point in time. Both metadata and data are captured in the snapshot.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana"&gt;The &lt;A href="http://msdn2.microsoft.com/en-us/library/ms175472.aspx"&gt;main uses of snapshots&lt;/A&gt; are for preserving views of the database for reporting purposes, and also to easily recover data affected by user error. Snapshots also provide a means to &lt;A href="http://msdn2.microsoft.com/en-us/library/ms175511.aspx"&gt;view the data in the mirror database&lt;/A&gt;.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana"&gt;DB Snapshots use "sparse files", which means that the actual snapshot size on disk will be very small initially and would only grow by recording the the changes to the database using a &lt;A href="http://msdn2.microsoft.com/en-us/library/ms187054.aspx"&gt;copy-on-write scheme&lt;/A&gt;.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana"&gt;Another cool feature of snapshots for recovering from administrative or user error is the ability to &lt;A href="http://msdn2.microsoft.com/en-us/library/ms179557.aspx"&gt;revert a database back to a snapshot&lt;/A&gt;. This is potentially much quicker than restoring a full backup, as we only copy the changed pages from the snapshot back into the data files. But there are other implications of reverting to a snapshot - most important being the fact that we rebuild the log in such cases. To ensure recoverability of all transactions committed after the snapshot was taken, be sure to backup the log prior to using this feature.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=620232" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/arvindsh/archive/tags/SQL+Architecture/default.aspx">SQL Architecture</category><category domain="http://blogs.msdn.com/arvindsh/archive/tags/SQL+General/default.aspx">SQL General</category></item></channel></rss>