Database Architecture   «Prev  Next»

Lesson 8 Redo Logs
Objective Explain how Oracle redo logs enable reliable crash recovery and near real-time recovery.

Why Oracle Uses Redo Logs

Every change you make to database blocks is first recorded as redo. Oracle implements write-ahead logging (WAL): before modified blocks are written to datafiles, the change description (redo) is flushed to the online redo logs. WAL guarantees that, after a crash, Oracle can replay committed work even if dirty buffers never reached the datafiles.

  • Crash recovery: Reapply committed changes that were in memory but not yet on disk.
  • Media/point-in-time recovery: With ARCHIVELOG mode, archived redo plus backups allow you to recover to a specific SCN/time.

Write-Ahead Logging: Step-by-Step

Initial state: employee row shows title = Manager.
1) Initial state: the row currently shows Manager.
Client issues UPDATE to promote employee.
2) A client issues an UPDATE that changes the row.
Oracle reads the data block into the buffer cache.
3) The relevant block is read into the database buffer cache.
Oracle modifies the copy of the block in memory.
4) The in-memory block is modified; the block becomes “dirty.”
Change vector written to the redo log buffer.
5) A change vector describing the modification is placed into the redo log buffer in the SGA.
Before COMMIT: crash would lose the uncommitted change.
6) Before COMMIT, a crash would discard the uncommitted change—this is correct behavior.
Client issues COMMIT.
7) The client issues COMMIT.
LGWR flushes redo for the transaction to the online redo log.
8) LGWR flushes the transaction’s redo to the online redo log (disk).
Commit record is also written.
9) A commit record is also written.
Commit succeeds after redo is durable.
10) Only after redo is durable does Oracle acknowledge a successful commit.
Crash now: redo allows Oracle to reapply the committed change.
11) If a crash occurs now, Oracle replays the committed change from redo.
DBWR later writes the dirty block to the datafile.
12) Later (asynchronously), DBWR writes the dirty block to the datafile.

Why not write blocks immediately?

  1. Throughput: LGWR writes redo sequentially, which is faster and avoids random I/O.
  2. Batching: Dirty buffers are written in batches by DBWR; not per-row.
  3. Minimal redo size: Only the change vectors are logged, not entire blocks.
Oracle’s database buffer cache[1] keeps active blocks in memory to reduce reads and to batch writes efficiently.

Crash Recovery vs. Media Recovery

Redo Log Structure: Groups, Members, Sequences

Online redo logs are organized into groups; each group may have multiple members (multiplexed copies on different disks). Oracle writes to one group at a time. When a group fills, a log switch occurs and the sequence number increments.

Cycling through redo log groups as sequence numbers advance.
Figure: Oracle cycles through redo log groups; sequence numbers reflect usage order.

Tip: Multiplex each group (≥2 members on different devices) to guard against single-file loss.

Handy Queries

Current group, size, members, and status:


SELECT l.group#, l.sequence#, l.bytes/1024/1024 AS size_mb,
       l.members, l.archived, l.status
FROM   v$log l
ORDER  BY l.group#;

SELECT lf.group#, lf.member
FROM   v$logfile lf
ORDER  BY lf.group#, lf.member;

Recent switches (useful for sizing and workload patterns):


SELECT sequence#, first_time, next_time
FROM   v$log_history
ORDER  BY first_time DESC FETCH FIRST 20 ROWS ONLY;

Force a log switch and archive (as needed):


ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM ARCHIVE LOG CURRENT;

Best Practices

Concept Recap

  1. Blocks are modified in memory (buffer cache); redo is generated in the redo buffer.
  2. LGWR sync-flushes redo to disk at COMMIT (plus other triggers).
  3. DBWR writes dirty buffers later; checkpoints bound recovery work.
  4. After a crash, Oracle replays redo for committed transactions to ensure durability.
[1] Database buffer cache: A shared memory area holding recently used blocks to minimize physical reads and allow efficient batched writes.

SEMrush Software 8 SEMrush Banner 8