From the course: Oracle Database 12c: Administration

Log writer - Oracle Database Tutorial

From the course: Oracle Database 12c: Administration

Start my 1-month free trial

Log writer

- [Narrator] Let's move on to the next background process in our list. This one is called LGWR, which is short for log writer. As the name implies, this is the Oracle background process responsible for writing redo records from the redo log buffering memory and onto a physical disk. Let's take a closer look. The log writer process is responsible for redo log buffer management. It does that by writing the redo log buffer records to a redo log file on disk. The way that the redo log writer works is by writing all of the redo entries that have been accumulated into the log buffering memory since the last time it wrote to disk. The redo log writer can start and coordinate multiple redo log writer helper processes that can concurrently perform some of the work on behalf of the redo log writer. This is done in occasions where the redo log writer can benefit from multiple concurrent operations. These exact scenarios are outside the scope of our course, but don't worry. They are not crucial for your understanding of the Oracle database architecture. Because the redo log buffer is a circular buffer, every time the log writer writes from the redo log buffer and onto the redo log files on disk, the Oracle server processes can write new redo entries over the previous entries in the redo log buffer. But again, only after those redo log records have been successfully written to disk. The log writer process writes fast enough to ensure that space is always available in the buffer for new entries. Now let's talk about what triggers the log writer to actually write to disk. First, well, every time a user session commits, meaning that the user asks the database to save the transaction and make sure the changes performed by that last transaction are safely and securely stored. This will trigger the log writer to write the contents of the redo log buffer from memory to the redo log files on disk. As I mentioned previously, the corresponding changes to rows contained in data blocks in the buffer cache are deferred until it is more efficient to write them. Remember, that's what the database writer process is for. This mechanism of only synchronously writing redo entries to disk is called the Oracle Fast Commit Mechanism. The second trigger which causes the log writers write, and it's a very important one, is when a redo log switch occurs. We haven't talked a lot about the Oracle redo logs after this point, so this is a great opportunity to shed some light on what the redo logs are and how the log writer background process writes to them. The redo log of a database consists of two or more redo log files. That's a hard requirement. The database requires a minimum of two files to guarantee that one is always available for writing while the other one is being archived. What's archiving of a redo log you may ask. Well, that is basically the process of periodically copying the redo log files to a safe and secure location for backup purposes. Because the redo logs contain information about all of the transactions which have been performed in the database, they are instrumental if there is ever a need to recover the database from a backup. Copying the redo logs to a secure location is done automatically by the Oracle instance. There is actually another dedicated background process responsible just for that. It's called the archiver process, and we'll talk about it later in our chapter. Anyway, so back to the redo log writer. So as I mentioned, we need a minimum of two redo log files. We usually have three or more in a real production Oracle database. The log writer writes to the redo log files in a circular fashion. When the current log file is filled with data, the log writer begins writing to the next available redo log file. Once that redo log file is also full, the redo log writer will move forward to the next log file. When the last available redo log file is filled, the log writer process returns to the first log file and writes to it all over again, starting the cycle from the beginning. Another trigger for the redo log writer to write to the redo log files on disk is if the redo log buffer itself is either 1/3 full or contains at least one megabyte of data. But we are not done just yet. Another trigger for the redo log process to write is just before the database writer background process also writes to disk. Remember that guy? The DBW process from our previous video. Note that the log writer writes to the redo log files on disk while the database writer writes to the data files on disk. We will talk about the Oracle database storage and all of the different types of files used by the Oracle database in our next chapter. So, why does the log writer has to write redo entries to the disk before the database writer can write a modified block from memory to disk? That's because all redo records which are associated with changes to a specific database row, which is contained in a block in memory, must be first written to disk before the block itself can be written as well. And our final trigger causing the log writer background process to write from the redo log buffer in memory to the disk is probably the most simple one. Every three seconds. Yep, the log writer will write all of the contents of the redo log buffer from memory to the redo log files on disk every three seconds.

Contents