Home > SQL Server Tips > Database Administration > SQL Server bulk-logged recovery
SQL Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

DATABASE ADMINISTRATION

SQL Server bulk-logged recovery


Greg Robidoux, Contributor
01.03.2007
Rating: -4.25- (out of 5)


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


SQL Server offers three types of recovery models: simple, full and bulk-logged. These models offer varying levels of recovery for restoring your databases from your backups. Bulk-logged recovery advantages include minimal space requirements for transaction logs and the best performance for bulk operations. Watch out, though. One disadvantage is that with a bulk-logged transaction in your backup file, you cannot do a point-in-time recovery.

In this tip, I'll explain the circumstances where you'd want to opt for bulk-logged recovery in SQL Server and what steps you'll need to take to restore a database set in that model.

As a recap, here are the differences between each recovery model:

Simple
The simple recovery model allows you to recover data only to the most recent full backup or differential backup. Transaction log backups are not available because the contents of the transaction log are truncated each time a checkpoint is issued for the database.

Full
The full recovery model can use full backups, differential backups and transaction log backups to provide a safety net against complete failure. Along with being able to restore a full or differential backup, you can recover the database to the point of failure or to a specific point in time. All operations, including bulk operations such as SELECT INTO, CREATE INDEX and bulk-loading data, are fully logged and recoverable.

Bulk-logged
The bulk-logged recovery model protects against failure and offers the best performance. In order to get better performance, the following operations are minimally logged and not fully recoverable: SELECT INTO, bulk-load operations, CREATE INDEX as well as text and image operations. Under the bulk-logged recovery model, a damaged data file can result in having to redo work manually based on the operations that are not fully logged. In addition, the bulk-logged recovery model allows the database to be recovered to the end of a trans


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 Performance Monitoring and Tuning
Performance implications of transaction log autogrowth in SQL Server
The short course on how SQL Server really works
Determining the source of full transaction logs in SQL Server
Improving SQL Server full-text search performance
New GROUP BY option provides better data control in SQL Server 2008
Microsoft SQL Server 2008 Resource Governor primer
Examining data files when SQL Server tempdb is full
Testing transaction log autogrowth behavior in SQL Server
Meeting business needs with SQL Server full-text search
Using dynamic management views to improve SQL Server index effectiveness

Database Administration
Top load balancing methods for SQL Server
Performance implications of transaction log autogrowth in SQL Server
The keys to database backup protection for SQL Server
Understanding transparent data encryption in SQL Server 2008
Working with sparse columns in SQL Server 2008
Determining the source of full transaction logs in SQL Server
Implementing SQL Server 2008 FILESTREAM functionality
Improving SQL Server full-text search performance
Using the OPENROWSET function in SQL Server
New replication features in SQL Server 2008 and what they mean to you

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


action log backup only when the log backup contains bulk changes.

Benefits of bulk-logged
The primary benefit of of using the bulk-logged recovery model is that it minimizes the space requirements for the transaction log so it can track every single operation that is part of the transaction. This is helpful if you have large systems where you import large sets of data or create large indexes. The transaction still gets committed and written to your data file, but the space requirements for the transaction log are not as great as with the full recovery model. From testing, you will see that inserting data still requires a lot of transaction log space, but the space needed to create indexes is greatly reduced.

The way SQL Server backups and recovery models work, you have the option of changing your model from full recovery to bulk-logged recovery and back as needed without interfering with your transaction log backups. This allows you to keep the size of your transaction log in check when doing large bulk-logged transactions.

The one thing to note is how the transactions are written to your transaction log backup. If there is a bulk-logged transaction in your backup file, you cannot do a point-in-time recovery. This is one of the biggest things you will notice with the restore process. When a bulk-logged transaction exists in a transaction log backup, you have to restore the entire transaction log.

Backup process
The backup process works the same way, whether you have your database in the full or bulk-logged recovery model. You still have the option of using full, differential or transaction log backups. The commands are exactly the same, as shown here:

BACKUP DATABASE Test TO DISK='C:\Test_full.BAK'

BACKUP DATABASE Test TO DISK='C:\Test_diff.BAK' WITH DIFFERENTIAL

BACKUP LOG Test TO DISK='C:\Test_log.TRN'

Another key thing to note with your transaction log backups is the size of the transaction log backup file. If you set your database to bulk-logged recovery and issue a minimally logged transaction like CREATE INDEX, you will see that your transaction log itself does not get that large. But when you issue the transaction log backup statement, the backup file may be a lot larger because of all the data that needs to be replayed in order to restore your database to the same state.

Restore process
The restore process is very similar to the restore perspective . The one difference is that you cannot do a point-in-time restore if the transaction log backup file contains any bulk-logged transactions. If you try to issue the restore using point-in-time recovery, and the transaction log backup has bulk-logged activity, you will get this error message:

Server: Msg 4327, Level 16, State 1, Line 1
The log in this backup set contains minimally logged changes. Point-in-time recovery is inhibited. RESTORE will roll forward to end of logs without recovering the database.

You can use the following commands to do a restore when the database is set to bulk-logged recovery: (As you can see, these commands are identical regardless of whether the database is in full or bulk-logged recovery.)

RESTORE DATABASE Test FROM DISK='C\Test_full.BAK' WITH NORECOVERY

RESTORE DATABASE Test FROM DISK='C:\Test_diff.BAK' WITH NORECOVERY

RESTORE LOG Test FROM DISK='C:\Test_log.TRN' WITH RECOVERY

What real benefits do you gain from using bulk-logged recovery? A lot depends on your environment. If you are issuing a huge amount of bulk insert statements and dropping and recreating indexes on the fly for batch processing, the bulk-logged recovery model may be the way to go. If you have a normal environment, where the data is not constantly in flux, the full recovery model may be the better bet. With any option you choose, the simpler route often causes more headaches further down the line, so choose your recovery model wisely and plan your recovery process accordingly.


[TABLE]


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