databaseoracleloggingundo-redoredo

Oracle:Why Oracle create a redo change vector describing the change to the undo block when user issue an instruction to change an item of data


Generally, when a user issues an instruction to change a data block, Oracle works through 4 critical steps to make the change happen:

  1. Create a redo change vector describing the change to the data block;

  2. Create an undo record for insertion into an undo block in the undo tablespace;

  3. Create a redo change vector describing the change to the undo block;

  4. Change the data block.

Why do we need step 3 to finish the change?


Solution

  • Let's say you have an unfinished(uncommitted) transaction. Oracle has done all things you said in the question.

    Now the machine crashes.

    The DBA, after the recovery of the machine(or on new machine, it depends :)) restores the last backup and applies all redo logs on the new instance. In the redo is also what was done in step 1. But that work is not committed, so the engine needs to roll it back. For this it needs the rollback segment. But rollback segment won't be there if you didn't log it on step 3.

    I know you'll ask now: why it applies logs for uncommitted work? That was my question also when I read about it. I don't know for sure, but maybe it's easier to do so. Maybe is harder to check for every entry of the log that it is part of a committed transaction. However, this is how Oracle works: I applies all the redo logs then rollback uncommitted transactions.