IT tutorials
 
Database
 

SQL Server 2008 R2 : Transaction Logging and the Recovery Process (part 2) - The Recovery Process

6/8/2013 7:47:41 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

2. The Recovery Process

When SQL Server is started, it verifies that completed transactions recorded in the log are reflected in the data and that incomplete transactions whose changes are reflected in the data are rolled back out of the database. This is the recovery process. Recovery is an automatic process performed on each database during SQL Server startup. Recovery must be completed before the database is made available for use.

The recovery process guarantees that all completed transactions recorded in the transaction log are reflected in the data and all incomplete transactions reflected in the data are rolled back. During recovery, SQL Server looks for the last checkpoint record in the log. Only the changes that occurred or were still open since the last checkpoint need to be examined to determine the need for any transactions to be redone (that is, rolled forward) or undone (that is, rolled back). After all the changes are rolled forward or rolled back, as necessary, the database is checkpointed, and recovery is complete.

The recovery algorithm has three phases centered around the last checkpoint record in the transaction log, as shown in Figure 4.

Figure 4. The phases of the recovery process.

These phases are as follows:

  1. Analysis phase— SQL Server reads forward from the last checkpoint record in the transaction log. This pass identifies a list of pages (the dirty page table [DPT]) that might have been dirty at the time of the system crash or when SQL Server was shut down, as well as a list of the uncommitted transactions at the time of the crash.

  2. Redo (roll-forward) phase— During this phase, SQL Server rolls forward all the committed transactions recorded in the log since the last checkpoint. This phase returns the database to the state it was in at the time of the crash. The starting point for the redo pass is the LSN of the oldest committed transaction within the DPT, so that only changes not previously checkpointed (only the committed dirty pages) are reapplied.

  3. Undo (rollback) phase— This phase moves backward from the end of the log to the oldest active transaction at the time of the system crash or shutdown. All transactions that were not committed at the time of the crash but had pages written to the database are undone so that none of their changes are actually reflected in the database.

Now let’s examine the transactions in the log in Figure 31.4 and determine how they will be handled during the recovery process:

  • Transaction T1 is started and committed prior to the last checkpoint. No recovery is necessary.

  • Transaction T2 started before the last checkpoint but had not completed at the time of the system crash. The changes written out by the checkpoint process for this transaction have to be rolled back.

  • Transaction T3 started before the last checkpoint was issued and committed after that checkpoint but prior to the system crash. The changes made to the data after the checkpoint need to be rolled forward.

  • Transaction T4 started and committed after the last checkpoint. This entire transaction needs to be rolled forward.

  • Transaction T5 started after the last checkpoint, but no changes to the data were recorded in the log, so no data changes were written to the data. (Remember that changes must be written to the log before they can be written to the data.) No undo action is required for this transaction.

In a nutshell, this type of analysis is pretty much the same analysis the recovery process would do. To identify the number of transactions rolled forward or rolled back during recovery, you can examine the SQL Server error log and look at the recovery startup messages for each database. Following is a sample fragment of the recovery messages you might see in the SQL Server error log:

2009-05-22 10:37:04.440 spid15s      Starting up database 'tempdb'.
2009-05-22 10:37:04.630 spid18s      Starting up database 'msdb'.
2009-05-22 10:37:04.640 spid19s      Starting up database 'sample'.
2009-05-22 10:37:04.660 spid20s      Starting up database 'AdventureWorks'.
2009-05-22 10:37:04.670 spid21s      Starting up database 'bigpubs2008'.
2009-05-22 10:37:05.140 spid20s      1 transactions rolled forward in database
 'AdventureWorks' (6). This is an informational message only. No user action is
 required.
2009-05-22 10:37:05.150 spid19s      1 transactions rolled forward in database
 'sample' (5). This is an informational message only. No user action is required.
2009-05-22 10:37:05.240 spid19s      0 transactions rolled back in database
 'AdventureWorks' (6). This is an informational message only. No user action is
 required.
2009-05-22 10:37:05.260 spid20s      0 transactions rolled back in database
 'sample' (5). This is an informational message only. No user action is required.
2009-05-22 10:37:05.260 spid19s      Recovery is writing a checkpoint in database
 'AdventureWorks' (6). This is an informational message only. No user action is
 required.
2009-05-22 10:37:05.300 spid20s      Recovery is writing a checkpoint in database
 'sample' (5). This is an informational message only. No user action is required.
2009-05-22 10:37:05.340 spid18s      50 transactions rolled forward in database
 'msdb' (4). This is an informational message only. No user action is required.
2009-05-22 10:37:05.350 spid19s      Starting up database 'AdventureWorksDW'.
2009-05-22 10:37:05.460 spid20s      0 transactions rolled back in database 'msdb'
 (4). This is an informational message only. No user action is required.
2009-05-22 10:37:05.470 spid20s      Recovery is writing a checkpoint in database
 'msdb' (4). This is an informational message only. No user action is required.
2009-05-22 10:37:05.480 spid20s      Starting up database 'AdventureWorksLT'.
2009-05-22 10:37:05.520 spid21s      1 transactions rolled forward in database
 'bigpubs2008' (7). This is an informational message only. No user action is
 required.
2009-05-22 10:37:05.610 spid7s       1 transactions rolled back in database
 'bigpubs2008' (7). This is an informational message only. No user action is
 required.
2009-05-22 10:37:05.610 spid7s       Recovery is writing a checkpoint in database
 'bigpubs2008' (7). This is an informational message only. No user action is
 required.
2009-05-22 10:37:05.630 spid19s      1 transactions rolled forward in database
 'AdventureWorksDW' (8). This is an informational message only. No user action is
 required.
2009-05-22 10:37:05.680 spid18s      0 transactions rolled back in database
 'AdventureWorksDW' (8). This is an informational message only. No user action is
 required.
2009-05-22 10:37:05.700 spid18s      Recovery is writing a checkpoint in database
 'AdventureWorksDW' (8). This is an informational message only. No user action is
 required.
2009-05-22 10:37:05.740 spid20s      1 transactions rolled forward in database
 'AdventureWorksLT' (9). This is an informational message only. No user action is
 required.
2009-05-22 10:37:05.760 spid20s      0 transactions rolled back in database
 'AdventureWorksLT' (9). This is an informational message only. No user action is
 required.
2009-05-22 10:37:05.770 spid20s      Recovery is writing a checkpoint in database
 'AdventureWorksLT' (9). This is an informational message only. No user action is
 required.
2009-05-22 10:37:05.770 spid18s      Starting up database 'AdventureWorks2008'.
2009-05-22 10:37:05.780 spid19s      Starting up database 'AdventureWorksDW2008'.
2009-05-22 10:37:05.790 spid21s      Starting up database 'AdventureWorksLT2008'.
2009-05-22 10:37:05.900 spid19s      1 transactions rolled forward in database
 'AdventureWorksDW2008' (11). This is an informational message only. No user action
 is required.
2009-05-22 10:37:05.910 spid21s      1 transactions rolled forward in database
 'AdventureWorksLT2008' (12). This is an informational message only. No user action
 is required.
2009-05-22 10:37:05.940 spid18s      9 transactions rolled forward in database
 'AdventureWorks2008' (10). This is an informational message only. No user action
 is required.
2009-05-22 10:37:05.950 spid7s       0 transactions rolled back in database
 'AdventureWorksDW2008' (11). This is an informational message only. No user action
 is required.
2009-05-22 10:37:05.950 spid19s      0 transactions rolled back in database
 'AdventureWorksLT2008' (12). This is an informational message only. No user action
 is required.
2009-05-22 10:37:05.960 spid7s       Recovery is writing a checkpoint in database
 'AdventureWorksDW2008' (11). This is an informational message only. No user action
 is required.
2009-05-22 10:37:05.970 spid19s      Recovery is writing a checkpoint in database
 'AdventureWorksLT2008' (12). This is an informational message only. No user action
 is required.
2009-05-22 10:37:06.530 spid19s      0 transactions rolled back in database
 'AdventureWorks2008' (10). This is an informational message only. No user action
 is required.
2009-05-22 10:37:06.630 spid19s      Recovery is writing a checkpoint in database
 'AdventureWorks2008' (10). This is an informational message only. No user action
 is required.
2009-05-22 10:37:08.220 spid19s      Recovery completed for database
AdventureWorks2008 (database ID 10) in 1 second(s) (analysis 73 ms, redo 1 ms, undo
 572 ms.) This is an informational message only. No user action is required.
2009-05-22 10:37:08.250 spid7s       Recovery is complete. This is an informational
message only. No user action is required.	  
 
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