05.11.2015 Views

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

310<br />

CHAPTER 9 ■ REDO AND UNDO<br />

ops$tkyte@ORA10G> @mystat2<br />

ops$tkyte@ORA10G> set echo off<br />

NAME<br />

V DIFF<br />

---------- ---------- ----------------<br />

redo size 11540676 81,168<br />

This time, there is only 80KB of redo generated.<br />

As you can see, this makes a tremendous difference—5.5MB of redo versus 80KB. The<br />

5.5MB is the actual table data itself; it was written directly to disk, with no redo log generated<br />

for it.<br />

If you test this on a NOARCHIVELOG mode database, you will not see any differences. The<br />

CREATE TABLE will not be logged, with the exception of the data dictionary modifications, in a<br />

NOARCHIVELOG mode database. If you would like to see the difference on a NOARCHIVELOG mode<br />

database, you can replace the DROP TABLE <strong>and</strong> CREATE TABLE with DROP INDEX <strong>and</strong> CREATE INDEX<br />

on table T. These operations are logged by default, regardless of the mode in which the database<br />

is running. This example also points out a valuable tip: test your system in the mode it<br />

will be run in production, as the behavior may be different. Your production system will be<br />

running in ARCHIVELOG mode; if you perform lots of operations that generate redo in this<br />

mode, but not in NOARCHIVELOG mode, you’ll want to discover this during testing, not during<br />

rollout to the users!<br />

Of course, it is now obvious that you will do everything you can with NOLOGGING, right? In<br />

fact, the answer is a resounding no. You must use this mode very carefully, <strong>and</strong> only after discussing<br />

the issues with the person in charge of backup <strong>and</strong> recovery. Let’s say you create this<br />

table <strong>and</strong> it is now part of your application (e.g., you used a CREATE TABLE AS SELECT NOLOGGING<br />

as part of an upgrade script). Your users modify this table over the course of the day. That<br />

night, the disk that the table is on fails. “No problem,” the DBA says. “We are running in<br />

ARCHIVELOG mode, <strong>and</strong> we can perform media recovery.” The problem is, however, that the initially<br />

created table, since it was not logged, is not recoverable from the archived redo log. This<br />

table is unrecoverable <strong>and</strong> this brings out the most important point about NOLOGGING operations:<br />

they must be coordinated with your DBA <strong>and</strong> the system as a whole. If you use them<br />

<strong>and</strong> others are not aware of that fact, you may compromise the ability of your DBA to recover<br />

your database fully after a media failure. They must be used judiciously <strong>and</strong> carefully.<br />

The important things to note about NOLOGGING operations are as follows:<br />

• Some amount of redo will be generated, as a matter of fact. This redo is to protect the<br />

data dictionary. There is no avoiding this at all. It could be of a significantly lesser<br />

amount than before, but there will be some.<br />

• NOLOGGING does not prevent redo from being generated by all subsequent operations.<br />

In the preceding example, I did not create a table that is never logged. Only the single,<br />

individual operation of creating the table was not logged. All subsequent “normal”<br />

operations such as INSERTs, UPDATEs, <strong>and</strong> DELETEs will be logged. Other special operations,<br />

such as a direct path load using SQL*Loader, or a direct path insert using the<br />

INSERT /*+ APPEND */ syntax, will not be logged (unless <strong>and</strong> until you ALTER the table<br />

<strong>and</strong> enable full logging again). In general, however, the operations your application<br />

performs against this table will be logged.

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

Saved successfully!

Ooh no, something went wrong!