9 Replies Latest reply on Apr 14, 2009 7:48 AM by oradba11

    Datablock writes

    oradba11
      when a checkpoint accurs --

      1. Log file switch .
      2. As defined in parameter Log checkpoint interval .
      3. alter system checkpoint .
      CKPT process signals DBWR to write only dirty blocks in to datafile. Before it LGWR writes all sql statements in the redo log files from log buffer.

      So as following events related to each poress trigger them to do their work.

      When do the LGWR writes to the online redo logs?
      . At checkpoint
      • At commit
      • When one-third full
      • When there is 1 MB ofredo
      • Every three seconds
      • Before DBWn writes

      When do the DBWR writes to the data files?
      • Checkpoint occurs
      • Dirty buffers reach threshold
      • There are no free buffers
      • Timeout occurs
      • RAC ping request is made
      • Tablespace OFFLINE
      • Tablespace READ ONLY
      • Table DROP or TRUNCATE
      • Tablespace BEGIN BACKUP

      What are the responsibilities of CKPT?
      • Signaling DBWn at checkpoints

      SMON Process ---
      • Updating datafile headers with checkpoint information
      • Updating control files with checkpoint information

      So my doubt is if database buffer cache got full so DBWR needs to write blocks in to data files.
      but no user issue commit ....can data files have uncommitted data in it and lgwr process also writes sql statements in to redo files so redo files also have uncommitted statements ....?
      when ever dbwr writes block lgwr also writes ....?

      Can some one write whole process of writing data blocks in to files ... ?
        • 1. Re: Datablock writes
          mbobak
          This can be a complex subject to cover completely.

          First off, if by your #1 above, you're saying that there's a logfile switch at every checkpoint, that's simply not true. (It is true that there's a checkpoint at every log file switch, though.)

          In general, I find it's useful to think about some basic facts:
          - changed data will always be written by LGWR to log file before DBWR writes data file.
          - Data files can contain uncommitted changes.

          So, what causes LGWR to write?
          - When log buffer is 1/3 full
          - When log buffer is 1MB full
          - Every three seconds
          - on commit

          When does DBWR write?
          - on checkpoint (Note that there are several different types of checkpoints.)
          - on buffer cache space pressure (no free buffers will cause DBWR to write blocks)
          - probably other events that are escaping my brain right now....


          Hope the above helps answer your questions,

          -Mark
          • 2. Re: Datablock writes
            Aman....
            Well, I believe first line in Mark's reply is the most valid answer. No one except oracle kernel developers know it "all" about the entire process.

            That said, I guess, you need to read a lot about the basic oracle architecture as there are couple of wrong assumptions in your question. For example, LGWR doesn't write at checkpoint, it doesn't need to. So before saying anything, I would really suggest that you read the Concepts guide from cover to cover, this would be very helpful.

            >
            So my doubt is if database buffer cache got full so DBWR needs to write blocks in to data files.
            but no user issue commit ....can data files have uncommitted data in it and lgwr process also writes sql statements in to redo files so redo files also have uncommitted statements ....?
            when ever dbwr writes block lgwr also writes ....?>

            First thing, redo logs contain change vectors. There is no point of putting the old data in the redo logs, if that what you mean by "uncommitted". But if you meant from uncommitted the changed data which has not yet got a commit flag with it, than yes, even before that data goes in to the data file or even in the buffer cache it is marked as "valid" , it is written into the redo log buffer and through that into the redo log fles, a mechanism which is called write ahead logging. Now data files will get the data at what interval that is not "completely" linked to the redo log files. It may happen that even before a log switch would occur, the buffer cache is filled up, which would give DBWR a "panic write" message and it would start flushing the buffer cache. So yes, the data file and redo log fles, both can and does have that data which is changed but not committed.

            About the second line, LGWR writes first not the DBWR due to the reason that I have mentioned, we need to protect the changed vectors.

            HTH
            Aman....
            • 3. Re: Datablock writes
              oradba11
              Hi aman
              thanks from reply

              let take a example

              one user update some rows in a table but still not fire commit..so that updated data or new data can be written in to datafiles ...so right now we have that dirty block in buffer cache only..and update statement in redo buffer and old image of data will be in undo file.
              Now data buffer chache got full and there is a need to free some space in data buffer because one user fired a select statement.

              So dbwr will write changed data (new data) in to datafiles ..?
              I read that lgwr will write in to redo log files before dbwr writes ....so that update statement will also be in redo files..?

              so now redo log files and data files is having uncommited data..(changed but not commited).. am i right ...?

              Now in redo log files and datafiles having uncommitd data(user can rollback it )
              .. so is there any need to remove this data from redo and data files ...? like how oracle will manage this (uncommited data in data files )....?
              • 4. Re: Datablock writes
                Aman....
                oradba11 wrote:
                one user update some rows in a table but still not fire commit..so that updated data or new data can be written in to datafiles ...so right now we have that dirty block in buffer cache only..and update statement in redo buffer and old image of data will be in undo file.
                Now data buffer chache got full and there is a need to free some space in data buffer because one user fired a select statement.

                So dbwr will write changed data (new data) in to datafiles ..?
                I read that lgwr will write in to redo log files before dbwr writes ....so that update statement will also be in redo files..?

                so now redo log files and data files is having uncommited data..(changed but not commited).. am i right ...?

                Now in redo log files and datafiles having uncommitd data(user can rollback it )
                .. so is there any need to remove this data from redo and data files ...? like how oracle will manage this (uncommited data in data files )....?
                Well, as I mentioned in the last reply, do make sure that you read the concepts guide as there are many answers in that book.


                Okay, I guess I am missing something. I guess, I gave the reply already that data files and redo log files would be having the changed yet uncommitted data. Thsi is fairly valid and right to mention. You must not be having any doubt about this. That said, I am not able to understand the last line though, why would we wnt to remove data files and redo logs?

                HTH
                Aman....
                • 5. Re: Datablock writes
                  26741
                  Yes, lgwr and dbwr may be writing "uncomitted" dirty data. However, the writes also include the undo.
                  Should the transaction fail or be rolled back by the user OR should the server/instance fail and Instance Recovery be initiated by the DBA, the uncomitted update will be rolled back on the basis of the writes to undo ! Even if dbwr hadn't yet written the undo to disk, lgwr, protecting both the undo and the table, would hvae done so. Therefore, doing a "replay" of the redo causes the undo to be "recreated" so that the undo can be applied to the transaction as well.
                  • 6. Re: Datablock writes
                    oradba11
                    ok not a problem ..

                    I will go through by book only...

                    ya one thing..

                    " ...Now in redo log files and datafiles having uncommitd data(user can rollback it )
                    .. so is there any need to remove *this data* from redo and data files ...? like how oracle will manage this (uncommited data in data files )....? "

                    i don't want to remove redo and data files ...._this data_ ----means that updated data (uncommitted data) which have been written to datafiles because of leck of space ....

                    thanks

                    take care
                    • 7. Re: Datablock writes
                      Aman....
                      oradba11 wrote:
                      ya one thing..

                      " ...Now in redo log files and datafiles having uncommitd data(user can rollback it )
                      .. so is there any need to remove *this data* from redo and data files ...? like how oracle will manage this (uncommited data in data files )....? "

                      i don't want to remove redo and data files ...._this data_ ----means that updated data (uncommitted data) which have been written to datafiles because of leck of space ....
                      I am sorry, I couldn't understand the last line's meaning.

                      Aman....
                      • 8. Re: Datablock writes
                        mbobak
                        Ok, let's see if this example helps clarify the situation.

                        Suppose you do an update of a very large table, and it floods the buffer cache with lots of dirty buffers.

                        Now, suppose sessions start suffering from 'free buffer waits'. This means those sessions encountering that error will signal DBWR to wake up and get busy writing some of the dirty blocks to disk, making them eligible to be aged out of the buffer. However, DBWR can not and will not write data to the datafiles until it's written to the online redo log file. So, DBWR will signal LGWR to make sure that the changes to the blocks it's about to write are already written to redo. Then, DBWR is free to write the buffers to the datafiles. Note that the data LGWR flushes from the log buffer and writes to the redo logs may contain uncommitted data. So, both redo and undo and datafiles can contain uncommitted data, all the way down to disk.

                        So, what happens?? How can Oracle deal with all this uncommitted data written everywhere? What if there's a crash? Well, ok, first, suppose, in the case of no crash, there's several thousand buffers that were updated by a session, and they're all written off to disk, and 10 minutes later, that session finally commits. What happens? Well, commit will be written to the redo log. So, a "commit marker" goes to redo, and is written to disk. This will mark the transaction committed in the undo segment header. Beyond that, nothing else has to happen immediately. Oracle is very good at deferring work till later. So, the blocks in the datafile still show as uncommitted, and point to the (now committed) transaction that's indicated in the undo segment header. The next time that block is read from disk, Oracle will do "delayed block cleanout" and clean out those left over pointers. It will read the block header, see the pointers to the the transaction, go read the undo block header, find the transaction is committed, and update the datablock accordingly.

                        So, ok, that's all fine and well, and good, but what if the instance crashes with all that uncommitted data in the datafiles? Well, ok, in the event of an instance crash, what happens? Oracle will read the headers of the control file and all the data files, it will use that information to determine the last valid checkpoint for each datafile, and now it knows how far back in the online redo log stream it has to go, and it will start at that point and roll forward, playing back all those transactions (this includes all transactions that committed as well as those that were uncommitted when the instance crashed.) So, now, once it's rolled forward to the current point in time, all the data should be restored to the datafiles, including the data from those uncommitted transactions. But wait, that uncommitted data isn't valid, cause the transactions that were in progress, are now gone, cause they were lost when the instance crashed! So, Oracle will read the undo segment headers, and find all the uncommitted transactions that are remaining from before the crash, and roll them back.

                        So, we roll forward to recover all transactions from the redo, then we rollback using data in undo to clean out uncommitted (lost) transactions. In this way, Oracle guarantees data integrity up to the last committed transaction, in the case of an instance failure.

                        Hope that helps,

                        -Mark
                        • 9. Re: Datablock writes
                          oradba11
                          Thanks a lot mark ....

                          this is what i was asking for... this is great ...

                          enjoy

                          take care