Forum Stats

  • 3,727,162 Users
  • 2,245,329 Discussions
  • 7,852,616 Comments

Discussions

In Memory Undo

2»

Answers

  • Aman....
    Aman.... Member Posts: 22,913 Gold Crown
    Permissible, but only when you are ready to come to my classes after forgetting it ;-) .

    Aman....
  • 695836
    695836 Member Posts: 785
    Are you an instructor in india?
  • Jonathan Lewis
    Jonathan Lewis Member Posts: 9,573 Gold Crown
    Indhar,

    I think Craig has described in-memory undo incorrectly.

    Essentially+ the content of the undo blocks and the content of the redo log file are the same whether or not you use in-memory undo (and private redo threads) or traditional redo logging. The main difference is one of timing and ordering; there is also a reduction in redo record+ count with in-memory undo, though the number of redo change vectors+ remains the same.

    With a traditional small transaction the steps are as follows:
    <ul>
    you change a table or index block - this requires you to generate a redo change vector
    at the same time you have to record enough information to rollback the change - this is an undo record
    but an undo record is stored in an undo block, so you generate a redo change vector to describe the change you make to the undo block
    Oracle combines the two change vectors into a single redo record - which is reported in the session statistic as an increment to "redo entries"
    to make the change Oracle uses the redo allocation and redo copy latches to acquire space and copy the record into the redo buffer.
    </ul>

    Say you inserted 10 rows, one at a time, into a table with 4 indexes - this would generate 50 redo records and 50 undo records, and hit the redo latches 50 times. (That's 5 records per row, one for the table row, one each for each of the indexes - times 10).

    With In-memory undo enabled - and since my example is a small enough piece of work:
    <ul>
    As you change the first table row Oracle allocates one private redo buffer (called a redo strand) and one private "undo" buffer from the shared pool.
    The "in memory undo" buffer is actually a buffer for the redo that describes the changes to the undo.
    As you make your changes to the table and indexes, each change vector is written into the private redo buffer
    At the same time, each change vector that describes the corresponding undo record is written into the "in memory undo" buffer.
    The total number of change vectors, and the content of those change vectors is exactly the same as in the traditional change vectors
    When you commit, Oracle concatenates the two buffers into a single large redo record and writes it into the redo buffer
    At the same time all 100 change vectors are applied to the table, index, and undo blocks (and all the other stuff relating to commits also happens).
    Consequently the final number of "db block changes" is the same in either case
    The most significant difference in volume of redo is that the traditional method results in 50 redo record headers (600 bytes) whereas the in-memory undo produces only one redo record header (12 bytes).
    </ul>

    There are lots of little details and variations around the edges - start and end of transaction, for example, and what happens if one of the two buffers fills (because they're only 64KB or 128KB in size) - but the description above covers the most significant differences in the strategy.

    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk

    To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}
    {noformat} (lowercase, curly brackets, no spaces) so that the text appears in 
    fixed format
    .
    
    
    "Science is more than a body of knowledge; it is a way of thinking" 
    Carl Sagan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
  • Aman....
    Aman.... Member Posts: 22,913 Gold Crown
    Thanks so much for the clarification sir.


    Best regards
    Aman....
  • PAB
    PAB Member Posts: 266
    I know I am too late to ask this followup question....I am sorry for that.....

    I am curious to know if private redo buffer (called a redo strand) and one private "undo" buffer in shared pool then how Oracle guarantee no data loss against system crash....

    Let me explain this in brief...

    Suppose at t1, I start instance and perform some update, as a result there will be one private redo and private undo buffer are created in shared pool.
    immediately after this system crash, So nothing yet written to redo log file and nothing in Undo segment too(as yet no undo collapse occurs). In this situation how oracle recover undo data?

    Shared pool is not DBBC, So I am just curious....

    Thanks
  • CKPT
    CKPT Member Posts: 9,955 Silver Crown
    edited December 2010
    Appriciated.. for long live question. but you can raise a new thread. why no

    Oracle will use both by the undo images, rollforward using commited data, rollback using uncommited data..
    both undo & redo will work
  • Aman....
    Aman.... Member Posts: 22,913 Gold Crown
    Suppose at t1, I start instance and perform some update, as a result there will be one private redo and private undo buffer >are created in shared pool.
    immediately after this system crash, So nothing yet written to redo log file and nothing in Undo segment too(as yet no undo >collapse occurs). In this situation how oracle recover undo data?
    Because , just placing the Redo and Undo chunks in the Shared Pool doesn't change the way LGWR works and alters the events when it writes. It would keep on writing every 3 seconds to the redo logs , either you are using IMU or normal functionality. The redo vectors also contain the information of changes done on the Undo blocks( its an update to them as well) and would protect it. Its highly unlikely that Oracle would miss writing the content to the redo log files -its happening all the time and very quickly. So in the case of instance crash , all what is required to recover , si there in the Redo's Change Vectors , including for Undo blocks as well. Using this, all would be recreated in the roll forward process . In a rare case, if you would miss the writing to redo log file, there won't be any possibility of doing the recovery, either you are using IMU or standard redo/undo mechanisms.

    Aman....
  • PAB
    PAB Member Posts: 266
    CKPT wrote:
    Appriciated.. for long live question. but you can raise a new thread. why no
    I am trying to keep similar thing togather....
    Oracle will use both by the undo images, rollforward using commited data, rollback using uncommited data..
    both undo & redo will work
    My question is not about how Oracle perform instance recovery....

    @Aman,

    I am sure that Oracle has some mechanism to guarantee no data loss.
    But as jonathan mention, undo and redo(Which keep redo for changes on undo) are in shared pool. And I don't think Lgwr writes this information from shared pool into redolog file until undo collapse occur.

    My question is how actual mechanism works to ensure protection for IMU before IMU collapse.

    Thanks for showing interest in this.
  • Aman....
    Aman.... Member Posts: 22,913 Gold Crown
    Pab,

    What do you mean by IMU/Undo collapse ?
    My question is how actual mechanism works to ensure protection for IMU before IMU collapse.
    I shall wait with you for Jonathan to reply over it .

    Aman....
  • Jonathan Lewis
    Jonathan Lewis Member Posts: 9,573 Gold Crown
    PAB wrote:

    Suppose at t1, I start instance and perform some update, as a result there will be one private redo and private undo buffer are created in shared pool.
    immediately after this system crash, So nothing yet written to redo log file and nothing in Undo segment too(as yet no undo collapse occurs). In this situation how oracle recover undo data?
    There are two points in my description you need to note:
    a) At the end I said "there are lots of details and variations around the edges"
    b) the bit which shows that the changes are made to the table and index blocks very late in the process.

    If your session commits, it writes the private redo into the public redo thread, which gets written to disc before the commit is acknowledged. So the problems of recovery are no different from what they used to be.

    If your session has NOT committed then (from the perspective of all other users) nothing has really happened (they're only supposed to see the effects of committed transactions) - so it doesn't matter that the private redo and undo have disappeared.

    The complications (or some of them from around the edges) are: how does any other session see that you're changing blocks that they need to change if you don't update the blocks until you've commited the whole transaction; how does Oracle minimise the time it takes to update all the blocks that need to be updated when you commit. (I do have some answers to these questions, but they are neither accurate nor complete - so I'd rather not write them up for public viewing.)

    An important feature of the mechanism, though, is that it only applies to small transactions - the private areas are limited to 64KB or 128KB (depending on bit-count in the CPU) - so when a transaction gets too big, Oracle flushes the starting portion to the redo buffer and carries on using the traditional mechanism.

    Regards
    Jonathan Lewis
  • PAB
    PAB Member Posts: 266
    Thanks Jonathan,

    You mean to say, if on instance recovery Oracle not found undo information which is loss from IMU than it take this as uncommitted changes and just ignore it...
    Am I right?

    Thanks for your feedback...
This discussion has been closed.