Databases & Storage · Paper 02 / 05

ARIES: A Transaction Recovery Method Supporting Fine-Granularity Locking and Partial Rollbacks Using Write-Ahead Logging

C. Mohan, Don Haderle, Bruce Lindsay, Hamid Pirahesh, Peter Schwarz

1992 · ACM Transactions on Database Systems · ~13 min read

Read the original paper

ARIES recovers a database after a crash with a write-ahead log, page LSNs and three passes: analysis, redo and undo. Read it to understand commit latency, why redo replays even failed transactions, and how recovery survives crashing again.

A bank’s database is halfway through a transfer when the power goes. It has already debited one account in memory, and the buffer manager, short of space, has written that page to disk. The credit to the other account was never written anywhere. A second transaction, which committed a moment earlier and was told “done”, changed a page that is still only in memory. When the machine restarts, the disk holds a change that must be removed and lacks a change that must be present.

Every serious database faces this on every crash, and in 1992 most vendors had a recovery scheme that handled it with restrictions: locks on whole pages rather than rows, no partial rollback, checkpoints that paused the system, or corner cases that were quietly wrong. ARIES, from C. Mohan and colleagues at IBM, is the method that handled all of it together, and it became the template for DB2, SQL Server and most engines that followed.

By the end of this explainer you should be able to take a short log, a crash point and the state of the pages on disk, and work out by hand what each recovery pass does. We will carry one example the whole way and then change it to see why each rule is there.

Why the fast buffer policies make recovery hard

Two decisions about the buffer pool set the difficulty. The first is whether a page changed by an uncommitted transaction may be written to disk. Allowing it is called steal, because the buffer manager steals the frame from a running transaction. The second is whether commit must wait until every page the transaction changed is on disk. Requiring it is called force. The terms come from Härder and Reuter’s 1983 survey of recovery, and ARIES chooses steal and no-force, the combination that is fastest and hardest to recover.

PolicyWhat it costs at run timeWhat recovery must do
No-steal, forceBig transactions must fit in memory; every commit waits for random page writesNothing: disk only ever holds committed pages, all of them
No-steal, no-forceBig transactions must fit in memoryRedo committed work that did not reach disk
Steal, forceEvery commit waits for random page writesUndo uncommitted work that did reach disk
Steal, no-force (ARIES)Commit waits only for a sequential log write; the buffer pool is free to evict anythingBoth redo and undo

The reason for choosing the hard corner is the commit path. Under force, a transaction that touched twenty pages scattered across the disk cannot commit until twenty random writes finish. Under no-force, it commits once a few log records, written sequentially to the end of one file, are durable. That gap is what makes high transaction rates possible, and steal is what lets a transaction update more data than fits in memory.

The log, the LSN and one number on every page

ARIES rests on write-ahead logging. Every change is described by a log record carrying enough information to redo it and to undo it, and the records are appended to a single sequential log. Two rules govern when things reach disk. A data page may be written only after the log records describing its changes are on disk. A commit is acknowledged only after the log is on disk up to and including the commit record. Nothing else is forced.

memory · buffer poolpage A · dirtypage B · dirtypage C · cleandiskdata pagesthe log · append-onlyLSN 1, 2, 3, 4 …① log record first, sequentially② page later, whenever convenientcommit = the log is on disk up to the commit record; no data page needs to be
The two rules of write-ahead logging. A page may go to disk only after the log records that explain it; a commit is acknowledged only once the log is durable up to the commit record. Data pages are written whenever the buffer manager likes, or not at all.

Each log record gets a log sequence number, an increasing identifier for its position in the log. Each data page stores a pageLSN: the LSN of the latest log record whose change has been applied to that page. That single field is what makes recovery decidable. Given a log record with LSN 20 for page B, recovery reads page B from disk and compares. If the pageLSN is 20 or more, the change is already there. If it is less, the change is missing.

Every update record also carries the LSN of the same transaction’s previous record, so each transaction’s records form a backward chain through the log. At run time the system keeps two small tables in memory: a transaction table with each active transaction and the LSN of its last record, and a dirty page table with each page that has been changed in memory but not written, together with its recLSN, the LSN of the first change that dirtied it. Periodically ARIES writes a checkpoint that copies both tables into the log. These checkpoints are fuzzy: the system keeps running while they are taken, and no pages are forced to disk.

A crash we can follow by hand

Here is our example, which is also the script in the simulation below. Two pages start on disk with A = 10 and B = 20, both with pageLSN 0. Two transactions run:

LSN 10  T1 update A   10 -> 15    prevLSN -
LSN 20  T2 update B   20 -> 25    prevLSN -
LSN 30  T1 commit                  (log forced through 30, client told "ok")
LSN 40  T2 update A   15 -> 17    prevLSN 20

