This discussion is archived
1 2 3 4 6 Previous Next 83 Replies Latest reply: Jan 7, 2012 1:03 PM by 909589 Go to original post RSS
  • 15. Re: Why not use Redo log for consistent read
    Aman.... Oracle ACE
    Currently Being Moderated
    user628400 wrote:
    this is awesom explanation and now I feel I am getting closer to what I was really looking for.
    Thanks for the kind words.
    So now I understand that undo blocks are stored in redo and not the real values. My only question is that is it possible that if database crashes and while recovering, the undo data is not there tha's needed by redo or archive logs? I am thinking undo segments will have to be real big to help database recover upto the most recent archive/redo log. I am sure I am missing some more points here but it looks like if redo keeps the undo blocks then if DB is recovering from days old archive logs then undo needs to be big enough to hold all that data. I am surely missing something here badly.
    Well, you haven't understood still I guess. Okay, let's take a little deep dive.

    When you do an update to an Oracle data block, whch means you change a salary value from 100 to 200, a change is done over the actual value(here 100). For this change, a Change Vector is generated which is actually an information that tells to oracle that this thing has happened and a code representation of the Update command for this value is generated. This Change Vector gets logged in the redo log buffer. For a transaction, multiple changes are logged into a redo stream which isnothing but the collection of the change vectors of that transaction. So the first thing you need to remember from now is that with the DML, the entire block doesn't get logged into the log buffer. Think about it, how it is possible in anyway since the size of the log buffer, in general is much smaller compared to other memory areas. If we would log a full block inthe log buffer, with few blocks only, it would touch its maximum size. So this is something you need to understand and remember.

    Now if you have understood what I just said, you should understand this as well that the Undo blocks are no different from the data blocks. Both contain segments only but for the Undo blocks, the control is not with you. Only Oracle knows how to go and make changes to them! That's all what is different for them other than data blocks. So if there would be an update happening to the Undo segment to maintain the old image, from the above example 100, it would also be doing the same behavior that the normal table Update statment would do to the EMP table. So again, the same thing would be going to the redo stream. That's what I explained that in the redo, both the entries for the change of your data and the change for the Undo image are maintained and that's what the meaning of both Old and New values in the redo since using it , both can be recovered.

    If all what above said is clear to you, you should have got an answer for your question that the recovery is done using the Redo's change vectors which are applied to the data files( Undo is also stored in a datafile which is a part of a tablespace) . If the Undo required is not available for the recovery of the uncommitted data, that would also be recreated using the Redo only which would recover the Undo as well , regenerating all of its contents! So you do need to care about the Redo/Archive only as the rest is going to be taken care by the Change Vectors stored in them!

    I hope this all makes some sense for you and would help.

    HTH
    Aman....
  • 16. Re: Why not use Redo log for consistent read
    Girish Sharma Guru
    Currently Being Moderated
    Aman,

    That's why i daily use this forum, in hope there will be couple of good question and great replies by Oracle experts. Please do continue to write such a nice posts....!

    Really it is very clear and it helped me to remove doubts. I have copied all the text in my oracle notes and now it has one more clear definations.

    Thank you from my side and from all forum newbies like me.

    Regards
    Girish Sharma
  • 17. Re: Why not use Redo log for consistent read
    Aman.... Oracle ACE
    Currently Being Moderated
    Girish,

    Thanks for the kind words but since you are over here from some time, I hope you do know that I know nothing actually! But I am still glad to hear that you did find my not-so-good explanation a bit useful.

    Regards
    Aman....
  • 18. Re: Why not use Redo log for consistent read
    631403 Newbie
    Currently Being Moderated
    Thanks for your patience.

    This is how I understand and I am sure I probably got the sequence all messesd up. But just so that I clearly understand it:

    1. insert 100 and commit
    2. write to redo log the block address or some pointer to undo segment say address UA which holds the value
    3. update 100 to 200 and commit
    4. Make another entry in undo log say address UB that now holds new value of 200
    5. Write the pointer to this change in redo log which will be UB
    6. Also, write another record in redo log about the transaction that took place in Step 5 i.e change of undo segment itself. (little confused at this point about where the values are stored in this step)

    Based on my understanding above I have more question but I'll ask later after veryfying that I got the steps ok.

    Thanks again
  • 19. Re: Why not use Redo log for consistent read
    Girish Sharma Guru
    Currently Being Moderated
    You are asking the question from Aman and i shall wait with you till Aman's reply comes, but meanwhile you can read below PPTs which are very good and nice presentations for your all questions :

    1.http://www.juliandyke.com/Presentations/RedoInternals.ppt
    2.www.juliandyke.com/Presentations/TransactionInternals.ppt
    3.Re: Commit/Rollback and Redo Log files.... (Do'nt forget to read and copy all the text of this thread which is a jewell in this forum)

    HTH
    Girish Sharma
  • 20. Re: Why not use Redo log for consistent read
    Aman.... Oracle ACE
    Currently Being Moderated
    user628400 wrote:
    Thanks for your patience.

    This is how I understand and I am sure I probably got the sequence all messesd up. But just so that I clearly understand it:

    1. insert 100 and commit
    2. write to redo log the block address or some pointer to undo segment say address UA which holds the value
    3. update 100 to 200 and commit
    4. Make another entry in undo log say address UB that now holds new value of 200
    5. Write the pointer to this change in redo log which will be UB
    6. Also, write another record in redo log about the transaction that took place in Step 5 i.e change of undo segment itself. (little confused at this point about where the values are stored in this step)
    What's the confusion about Undo? As I said before as well, Undo change is also the same change as like normal Data block change so it would also get logged into the redo log buffer just like that.

    Rest all the steps look fine.

    HTH
    Aman....
  • 21. Re: Why not use Redo log for consistent read
    631403 Newbie
    Currently Being Moderated
    Confusion is that when Undo records are also recorded in redo logs. Is it recorded in the same way that the redo log points to the change vector of undo and undo has a copy of value of what it itself changed?

    For eg: If undo changed value of 100 to 200 does it have 3 different entries in undo:

    1. 100 to record old value for the row
    2. 200 to record new value for the row
    3. another entry of 200 in undo to record what was changed in undo segment itself? (This step is specifically the Step 6 where I have confusion).
  • 22. Re: Why not use Redo log for consistent read
    sb92075 Guru
    Currently Being Moderated
    Realize that UNDO is only applicable between the time of DML & COMMIT.
    After COMMIT the UNDO information is no longer needed for recovery.
  • 23. Re: Why not use Redo log for consistent read
    Aman.... Oracle ACE
    Currently Being Moderated
    user628400 wrote:
    Confusion is that when Undo records are also recorded in redo logs. Is it recorded in the same way that the redo log points to the change vector of undo and undo has a copy of value of what it itself changed?
    Well, I guess I have explained this before as well. Anyways, Undo would be having old image and the place where the entry has been put, that place's information would be recorded in the Redo.
    For eg: If undo changed value of 100 to 200 does it have 3 different entries in undo:

    1. 100 to record old value for the row
    2. 200 to record new value for the row
    3. another entry of 200 in undo to record what was changed in undo segment itself? (This step is specifically the Step 6 where I have confusion).
    What is 100, 200 recording the values? You must read what I said before that Undo Segment is just as what a normal Segment is which means that when an entry is made in the Undo Segment, the information logged in the Redo log is same as like normal as a Data Block .

    Your #3 doesn't make any sense as 200 won't represent anything. Its just a value.

    Be more specific in your doubt please! And please re-read the entire set of replies, I am sure you would get somewhere.

    HTH
    Aman....
  • 24. Re: Why not use Redo log for consistent read
    631403 Newbie
    Currently Being Moderated
    Please bare with me. This is what I understand so far:

    1. Redo stores the change vectors and not the actual table value.
    2. Actual table values are stored in undo segment.
    3. Undo segment Stores the old data or the past image.
    4. Redo logs have the pointer to the old data in undo segment using change vector for eg: if row gets changed from 100 to 200 redo will hold pointer to undo block where 100 is stored
    5. Redo log also contains the changed image of undo data block. So for eg: when a change occurs to a data block of undo the same is logged in redo.

    Some questions I have is:
    1. Does undo also store the current image. For eg: If the row was modified from 100 to 200. Then does undo has only 100? Or does it have both 100 and 200? I am assuming undo has both the values if redo has to point to it. But if Undo has both the values then why do we say that undo has the past image. In this case 200 is the current image and 100 is the past image. How does this work?

    2. What if undo is not big enough and we have to recover a datafile for which the data is not in undo. As you mentioned redo doesn't have data. But if undo also doesn't have data then what happens? Even if redo need to rebuild the undo segment how will it do it if undo does't have enough data. I am trying to visualize the flow but it just seems like there will not be enough data to recover a datafile with small undo. From where will redo get the data?

    3. We keep saying redo is very critical and should be multiplexed with multiple group and members. But it looks like undo is equally important because without actual data what can redo do?


    Agaiin, please bare with me. I am trying to understand the basics of it and trying to ask my questions as clearly as possible.
  • 25. Re: Why not use Redo log for consistent read
    Aman.... Oracle ACE
    Currently Being Moderated
    Hmm, well not an issue in bearing with you. But I would request you as well to bear with me and not change my replies. Don't think Iam upset but its going to make things more tougher for you if you would add your version in the definition given. Let's start one more time!
    . Redo stores the change vectors and not the actual table value.
    Correct. Just one thing to remember, redo contains the changed data. Whatever you update, it goes here.
    2. Actual table values are stored in undo segment.
    What does it mean by "actual value" here? As I said many times before as well, Undo stores only old image . So if you have changed 100 to 200, only 100 goes into the Undo and should be as well since form here only, the CR(consistent read) block would be prepared.
    3. Undo segment Stores the old data or the past image.
    Correct.
    4. Redo logs have the pointer to the old data in undo segment using change vector for eg: if row gets changed from 100 to 200 redo will hold pointer to undo block where 100 is stored
    Where did you read this from and where did I say this as well? Redo logs contain the change vectors of both your block as well as teh Undo block's changes. The pointer is kept in your block's transaction header only for the Undo and is called Undo Byte Address which tells oracle that where is your old value kept in Undo. Redo doesn't need to point to Undo. Tell me a good reason why it should be happening in any case?
    5. Redo log also contains the changed image of undo data block. So for eg: when a change occurs to a data block of undo the same is logged in redo.
    Correct.
    . Does undo also store the current image. For eg: If the row was modified from 100 to 200. Then does undo has only 100? Or does it have both 100 and 200? I am assuming undo has both the values if redo has to point to it. But if Undo has both the values then why do we say that undo has the past image. In this case 200 is the current image and 100 is the past image. How does this work?
    Repeat as long as you wont believe,

    Undo contains old and redo contains new.

    I am not sure that from where you have got the point that redo has to point to undo. Why does it need to in anyways? Please don't think just like that but logically. The changes are kept only at Redo. The old value only goes to Undo. The Undo needs to be required to create CR block and is easier to use it as well since Oralce can reach it right away using the UBA. It would be too tough to go to to the redo for the same( if it would be happening but its not) since Redo is read like a Tape drive. It can't pick things from in between but has to start fro teh first scn recorded of the rtansaction and go to the next one. So please, don't make wrong hypothesis , its not correct. Redo contains pointers to the Undo changes and that's needed because for the recovery of Undo also( it still is a data file) , we would need them. And why we do we say that Undo contains past image is because its correct. What you have assumed is wrong completely.
    What if undo is not big enough and we have to recover a datafile for which the data is not in undo. As you mentioned redo doesn't have data. But if undo also doesn't have data then what happens? Even if redo need to rebuild the undo segment how will it do it if undo does't have enough data. I am trying to visualize the flow but it just seems like there will not be enough data to recover a datafile with small undo. From where will redo get the data?
    Redo doesn't need data. The change vector is the representation of the changes that you have done and is sufficient enough to recover your data. If you would lose undo data file, do you think that recovery can't be done? No, it would be still recoverable and from where, from Redo only! If your hypothesis would be correct, we could never recover Undo datafile since its gone!

    As I said before, Undo would keep your data if the tranasction is not over till your life time. And all of its modifications, over its tranactikon table and to its blocks is kept in the redo, so from there all can be recovered. I amnot sure what Undo being big or small has to do with teh recovery? Yes, if its not good enough in size, you won't be able to do your dmls which makes sense since there won't be no place to keep your old image of data. But that's all about it.
    We keep saying redo is very critical and should be multiplexed with multiple group and members. But it looks like undo is equally important because without actual data what can redo do?
    What do you think that happens when recovery is initiated? Does oralce applies Update, Insert, Delete statements like you would do to recover your changes because its the only time I can think that the actual values are needed. But it doesn't work like that. Redo's change vectors are used by oralce to recover it all and they represent changes only what have happened over the datafiles. Undo is not required here. Even if you would miss Undo(its gone) , we can recover it as well from the Redo. So all you need is Redo to be kept safe , rest you can blow it all!

    HTH
    Aman....
  • 26. Re: Why not use Redo log for consistent read
    631403 Newbie
    Currently Being Moderated
    Excellent! When I started this thread I started off with similar understanding that redo has new data and undo has past image but got confused along the way. I think I didn't understand what actually was change vector. I kept thinking that this vector just contains the address of old and new values into undo and that's what confused me. But thanks for taking time and calrifying it in detail and for being patient. Reason I asked my question the way I asked was so that I am not conufsed all the time.

    So going back to my original question it looks like the reason we don't use redo for consistent read is for efficiency, optimization and performance reasons.

    Can I ask you another question? I guess I am asking it anyways :)

    When a select is issued how does it know where in undo segment that block is for CR? Is there a undo header where SCNs are kept that tells oracle to fetch the past image from particular block in Undo?

    Thanks again.

    Edited by: user628400 on Jan 26, 2010 7:59 PM
  • 27. Re: Why not use Redo log for consistent read
    Aman.... Oracle ACE
    Currently Being Moderated
    user628400 wrote:
    Excellent! When I started this thread I started off with similar understanding that redo has new data and undo has past image but got confused along the way. I think I didn't understand what actually was change vector. I kept thinking that this vector just contains the address of old and new values into undo and that's what confused me. But thanks for taking time and calrifying it in detail and for being patient. Reason I asked my question the way I asked was so that I am not conufsed all the time.
    Not a problem. Glad to see that finally you did get it.
    So going back to my original question it looks like the reason we don't use redo for consistent read is for efficiency, optimization and performance reasons.
    Yes.

    >
    When a select is issued how does it know where in undo segment that block is for CR? Is there a undo header where SCNs are kept that tells oracle to fetch the past image from particular block in Undo?
    When a select is started , it starts with a Query SCN which is compared with the Active Transaction SCN set in the block's Transaction Header. If there is an active transaction running on teh block , for which the information is set in theheader, there must be an transaction entry kept in the Transaction Table which is in the Undo Segment only. Comparing the SCNs , its decided that whether to give you a consistent read or a current read. If the Query SCN is more recent than the transaction SCN that means the query can't see what's written in the block and needs a consistent copy to be there. As I mentioned before, UBA(Undo Byte Address) is set in the block's ITL , it can be find out what which undo segment contains your old copy of block, use it to prepare the CR buffer( Buffer type is 3 from X$BH) and ship to you.

    HTH
    Aman....
  • 28. Re: Why not use Redo log for consistent read
    631403 Newbie
    Currently Being Moderated
    Thanks
    If there is an active transaction running on teh block , for which the information is set in theheader
    Which block is this? Is this the block stored in the data file, buffer cache or could be both?
  • 29. Re: Why not use Redo log for consistent read
    Aman.... Oracle ACE
    Currently Being Moderated
    Can you elaborate please?

    Aman....
1 2 3 4 6 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points