What is Redo?

What is Redo Log?

Redo log consists of two or more preallocated files that store all changes made to the database as they occur. Redo log is the most crucial structure for recovery operations.Every instance of an Oracle Database has an associated redo log to protect the database in case of an instance failure. Redo records can be used to reconstruct all changes made to the database, including the undo segments.

SGA

What is Redo Threads?

With reference to multiple database instances, the redo log for each database instance is also referred to as a redo thread. In typical configurations, only one database instance accesses an Oracle Database, so only one thread is present. In an Oracle RAC environment, however, two or more instances concurrently access a single database and each instance has its own thread of redo. A separate redo thread for each instance avoids contention for a single set of redo log files, thereby eliminating a potential performance bottleneck.

What is inside the Redo log?

Redo log files are filled with Redo records also called as redo entry. These Redo entries are made up of group of change vectors, referring to the changes made to a single block in the database.

For example : If we change a salary value in an employee table, you generate a redo entry containing change vectors that describe changes to the data segment block for the table, the undo segment data block, and the transaction table of the undo segments.

Redo records are buffered in a circular fashion in the redo log buffer of the SGA and are written to one of the redo log files by the Log Writer (LGWR) database background process.

Whenever a transaction is committed, LGWR writes the transaction redo records from the redo log buffer of the SGA to a redo log file, and assigns a system change number (SCN) to identify the redo records for each committed transaction. Only when all redo records associated with a given transaction are safely on disk in the online logs is the user process notified that the transaction has been committed.

LGWR flushes all of the redo log entries in the redo log buffer to a redo log file, even though some redo records may not be committed. If necessary, the database can roll back these changes.

Work of LGWR in Redo log?

Database requires a minimum of two files to guarantee that one is always available for writing while the other is being archived.

LGWR writes to redo log files in a circular fashion. Filled redo log files are available to LGWR for reuse depending on whether archiving is enabled.

  • If archiving is disabled (the database is in NOARCHIVELOG mode), a filled redo log file is available after the changes recorded in it have been written to the datafiles.
  • If archiving is enabled (the database is in ARCHIVELOG mode), a filled redo log file is available after the changes recorded in it have been written to the datafiles and the file has been archived.

What the types of Redo log Files?

Active (Current) Redo Log
Oracle Database uses only one redo log files at a time to store redo records written from the redo log buffer. The redo log file that LGWR is actively writing to is called the current / active redo log file.
Redo log files that are required for instance recovery are called active redo log files.

Inactive redo log
Redo log files that are no longer required for instance recovery are called inactive redo log files.

NOTE : If you have enabled archiving (the database is in ARCHIVELOG mode), then the database cannot reuse or overwrite an active online log file until one of the archiver background processes (ARCn) has archived its contents. If archiving is disabled (the database is in NOARCHIVELOG mode), then when the last redo log file is full, LGWR continues by overwriting the first available active file.

What is log switch?

A log switch is the point at which the database stops writing to one redo log file and begins writing to another. Normally, a log switch occurs when the current redo log file is completely filled and writing must continue to the next redo log file. However, you can configure log switches to occur at regular intervals, regardless of whether the current redo log file is completely filled. You can also force log switches manually by executing the following command:

SQL> alter system switch logfile;

What is log sequence number?

Oracle Database assigns each redo log file a new log sequence number every time a log switch occurs and LGWR begins writing to it. When the database archives redo log files, the archived log retains its log sequence number. A redo log file that is cycled back for use is given the next available log sequence number.

Leave a Reply