How does Oracle manage undo data?
In the world of Oracle Database, Undo Data is the ultimate safety net. It is the "Ctrl+Z" of the database world, ensuring that if you make a mistake—or if the system crashes—the data can always be returned to a consistent state.
While Redo records what you did, Undo records how to reverse it.
Whenever a transaction modifies data, Oracle doesn't just overwrite the old value. It captures the "before image" (the data as it looked before the change) and stores it in a special place called Undo Segments, located within an Undo Tablespace.
If you change a salary from 5000 to 6000, Oracle:
Writes 5000 to the Undo Segment.
Writes 6000 to the Data Block in the Buffer Cache.
Oracle manages undo data to serve three primary functions:
If you realize you made a mistake and type ROLLBACK;, Oracle goes straight to the Undo Segments, finds the "before images" for your session, and puts the old values back into the data blocks.
This is Oracle’s secret weapon. If User A starts a massive report at 9:00 AM, and User B updates the data at 9:05 AM, User A's report must still show the 9:00 AM version of the data.
Oracle uses Undo Data to reconstruct the "old" version of the blocks for User A, ensuring they see a consistent "snapshot" in time without blocking User B from working.
As we discussed in Crash Recovery, when an instance restarts after a crash, SMON uses Undo Data to "Roll Back" any transactions that were in progress but never committed.
Oracle manages undo automatically using AUM (Automatic Undo Management).
Undo Tablespace: A dedicated physical file on disk.
Undo Segments: Internal structures that act like circular buffers.
Undo Extents: The actual chunks of space.
Undo space is recycled. Once a transaction is Committed, that undo data is no longer strictly "needed" for rollback. Oracle marks that space as Unexpired (still needed for read consistency) and eventually Expired (safe to overwrite).
UNDO_RETENTIONHow long should Oracle keep the "old" data after you commit? This is controlled by the UNDO_RETENTION parameter (measured in seconds).
If you set it to 3600 (1 hour), Oracle tries to keep undo data for at least an hour so that long-running reports don't fail with the infamous ORA-01555: snapshot too old error.
Note: If the Undo Tablespace runs out of space, Oracle will overwrite "Unexpired" data unless you have enabled Undo Guarantee.
| Feature | Undo Data | Redo Log |
| Purpose | To Undo a change (Rollback). | To Replay a change (Recovery). |
| Analogy | The "Eraser." | The "Recorder." |
| Used For | Read Consistency, Rollback. | Data Loss Prevention. |
| Storage | Undo Tablespace (Data Files). | Online Redo Log Files. |
If your Undo Tablespace is too small, your users will experience errors during large deletes or updates. You can check the health of your undo management with this view:
SELECT begin_time, end_time, undoblks, transactioncount, maxquerylen
FROM v$undostat
ORDER BY begin_time DESC;
maxquerylen tells you the duration of the longest query. If this is higher than your UNDO_RETENTION, you risk a "Snapshot too old" error!
Because Oracle manages Undo so efficiently, you can use features like Flashback Query to see what a table looked like 15 minutes ago without restoring any backups:
SELECT * FROM employees AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '15' MINUTE);