Overview

Oracle keeps two complementary change records. Redo describes changes so committed work survives a crash (durability, and the stream for archiving and Data Guard). Undo stores the before images, so a transaction can roll back and readers can see a consistent snapshot without being blocked. Together they implement the ACID behaviour in transactions-acid and Oracle’s flavour of MVCC (locking-and-mvcc).

Core concepts

  • Redo log buffer -> LGWR -> online redo log groups (each with one or more members). At COMMIT, LGWR writes the redo to disk and the session waits on log file sync. Data blocks are written lazily by DBWn (oracle-architecture).
  • When a group fills, a log switch occurs; in ARCHIVELOG mode ARCn copies it to the archive destination, creating the archive needed for point-in-time recovery and standby databases.
  • Undo lives in an undo tablespace, managed automatically (UNDO_MANAGEMENT=AUTO). UNDO_RETENTION (900 s by default) is the target time to keep committed undo for read consistency and flashback (oracle-flashback).
  • Read consistency: a query sees data as of its start SCN; if a block changed afterwards, Oracle rebuilds the older version from undo. If the undo needed has been overwritten you get ORA-01555: snapshot too old.
  • Because readers use undo rather than locks, readers never block writers and writers never block readers (oracle-locking-concurrency).
  • Updates generate redo for both the change and the undo record, so they cost more redo than inserts.

Worked example

Measured with v$mystat (redo size) and v$transaction on the test instance (10,000 rows of about 100 bytes):

OperationRedo generatedUndo used
INSERT 10,000 rows1,886 KB (about 190 bytes per row)16 undo blocks, 452 undo records
UPDATE all 10,000 rows (new 100-byte value)5,136 KB (about 525 bytes per row)314 undo blocks, 10,606 undo records

After ROLLBACK, a query for the old value returned all 10,000 rows again: the before-images in undo were applied. Inserts need little undo (only the row identifier to delete); updates must save the old row image.

Pitfalls and production notes

  • Frequent log switches (small redo logs; here 10 MB in the container) cause log file switch (checkpoint incomplete) waits; production logs are sized in hundreds of MB to GB so switches occur every 15-30 minutes.
  • Commit after each row in a loop adds a log file sync wait per row; commit once per batch (oracle-plsql).
  • ORA-01555 is fixed by shorter queries, a larger UNDO_RETENTION/undo tablespace, or less frequent commits in loops that fetch across commits.
  • Redo is the bottleneck of write-heavy systems; put it on low-latency storage and multiplex members.
  • NOLOGGING operations skip redo for direct-path loads but reduce recoverability; take a backup afterwards.

Practice questions

  1. Why does an UPDATE generate more redo than an INSERT of the same size?
  2. What does a session wait on at commit, and what can you do to reduce it?
  3. A report fails with ORA-01555 at night. List three mitigations.

References

  • Oracle Database Concepts, Transactions; Data Concurrency and Consistency; Managing Undo

oracle-flashback · oracle-locking-concurrency · oracle-rman-backup · pg-wal-checkpoints