# Redo log

Part of the transaction log containing transactions completed by COMMIT or ROLLBACK.
Because all relational databases (RDBMS) contains, by definition, a transaction log (most of the time based on the [ARIES algorithm [Algorithms for Recovery and Isolation Exploiting Semantics]]), the log, which is a binary file, is divided into three parts, sequentially:
* The part of completed transactions, called REDO LOG, which can be replayed in order to allow a point-in-time recovery of data (PITR) or to complete a backup being restored.
* The active part of transactions, called UNDO LOG, which contains the current transactions which have not yet been finalized by one of the COMMIT or ROLLBACK commands and permits to cancel all data that have been modified in memory.
* A possible empty part allowing to integrate more easily the future transactions..
In the Oracle RDBMS environment, redo logs comprise files in a proprietary format which log a history of all changes made to the database. Each redo log file consists of redo records. A redo record, also called a redo entry, holds a group of change vectors, each of which describes or represents a change made to a single block in the database.
For example, if a user UPDATEs a salary-value in a table containing employee-related data, the DBMS generates a redo record containing change-vectors that describe changes to the data segment block for the table. And if the user then COMMITs the update, Oracle generates another redo record and assigns the change a "system change number" (SCN).
Whenever something changes in a datafile, Oracle records the change in the redo log. The name redo log indicates its purpose: If the database crashes, the RDBMS can redo (re-process) all changes on datafiles which will take the database data back to the state it was when the last redo record was written. DBAs use the views V$LOG, V$LOGFILE, V$LOG_HISTORY and V$THREAD to find information about the redo log of the database. Each redo log file belongs to exactly one group (of which at least two must exist). Exactly one of these groups is the CURRENT group (can be queried using the column status of v$log). Oracle uses that current group to write the redo log entries. When the group is full, a log switch occurs, making another group the current one. Each log switch causes checkpoint, however, the converse is not true: a checkpoint does not cause a redo log switch. One can also manually cause a redo-log switch using the ALTER SYSTEM SWITCH LOGFILE command.

## Classification

Redo log files occur in two types:
* online redo logs ("ORL" or "redo logs" for short)
* archived redo logs ("archive logs")

## Usage

Before a user receives a "Commit complete" message, the system must first successfully write the new or changed data to a redo log file.
The RDBMS first writes all changes included in the transaction into the log buffer in the System Global Area (SGA). Using memory in this way for the initial capture aims to reduce disk IO. Of course, when a transaction commits, the redo log buffer must be flushed to disk, because otherwise the recovery for that commit could not be guaranteed. The LGWR (Log Writer) process does that flushing.
Having a redo log makes it possible to replay SQL statements. Before an Oracle database changes data in a datafile it writes changes to the redo log. If something happens to one of the datafiles, a recovery procedure can restore a backed-up datafile and then replay the redo written since backup-time; this brings the datafile to the state it had before it became unavailable. Standby databases in an Oracle Data Guard environment use the same technique: one database (the primary database) records all changes and sends them to the standby database(s). Each standby database applies (replays) the arrived redo, resulting in synchronization with the primary database.
If a database crashes, the recovery process has to apply all transactions, both uncommitted as well as committed, to the data-files on disk, using the information in the redo log files. Oracle must re-do all redo-log transactions that have both a BEGIN and a COMMIT entry (roll forward), and it must undo all transactions that have a BEGIN entry but no COMMIT entry (roll back). (Re-doing a transaction in this context simply means applying the information in the redo log files to the database; the system does not re-run the transaction itself.) The system thus re-creates committed transactions by applying the “after image” records in the redo log files to the database, and undoes incomplete transactions by using the "before image" records in the undo tablespace.
Change data capture can read the redo logs.
In Oracle Data Guard configurations, standby redo logs resemble their equivalent online redo logs, but serve to store redo data transmitted from a different database.

## Implications

Given the verbosity of the logging, Oracle Corporation provides methods for archiving redo logs (archive-logs), and this in turn can feed into data-backup scenarios and standby databases.
The existence of a detailed series of individually logged transactions and actions provides the basis of several data-management enhancements such as Oracle Flashback, log-mining and point-in-time recovery. The concept of a database incarnation can influence the use of redo in database recovery.
For database tuning purposes, efficiently coping with redo logs requires plentiful and fast-access disk.