05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 9<br />

■ ■ ■<br />

Redo <strong>and</strong> Undo<br />

This chapter describes two of the most important pieces of data in an <strong>Oracle</strong> database: redo<br />

<strong>and</strong> undo. Redo is the information <strong>Oracle</strong> records in online (<strong>and</strong> archived) redo log files in<br />

order to “replay” your transaction in the event of a failure. Undo is the information <strong>Oracle</strong><br />

records in the undo segments in order to reverse, or roll back, your transaction.<br />

In this chapter, we will discuss topics such as how redo <strong>and</strong> undo (rollback) are generated,<br />

<strong>and</strong> how they fit into transactions, recovery, <strong>and</strong> so on. We’ll start off with a high-level<br />

overview of what undo <strong>and</strong> redo are <strong>and</strong> how they work together. We’ll then drill down into<br />

each topic, covering each in more depth <strong>and</strong> discussing what you, the developer, need to<br />

know about them.<br />

The chapter is slanted toward the developer perspective in that we will not cover issues<br />

that a DBA should be exclusively in charge of figuring out <strong>and</strong> tuning. For example, how to<br />

find the optimum setting for RECOVERY_PARALLELISM or the FAST_START_MTTR_TARGET parameters<br />

are not covered. Nevertheless, redo <strong>and</strong> undo are topics that bridge the DBA <strong>and</strong> developer<br />

roles. Both need a good, fundamental underst<strong>and</strong>ing of the purpose of redo <strong>and</strong> undo, how<br />

they work, <strong>and</strong> how to avoid potential issues with regard to their use. Knowledge of redo <strong>and</strong><br />

undo will also help both DBAs <strong>and</strong> developers better underst<strong>and</strong> how the database operates<br />

in general.<br />

In this chapter, I will present the pseudo-code for these mechanisms in <strong>Oracle</strong> <strong>and</strong> a conceptual<br />

explanation of what actually takes place. Every internal detail of what files get updated<br />

with what bytes of data will not be covered. What actually takes place is a little more involved,<br />

but having a good underst<strong>and</strong>ing of the flow of how it works is valuable <strong>and</strong> will help you to<br />

underst<strong>and</strong> the ramifications of your actions.<br />

What Is Redo?<br />

Redo log files are crucial to the <strong>Oracle</strong> database. These are the transaction logs for the database.<br />

<strong>Oracle</strong> maintains two types of redo log files: online <strong>and</strong> archived. They are used for<br />

recovery purposes; their purpose in life is to be used in the event of an instance or media<br />

failure.<br />

If the power goes off on your database machine, causing an instance failure, <strong>Oracle</strong> will<br />

use the online redo logs to restore the system to exactly the point it was at immediately prior<br />

to the power outage. If your disk drive fails (a media failure), <strong>Oracle</strong> will use archived redo<br />

logs as well as online redo logs to recover a backup of the data that was on that drive to the<br />

correct point in time. Additionally, if you “accidentally” truncate a table or remove some<br />

283

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!