Oracle Internals Notes
Log Switch Steps
Redo generation is entirely disabled during a log switch.
This is done by setting an SGA variable reflecting the cause and status of the log switch.
Sessions about to allocate space in the log buffer check this variable first
and if a log switch is in progress they wait on the appropriate one of several wait events associated with log switching.
No log buffer space allocation is attempted until after the log switch has completed,
therefore the log buffer space wait event will not be seen during a log switch.
However, if a large number of processes have been waiting for a log switch to complete
then there can be a burst of redo generation thereafter that does result in secondary log buffer space waits.
LGWR performs the following four steps to effect a log switch.
The writes to the log file header blocks during log file open and close operations are log file single write operations.
Header block writes have to be single writes (rather than parallel writes to all the members of the group)
because part of the header information is the file number, and that is different for each member.
It performs a controlfile transaction to select the next log file to be used
and to clear its controlfile entry.
Normally, the log file currently bearing the lowest log sequence number is chosen.
If necessary, the log switch will be delayed at this point
until DBWn has completed the log switch checkpoint following the previous use of this log file,
and until ARCn has archived its contents.
If so, sessions waiting for the log switch
will sleep on the log file switch (checkpoint incomplete) or log file switch (archiving needed) wait events,
instead of the log file switch completion event.
It flushes any remaining redo in the log buffer to disk,
and then writes the SCN of the last redo record in the log file (the high SCN) into the log file header block.
Once these writes have completed, LGWR closes the log file.
It then advances the SCN and performs a second controlfile transaction
to mark the next log file as CURRENT, and to mark the old log file as ACTIVE.
The status of that log file will be changed to INACTIVE once DBWn has completed the log switch checkpoint.
If the database is in ARCHIVELOG mode,
then LGWR also adds the previous log file to the archive linked list through the log file entries section of the controlfile (see V$ARCHIVE)
and if automatic archiving is enabled, it posts the ARCn background process to archive it.
From Oracle 8.1, LGWR can spawn a new ARCn process up to the value of log_archive_max_processes,
if all the existing archive processes are still busy.
Finally, LGWR opens all members of the new log file group and writes the new log sequence number and low SCN into the header block.
It then enables redo generation again.