A and B here stand for records. In a real system they could even be two rows on the same page, which matters later. After LSN 40 the buffer manager needs a free frame and evicts page A, whose pageLSN is 40. The write-ahead rule forces the log through LSN 40 first, then page A goes to disk with value 17. Page B, holding 25, is still only in memory. Then the power fails.

On disk we now have A = 17 with pageLSN 40, which includes T2’s uncommitted change, and B = 20 with pageLSN 0, which is missing T2’s change. The log is durable through LSN 40. The correct final state is A = 15, because T1 committed and T2 did not, and B = 20.

Recovery runs three passes over the log.

oldcheckpointcrash →analysisforward: which transactions were live, which pages dirtyredoforward: repeat every logged change the disk lacks, losers includedundo← backward: roll back the losers, logging each step as a CLR
The three passes of restart recovery. Analysis reads forward from the last checkpoint to rebuild the transaction and dirty page tables. Redo reads forward from the oldest change that might be missing. Undo reads backward through the transactions that did not commit.

Analysis reads forward from the last checkpoint, which in our case is the start of the log. It sees T1’s update, T2’s update, T1’s commit, T2’s second update. It ends with a transaction table holding T2 as a loser, with last LSN 40, and T1 as committed. It also rebuilds a dirty page table conservatively: page A with recLSN 10 and page B with recLSN 20. Analysis cannot know that page A was flushed, because the flush was not logged, so it assumes any page changed since the checkpoint might be dirty. Redo will sort that out.

Redo starts at the smallest recLSN in the dirty page table, LSN 10, and walks forward. LSN 10 is for page A; page A on disk has pageLSN 40, which is not less than 10, so the change is already there and redo skips it. LSN 20 is for page B; page B has pageLSN 0, so redo sets B to 25 and its pageLSN to 20. LSN 30 is a commit, nothing to apply. LSN 40 is for page A, pageLSN 40, skip. The database is now exactly as it was at the instant of the crash: A = 17, B = 25. Note that redo just re-applied T2’s change to B, even though T2 is a loser.

Undo takes the losers and walks their chains backward, always picking the largest LSN still to be undone. T2’s last record is LSN 40. Undo sets A back to 15 and writes a compensation log record, a CLR, at LSN 50 that says “A restored to 15” and carries an undoNextLSN of 20, the next record of T2 that still needs undoing. Then it undoes LSN 20, setting B back to 20, and writes CLR 60 with undoNextLSN empty. T2 has nothing left, so undo writes an end record for it. Final state: A = 15, B = 20, as required.

Try itCrash a database and bring it back

Run the script, flush pages to disk whenever you like (or never), then crash. Recovery must end with T1's committed write present and T2's uncommitted writes gone, whatever you did.

write-ahead log durable to LSN 0
lsntxnrecordon disk
empty
pages
pageon diskin buffer
A10 lsn 0clean
B20 lsn 0clean
staterunning

Two rules make everything else possible. Write-ahead: a page may reach disk only after the log records describing it have. Force at commit: the log is flushed before a commit is acknowledged. Pages themselves may be flushed any time, or never.

In the simulation, try different flush choices before you crash. Flush nothing, flush everything, flush only B. The disk state at the crash changes each time, and the decisions in the redo pass change with it, but the end state does not.

Predict first

Change one thing: page A was flushed after LSN 10 but before LSN 40, so on disk A = 15 with pageLSN 10, and the log only reached disk through LSN 30 (T1’s commit force). Page B was never flushed. What does each pass do, and what is the final state?

Show the worked answer

The log on disk ends at LSN 30, so LSN 40 is lost along with the memory. That is safe: by the write-ahead rule, no page carrying LSN 40’s change can be on disk either.

Analysis finds T1 committed and T2 a loser whose last durable record is LSN 20. Redo starts at LSN 10. Page A has pageLSN 10, so LSN 10 is skipped. Page B has pageLSN 0, so LSN 20 is re-applied, B = 25. Undo then reverses LSN 20 with a CLR, B = 20. Final state A = 15, B = 20, the same as before. The redo and undo work differed; the answer did not.

Why repeat history for the losers too

The redo pass looks wasteful. It re-applied T2’s change to B only so that undo could take it away again. Earlier schemes tried to redo only committed transactions and skip the losers, which seems more efficient. The paper calls its own approach repeating history and argues it is what makes everything else work.

The argument comes from fine-grained locking. Suppose A and B are two rows on the same page P, and two transactions are allowed to update different rows of that page concurrently, which is what row-level locking means. The page has one pageLSN. If recovery redid only the winners, it would apply T1’s change to P and skip T2’s, and then P’s pageLSN would no longer describe the page: some records below that LSN would be applied and some not. The test “is pageLSN at least this record’s LSN” would stop being a reliable answer, and the undo pass would be reversing changes that may or may not be present.

