Home > SQL Server Tips > SQL Server Management > Optimize database snapshots in SQL Server 2005
SQL Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

SQL SERVER MANAGEMENT

Optimize database snapshots in SQL Server 2005


Greg Robidoux, Edgewood Solutions
03.07.2007
Rating: --- (out of 5)


Expert advice on database administration
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


In a previous article, SQL Server 2005: When and how to use Database Snapshots, we took a look at the new database snapshot feature which is available only in SQL Server 2005 Enterprise and Developer Editions. Basically, a database snapshot allows you to create a static read-only copy of your database that can be used for other purposes, such as reporting, auditing or recovering data.

How it works
The database snapshot creates a database shell of your existing database. Then whenever data pages are changed the changes are written to sparse files. When the data is accessed any data that has not changed is retrieved from the original database and any changed data is retrieved from the sparse files.

To illustrate this, take a look at the picture below. The illustration shows us that 90 percent of the data has not been changed, so 90 percent of the data is still retrieved from the original database files when a query is issued. The additional 10 percent of the data that has changed is retrieved from the sparse file.

[IMAGE]
Source: SQL Server 2005 Books Online

Sparse files and the database snapshot
When a snapshot is created the initial creation is very quick, because only a shell is created to maintain the data that changes. Over time as data pages are changed, their original pages -- not the changed pages -- are written to the sparse files. The more the data changes in your primary database the more data has to be written to the sparse files. Therefore this will require more disk space to maintain your primary database, as well as the snapshot database and an increase in disk I/O on the your server.

Sparse files are written in 64KB chunks. Each of these increments can hold eight 8KB data pages. So each time any data is changed on a page in your primary database, the page is first copied to the sparse file and then the changes are made to your primary data file. Once these pages are written to the sparse fil


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
SQL Server Backup and Recovery
The keys to database backup protection for SQL Server
Choosing a SQL Server disaster recovery solution
Licensing a standby server for SQL Server replication
Can I encrypt and restore a database backup in SQL Server 2005?
SQL Server errors, failures and other problems fixed from the trenches
Get SQL Server log shipping functionality without Enterprise Edition
SQL Server 2008 backup compression pros and cons
SQL Server backups using SAN database snapshots
Tips for scheduling and testing SQL Server backups
Code to restore SQL Server databases in VB.NET
SQL Server Backup and Recovery Research

Microsoft SQL Server 2005 (Yukon)
SQL Server Reporting Services Fast Guide
SQL Server Service Broker Tutorial and Reference Guide
Tips for tuning SQL Server 2005 to improve reporting performance
SQL Server consolidation: Why it's an optimization technique
Parent-child dimensions in SQL Server 2005 with Analysis Services MDX
Enforcing data integrity in a SQL Server database
SSIS error message due to installation problem on SQL Server 2005
Should you upgrade to SQL Server 2005 or SQL Server 2008?
Basics for working with DATETIME and SMALLDATETIME in SQL Server 2005
How to configure Database Mail in SQL Server 2005 to send mail
Microsoft SQL Server 2005 (Yukon) Research

SQL Server Management
A first look at Microsoft SQL Server 2008 R2
Maintaining high availability of SQL Server virtual machines
Creating fault-tolerant SQL Server installations
Using Microsoft Hyper-V for SQL Server consolidation
Scaling up vs. scaling out with SQL Server 2008
Migrating to SQL Server 2008 and leveraging new features
Testing a SQL Server environment before an upgrade
Does upgrading to SQL Server 2008 fit your business?
Meeting business needs with SQL Server full-text search
Using dynamic management views to improve SQL Server index effectiveness

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
rollback  (SearchSQLServer.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


e they no longer need to be written out again, since the entire contents of the page are preserved from what they looked like when the snapshot was created.

In order to optimize and eliminate any disk contentions, it would be wise to create the sparse files on a separate drive and/or array than your primary database. The reason for this is two-fold.

  • First when the snapshot is created, no data is written to the sparse file. All data access from the snapshot is actually hitting the primary data files. As data changes over time you can decrease some of the I/O load by having any unchanged data retrieved from the primary database files and all changed data retrieved from the sparse files, which would reside on different arrays and/or disks.

  • Second, depending on the volatility your database and the amount of changes, you can decrease I/O bottleneck size by separating the reads from your primary database files and your writes to the sparse files.
  • Using the database snapshot
    The big thing to keep in mind here is that you are still accessing the primary database to fulfill your query requests. When the initial snapshot is created, only an empty shell is created and all data requests are fulfilled by the primary database files. As time goes on and changes are made, there is now some type of split between data requests from the original database files and the sparse files. So even though it looks like there is a separate database, the underlying data is still from the primary database.

    Based on this, you need to make sure not to issue other queries that are not outside the normal scope of your every day activities. Let's say you create a snapshot and you issue read writes, to everyone that writes reports. When these report queries are executed, they are still going to impact the primary database, so you need to ensure that any new activities do not impact the primary database activities.

    Also, you should review the amount of data that is in the sparse files, versus the overall potential of data that could be written to the sparse files. Basically, when the snapshot is created, the size of the primary database is the potential for the snapshot sparse files. If the amount of data that is in your sparse files becomes half or more than half the database size, maybe a better approach would be to create an entire copy of the database instead of using snapshots.

    Overall, I think the introduction of database snapshots is a great new feature. I still wish this was available in all versions of SQL Server 2005 and not just the Enterprise and Developer editions. One area that was not discussed was the use off snapshots with database mirroring. This gives you the best of both worlds, because the mirror is offline and you can not access the data, so this approach gives you the best of both worlds. Take the time to understand how snapshots can work in your environment and also make sure you monitor the impact of maintaining the snapshot as well as data access against the snapshot.


    [TABLE]

    More on this topic:

  • SQL Server 2005 backup and recovery: 5 handy tips
  • Database mirroring and its witness
  • Learning Center: New tools and enhancements in SQL Server 2005

    Rate this Tip
    To rate tips, you must be a member of SearchSQLServer.com.
    Register now to start rating these tips. Log in if you are already a member.




    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



  • SQL Server Development - .NET, C#, T-SQL, Visual Basic
    HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




    All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts