Hello! Welcome to the next lesson in our journey through database system internals.
In our last lesson, we designed the essential data structures for a robust logging system. We detailed the anatomy of UPDATE, COMMIT, END, CLR, and CHECKPOINT log records, and established the roles of the Active Transaction Table (ATT) and Dirty Page Table (DPT). These are the fundamental building blocks.
Today, we'll see the architectural blueprint that puts these blocks together. This lesson covers the core logic of the ARIES recovery algorithm. Your goal is to describe the three phases of the ARIES recovery algorithm: Analysis, Redo, and Undo. We will explore what each phase accomplishes, how it processes the log, and how they work in concert to bring a crashed database back to a consistent state, honoring the ACID guarantees.
The ARIES Three-Phase Protocol: An Overview
ARIES (Algorithms for Recovery and Isolation Exploiting Semantics) is celebrated for its correctness and robustness, particularly its ability to recover even if a crash occurs during the recovery process itself. It achieves this through a carefully orchestrated, three-phase protocol that runs after the database system restarts from a crash.
The three phases are:
- Analysis: Scans forward through the log to figure out the state of the system at the moment of the crash.
- Redo: Scans forward to "repeat history," ensuring the database state on disk reflects all changes up to the crash, including those from uncommitted transactions.
- Undo: Scans backward to remove the changes made by any "loser" transactions (those that were active but not committed at the time of the crash).
The diagram below provides a visual map of the recovery process. Think of it as a timeline of the Write-Ahead Log (WAL), where time flows from top to bottom. The recovery process uses this log to navigate through time.

To get a concise, formal definition of each phase, let's turn to the CMU lecture notes.
Lecture #20: Database Crash Recovery - CMU 15-445/645
These notes from CMU's database course provide a crisp, one-sentence summary for each of the three ARIES phases.
Please read the section '5 ARIES Recovery' on page 4. Focus on the numbered list that defines the Analysis, Redo, and Undo phases. Also, review the diagram in Figure 4, which is the same as the one above, to connect the descriptions to the visual timeline.
A Walkthrough of the ARIES Phases
Now that you have a high-level map, let's see the protocol in action. The following video from CMU's Introduction to Database Systems provides a clear, conceptual walkthrough of the three phases, explaining the purpose and direction of each step.
20 - Database Recovery with ARIES (CMU Intro to Database Systems / Fall 2022)
Professor Andy Pavlo walks through the ARIES recovery process, explaining what happens in each of the three phases.
Watch the segment from 51:35 to 58:39. As you watch, focus on answering these questions: What is the main goal of the Analysis phase? From which point in the log does the Redo phase start, and why? Why is it important that the Redo phase reapplies changes from all transactions, even those that will be aborted? In which direction does the Undo phase scan the log, and what does it do?
Dissecting Each Phase
The video gave us a great dynamic overview. Now, let's solidify our understanding by examining the goal and process of each phase more closely, using a technical blog post that you might find useful for review.
Database Recovery Demystified: Understanding ARIES ...
This technical blog post, 'Database Recovery Demystified', provides an excellent summary of the ARIES phases with helpful diagrams.
Please read the sections 'Phase 1: Analysis', 'Phase 2: Redo', and 'Phase 3: Undo'. You don't need to step through the interactive diagrams in detail yet, but focus on the 'Goal' of each phase and the accompanying descriptive text.
Let's recap the key points from the video and the blog post for each phase.
Phase 1: Analysis
- Goal: To determine which transactions had committed, which were in-flight ("losers"), and which pages might have been dirty in the buffer pool at the time of the crash.
- Process:
- Start at the
BEGIN_CHECKPOINTrecord of the last successful checkpoint (found via the Master Record). - Scan forward to the end of the log.
- Use the
CHECKPOINTrecord's ATT and DPT as a starting point. - Update the ATT and DPT based on the log records encountered. For example, add new transactions to the ATT, change their status to
COMMITupon seeing a commit record, and add pages to the DPT upon seeing an update.
- Start at the
- Result: A final version of the Active Transaction Table (ATT) and the Dirty Page Table (DPT) that accurately reflects the state at the moment of the crash.
Phase 2: Redo
- Goal: To "repeat history," ensuring the database on disk is brought to the exact state it was in at the moment of the crash.
- Process:
- Find the smallest
recLSN(Recovery LSN) among all pages in the DPT. This identifies the earliest log record of a change that might not have made it to disk. This is the starting point for the Redo phase. - Scan forward from this starting LSN to the end of the log.
- For each
UPDATEorCLRrecord, check if the change is already reflected on the page on disk (by comparing the page'spageLSNwith the log record'sLSN). - If the change is not on disk, re-apply it (i.e., redo the operation).
- Find the smallest
- Crucial Principle: This phase is simple and robust because it re-applies changes from all transactions—winners and losers alike. This ensures that any effects of aborted transactions that were on disk are correctly restored before we attempt to undo them.
Phase 3: Undo
- Goal: To reverse all changes made by "loser" transactions (those still in the ATT with a non-committed status after the Analysis phase).
- Process:
- Identify the set of loser transactions from the ATT.
- Scan backward from the end of the log.
- For each log record belonging to a loser transaction, write a Compensation Log Record (CLR) to the log, and then apply the undo operation (using the
before-imagefrom the originalUPDATErecord). - The
lastLSNin the ATT and theprevLSNin each log record allow for efficiently traversing only the relevant records for each loser transaction.
- Crucial Principle: By logging the undo operations as CLRs, ARIES ensures that if a crash happens during recovery, the system won't undo the same operation twice. The CLRs will simply be redone in the next recovery attempt.
Test your understanding!
The Redo phase "repeats history," including reapplying updates from transactions that will be aborted later in the Undo phase. This seems wasteful. Why can't the system just skip redoing the work of these "loser" transactions?
Show answer
This is a key insight into why ARIES is so robust. The reason is the STEAL buffer policy. A "loser" transaction might have updated a page in memory, and that dirty page might have been flushed to disk, overwriting an older value from a "winner" transaction.
If we crash and don't redo the loser's update, the page on disk would be in an old state. If we then tried to undo the loser's update (which isn't even there), we might incorrectly restore a much older value, corrupting the database.
By blindly redoing everything, we guarantee the database state is exactly as it was at the moment of the crash. Only from this known, consistent state can we safely begin rolling back the loser transactions. Simplicity leads to robustness.
Conclusion
You have now seen the high-level architecture of ARIES recovery. By orchestrating these three phases—Analysis, Redo, and Undo—the system can reliably restore a consistent database state after any failure, fulfilling its promise of atomicity and durability.
Key Takeaways:
- Analysis: Scans forward from the last checkpoint to identify winner/loser transactions and dirty pages. Its goal is to build a map for the other two phases.
- Redo: Scans forward from the oldest potentially unpersisted change, repeating history to bring the database to its exact state at the time of the crash.
- Undo: Scans backward from the end of the log, reversing the actions of all loser transactions and writing Compensation Log Records (CLRs) to log these reversals.
Preview of the Next Lesson
We have described what the phases do. In the upcoming lessons, we'll focus on how they do it. We will take a sample log file and manually perform the Analysis phase, reconstructing the Active Transaction Table and Dirty Page Table just as the database would. This will turn these abstract concepts into a concrete, step-by-step procedure.