Repeating history keeps one invariant intact: after redo, every page reflects every logged change up to its pageLSN, regardless of who made it. Undo then runs on a state that really existed, using the same logic as a normal rollback during operation. That is why ARIES can offer row-level locks and a simple recovery at the same time.

Crashing during recovery, and why undo is logged

Now change the example again. Recovery has written CLR 50, restoring A to 15, and that CLR has reached the log. Before it can process LSN 20, the machine crashes a second time.

On the next restart, analysis sees T2 is still a loser, but its last record is now CLR 50. Redo repeats history again, including CLR 50 if page A on disk does not already reflect it, so A is 15. Undo starts from T2’s last record, CLR 50. A CLR is never undone; instead undo jumps to its undoNextLSN, which is 20. It undoes LSN 20 and finishes. LSN 40 is not touched a second time.

Without the CLR, the second recovery would have to rediscover what the first one had done. For a simple “set the value back to 15” that is harmless, because applying it twice gives the same answer. But ARIES supports logical undo: undoing an insert into a B-tree index may mean deleting the key from whatever page it now lives on, after other transactions have split pages and moved keys around. Logical operations are not safe to repeat blindly. CLRs make the undo work itself part of history, which redo repeats and undo never re-does, so recovery does a bounded amount of work however many times it is interrupted.

The same machinery gives partial rollback almost for free. A transaction that sets a savepoint and later rolls back to it simply runs the undo logic over its own chain back to the savepoint’s LSN, writing CLRs, and then carries on. The paper also introduces nested top actions for structural changes such as a page split in an index. The split should survive even if the transaction that triggered it rolls back, because other transactions may already be using the new page. A nested top action ends with a dummy CLR whose undoNextLSN skips over the split’s records, so a later rollback steps around them.

What the method costs, and what later engines changed

ARIES is not free. Every update writes a log record with enough information to redo and undo it, so the log volume is roughly proportional to the data changed. Commit latency is the latency of making the log durable, which is why databases put the log on the fastest device available and why group commit, flushing many transactions’ commit records in one write, appears in every serious engine. Recovery time depends on how far back the oldest recLSN is and how much work the losers did. A transaction that ran for an hour before the crash can take a long time to undo, during which its locks are held.

Later systems kept the principles and changed the details. MySQL’s InnoDB keeps a redo log and separate undo logs, and the undo logs are themselves protected by redo. PostgreSQL uses write-ahead logging for redo but has no undo pass, because its multi-version storage never overwrites a row in place. An uncommitted row version is simply invisible to everyone once the transaction is marked aborted, and vacuum removes it later. The cost moves from recovery time to storage and background cleanup.

SQL Server, whose recovery follows ARIES, added Accelerated Database Recovery in 2019 to deal with the long-transaction problem. It keeps row versions in a persistent version store so that aborting a transaction becomes a matter of marking it aborted and letting readers skip its versions, rather than undoing every change one log record at a time. That is a move toward the PostgreSQL idea, layered onto an ARIES engine. Research systems built for fast non-volatile memory have gone further and questioned whether a separate log is needed at all, but on disk and SSD the ARIES structure is still the default.

If you are building a store where data is never updated in place, the full method is more than you need. An append-only log of immutable records, as in an LSM-tree or Kafka, only has to redo the log tail into memory on restart. Undo exists because pages are overwritten. Remove overwriting and you remove undo, which is the trade PostgreSQL and every log-structured system on this list make.

How to read the original

The paper is about seventy pages in ACM Transactions on Database Systems, and very few readers get through it in one sitting. Start with the introduction, which states the goals as a list of properties the method must have (fine-grained locking, partial rollback, fuzzy checkpoints, recovery that survives repeated crashes, and so on). Keep that list beside you; much of the rest is the argument that each property holds.

Next read the overview and the sections on data structures and normal processing, which define the log record fields, pageLSN, the transaction and dirty page tables, and how a rollback writes CLRs. Then read restart processing, the three passes, with a hand-written example like ours beside you. Skim media recovery and the material on nested top actions on a first read, and come back to them if you work on index structures. The long comparison with other recovery methods near the end is the best history of the field there is, and it explains why System R’s shadow paging and several other approaches were abandoned. There is no benchmark section. The evaluation is the argument that every listed property holds at once, so look for the places where the authors show a competitor losing one of them.

The next paper, the LSM-tree, starts from the same insight that sequential log writes are cheap and random page writes are expensive, and pushes it much further: what if the data itself were written like a log, so that nothing is ever updated in place?