IT tutorials
 
Database
 

SQL Server 2008 R2 : Database Backup and Restore (part 2) - Recovery Models

11/17/2012 5:00:16 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
Each database has a recovery model that determines how transactions will be written to the transaction log. The recovery model you choose has a direct impact on your ability to recover from a media failure. These following three recovery models are available with SQL Server 2008:

You set the recovery model via T-SQL or the Database Properties window in SSMS. The following example shows the T-SQL command you can use to change the AdventureWorks2008 database to the bulk-logged model:

ALTER DATABASE [AdventureWorks2008] SET RECOVERY BULK_LOGGED WITH NO_WAIT

Figure 1 shows the Options page on the Database Properties window, which also allows you to select a recovery model.

Figure 1. Setting the recovery model in SSMS.

Full Recovery

The full recovery model gives you the most protection against data loss. A database set to full recovery will have all database operations written to the transactions log. These operations include insertions, updates, and deletions, as well as any other statements that change the database. In addition, the full recovery model captures any database inserts that are the result of a BCP command or BULK INSERT statement.

In the event of a media failure, a database that is in full recovery can be restored to the point in time at which the failure occurred. Your ability to restore to a point in time is dependent on your database backup plan. If a full database backup is available, along with the transaction log backups that occurred after the full database backup, you can recover to the point of the last transaction log backup. In addition, if your current transaction log is available, you can restore up to the point of the last committed transaction in the transaction log.

This recovery model is the most comprehensive, but in some respects, it is the most expensive. It is expensive in terms of the transaction log space needed to capture all the database operations. The space can be significant with databases that have a lot of update activity or with databases that have large bulk load operations. It is also expensive in terms of server overhead because every transaction is captured and retained in the transaction log so that they can be recovered in the event of a failure.

Tip

A common problem in SQL Server environments involves a database that is set to full recovery but whose transaction log is never backed up. In this scenario, the transaction log can grow to the point that it fills up the drive on which the transaction log is located. You need to ensure that you have regularly scheduled backups of the transaction log if you have set your database to full recovery. The transaction log backups allow you to recover from a media failure and also remove the inactive portion of the transaction log so that it does not need to grow.


Bulk-Logged Recovery

The bulk-logged recovery model is similar to full recovery, but it differs in the way that bulk operations are captured in the transaction log. With full recovery mode, SQL Server writes every row to the transaction log that is inserted with BCP or BULK INSERT. Bulk-logged recovery keeps track of the extents that have been modified by a bulk load operation but does not write each row to the transaction log. This reduces the overall size of the transaction log during bulk load operations and still allows the database to recover after a bulk load operation has occurred.

The biggest downside to setting a database to bulk-logged recovery is that the log backups for the databases can be large. The log backups are large because SQL Server copies all the data extents that have been affected by bulk load operations since the last backup of the transaction log. Remember that data extents consist of eight data pages each, and each page is 8KB in size. This may not seem like much by today’s standards, but it can be significant when you’re bulk loading a large table. For example, consider a table occupying 1GB of space that is truncated each week and reloaded with a bulk insert. The bulk insert operation goes relatively fast because the rows are not being written to the transaction log, but the backup of the transaction log is much larger.

Note

In testing we did on a table with approximately 2.4 million rows (that occupied 500MB of space), the log file grew over 2GB during a bulk insert operation that reloaded all rows in a full recovery mode database. In contrast, the same bulk insert operation on the database with bulk-logged recovery grew the log by only 9MB. However, the backup of the 9MB transaction log was approximately 500MB. This is much larger than the actual log itself because the bulk operation caused all the modified extents from the bulk insert operation to be stored in the log backup as well.


The other downside to bulk-logged recovery is that with it, you may sacrifice the ability to restore to the most recent point in time. This situation occurs if a bulk insert operation has occurred since the last database backup and a media failure occurs. In this case, the restores can occur for any backups that were taken that do not contain a bulk insert operation, but any outstanding changes that were retained in the transaction log cannot be applied. The reason is that bulk operations are not written to the log directly in this model and cannot be recovered. Only bulk operations captured in a backup can be restored.

If transactions have occurred in a database since the last backup, and no bulk insert operations have occurred, you can recover those pending transactions as long as the media containing the transaction log is still available. The tail of the transaction log can be backed up and applied during a restore operation. 

Simple Recovery

The simple recovery model is the easiest to administer, but it is the option that has the greatest possibility for data loss. In this mode, your transactions log is truncated automatically based on a checkpoint in the database. These checkpoints happen often, and they cause the data in the transaction log to be truncated frequently.

Note

Prior to SQL Server 2000, the trunc. log on checkpoint database option was used to truncate the log on a checkpoint and produce the same type of behavior as simple recovery. This database option and the equivalent backup options NO_LOG and TRUNCATE_ONLY are no longer supported. The only supported method for truncating the transaction log in SQL Server 2008 is to switch the database to use the simple recovery model.


The most important point to remember about the simple recovery model is that with it, you cannot back up the transaction log that captures changes to your database. If a media failure occurs, you are not able to recover the database activity that has occurred since the last database backup. This is a major exposure, so simple recovery is not recommended for production databases. However, it can be a good option for development databases where the loss of some transactions is acceptable. In these types of environments, simple recovery can equate to saved disk space because the transaction log is constantly truncated. The administration in these environments is reduced as well because the transaction log backups are not an option and thus do not need to be managed.

 
Others
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us