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

DATABASE MANAGEMENT AND ADMINISTRATION

Optimize database snapshots in SQL Server 2005


Greg Robidoux, Contributor
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.


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 file 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.


    ABOUT THE AUTHOR:   
    Greg Robidoux is the president and founder of Edgewood Solutions LLC, a technology services company delivering professional services and product solutions for Microsoft SQL Server. He has authored numerous articles and has delivered presentations at regional SQL Server users' groups and national SQL Server events. Robidoux, who also serves as the SearchSQLServer.com Backup and Recovery expert, welcomes your questions.
    Copyright 2007 TechTarget

    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.




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



    RELATED CONTENT
    Microsoft SQL Server Performance Monitoring and Tuning
    Using traces in SQL Server Profiler
    SQL Server Mailbag: CALs, witnesses and unwanted changes
    SQL Server Mailbag: Data restoration and DB property management
    Working with IntelliSense in SQL Server 2008 Management Studio
    SQL Server Mailbag: Stored procedures, triggers and SSRS reports
    Troubleshooting Distributed Transaction Coordinator errors in SQL Server
    Clearing the Windows page file and its effect on server performance
    Optimizing SQL Server indexes –- even when they're not your indexes
    Performance implications of transaction log autogrowth in SQL Server
    The short course on how SQL Server really works

    Microsoft SQL Server 2005
    End of life comes for SQL Server 2005 SP2, 2008
    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
    Microsoft SQL Server 2005 Research

    Database Management and Administration
    Password cracking tools for SQL Server
    Using traces in SQL Server Profiler
    Meet compliance requirements with improved database security practices
    Hardening the network and OS for SQL Server security
    Securing the server and database in SQL Server
    How SQL Server 2008 components impact SharePoint implementations
    Troubleshooting Distributed Transaction Coordinator errors in SQL Server
    Achieving high availability and disaster recovery with SharePoint databases
    Clearing the Windows page file and its effect on server performance
    Deploying a SQL Server virtual appliance for Microsoft Hyper-V

    RELATED GLOSSARY TERMS
    Terms from Whatis.com − the technology online dictionary
    contiguity  (SearchSQLServer.com)
    contiguous  (SearchSQLServer.com)
    drilldown  (SearchSQLServer.com)
    hashing  (SearchSQLServer.com)
    hybrid online analytical processing  (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

    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