Database Reference
In-Depth Information
Chapter 6
Redo and Undo
This chapter introduces you two of the most important pieces of data in an Oracle database: redo and undo. Redo
is the information Oracle records in online (and archived) redo log files in order to “replay” your transaction in the
event of a failure. Undo is the information Oracle records in the undo segments in order to reverse, or roll back, your
transaction.
In this chapter, we will discuss topics such as how redo and undo (rollback) are generated, and how they fit into
transactions. We'll also discuss the performance implications of COMMIT and ROLLBACK statements. I will present the
pseudo-code for these mechanisms in Oracle and a conceptual explanation of what actually takes place. I will not
cover every internal detail of what files get updated with what bytes of data. What actually takes place is a little more
involved, but having a good understanding of the flow of how it works is valuable and will help you to understand the
ramifications of your actions.
Time and time again, I get questions regarding the exact bits and bytes of redo and undo. People seem to want
to have a very detailed specification of exactly, precisely, what is in there. I never answer those questions. Instead, I focus
on the intent of redo and undo, the concepts behind redo and undo. I focus on the use of redo and undo—not on the bits
and bytes. I myself do not “dump” redo log files or undo segments. I do use the supplied tools, such as LogMiner to read
redo and flashback transaction history to read undo, but that presents the information to me in a human-readable format.
So, we won't be doing internals in this chapter but rather building a strong foundation.
Note
What Is Redo?
Redo log files are crucial to the Oracle database. These are the transaction logs for the database. Oracle maintains two
types of redo log files: online and archived . They are used for recovery purposes; their main purpose in life is to be
used in the event of an instance or media failure.
If the power goes off on your database machine, causing an instance failure, Oracle will use the online redo logs
to restore the system to exactly the committed point it was at immediately prior to the power outage. If your disk drive
fails (a media failure), Oracle will use both archived redo logs and online redo logs to recover a backup of the data that
was on that drive to the correct point in time. Moreover, if you “accidentally” truncate a table or remove some critical
information and commit the operation, you can restore a backup of the affected data and recover it to the point in
time immediately prior to the “accident” using online and archived redo log files.
Archived redo log files are simply copies of old, full online redo log files. As the system fills up log files, the ARCn
process makes a copy of the online redo log file in another location, and optionally puts several other copies into local
and remote locations as well. These archived redo log files are used to perform media recovery when a failure is caused
by a disk drive going bad or some other physical fault. Oracle can take these archived redo log files and apply them to
backups of the data files to catch them up to the rest of the database. They are the transaction history of the database.
 
 
Search WWH ::




Custom Search