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

rekharaghuram
from rekharaghuram More from this publisher
05.11.2015 Views

CHAPTER 9 ■ REDO AND UNDO 311 • After performing NOLOGGING operations in an ARCHIVELOG mode database, you must take a new baseline backup of the affected data files as soon as possible, in order to avoid losing subsequent changes to these objects due to media failure. We wouldn’t actually lose the subsequent changes, as these are in the redo log; we would lose the data to apply the changes to. Setting NOLOGGING on an Index There are two ways to use the NOLOGGING option. You have already seen one method—that of embedding the NOLOGGING keyword in the SQL command. The other method, which involves setting the NOLOGGING attribute on the segment (index or table), allows operations to be performed implicitly in a NOLOGGING mode. For example, I can alter an index or table to be NOLOGGING by default. This means for the index that subsequent rebuilds of this index will not be logged (the index will not generate redo; other indexes and the table itself might, but this index will not): ops$tkyte@ORA10G> create index t_idx on t(object_name); Index created. ops$tkyte@ORA10G> @mystat "redo size" ops$tkyte@ORA10G> set echo off NAME VALUE ---------- ---------- redo size 13567908 ops$tkyte@ORA10G> alter index t_idx rebuild; Index altered. ops$tkyte@ORA10G> @mystat2 ops$tkyte@ORA10G> set echo off NAME V DIFF ---------- ---------- ---------------- redo size 15603436 2,035,528 When the index is in LOGGING mode (the default), a rebuild of it generated 2MB of redo log. However, we can alter the index: ops$tkyte@ORA10G> alter index t_idx nologging; Index altered. ops$tkyte@ORA10G> @mystat "redo size" ops$tkyte@ORA10G> set echo off NAME VALUE ---------- ---------- redo size 15605792

312 CHAPTER 9 ■ REDO AND UNDO ops$tkyte@ORA10G> alter index t_idx rebuild; Index altered. ops$tkyte@ORA10G> @mystat2 ops$tkyte@ORA10G> set echo off NAME V DIFF ---------- ---------- ---------------- redo size 15668084 62,292 and now it generates a mere 61KB of redo. But that index is “unprotected” now, if the data files it was located in failed and had to be restored from a backup, we would lose that index data. Understanding that fact is crucial. The index is not recoverable right now—we need a backup to take place. Alternatively, the DBA could just re-create the index as we can re-create the index directly from the table data as well. NOLOGGING Wrap-Up The operations that may be performed in a NOLOGGING mode are as follows: • Index creations and ALTERs (rebuilds). • Bulk INSERTs into a table using a “direct path insert” such as that available via the /*+ APPEND */ hint or SQL*Loader direct path loads. The table data will not generate redo, but all index modifications will (the indexes on this nonlogged table will generate redo!). • LOB operations (updates to large objects do not have to be logged). • Table creations via CREATE TABLE AS SELECT. • Various ALTER TABLE operations such as MOVE and SPLIT. Used appropriately on an ARCHIVELOG mode database, NOLOGGING can speed up many operations by dramatically reducing the amount of redo log generated. Suppose you have a table you need to move from one tablespace to another. You can schedule this operation to take place immediately before a backup occurs—you would ALTER the table to be NOLOGGING, move it, rebuild the indexes (without logging as well), and then ALTER the table back to logging mode. Now, an operation that might have taken X hours can happen in X/2 hours perhaps (I’m not promising a 50 percent reduction in runtime!). The appropriate use of this feature includes involvement of the DBA, or whoever is responsible for database backup and recovery or any standby databases. If that person is not aware of the use of this feature, and a media failure occurs, you may lose data, or the integrity of the standby database might be compromised. This is something to seriously consider.

312<br />

CHAPTER 9 ■ REDO AND UNDO<br />

ops$tkyte@ORA10G> alter index t_idx rebuild;<br />

Index altered.<br />

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

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

NAME<br />

V DIFF<br />

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

redo size 15668084 62,292<br />

<strong>and</strong> now it generates a mere 61KB of redo. But that index is “unprotected” now, if the data files<br />

it was located in failed <strong>and</strong> had to be restored from a backup, we would lose that index data.<br />

Underst<strong>and</strong>ing that fact is crucial. The index is not recoverable right now—we need a backup<br />

to take place. Alternatively, the DBA could just re-create the index as we can re-create the<br />

index directly from the table data as well.<br />

NOLOGGING Wrap-Up<br />

The operations that may be performed in a NOLOGGING mode are as follows:<br />

• Index creations <strong>and</strong> ALTERs (rebuilds).<br />

• Bulk INSERTs into a table using a “direct path insert” such as that available via the<br />

/*+ APPEND */ hint or SQL*Loader direct path loads. The table data will not generate<br />

redo, but all index modifications will (the indexes on this nonlogged table will<br />

generate redo!).<br />

• LOB operations (updates to large objects do not have to be logged).<br />

• Table creations via CREATE TABLE AS SELECT.<br />

• Various ALTER TABLE operations such as MOVE <strong>and</strong> SPLIT.<br />

Used appropriately on an ARCHIVELOG mode database, NOLOGGING can speed up many<br />

operations by dramatically reducing the amount of redo log generated. Suppose you have a<br />

table you need to move from one tablespace to another. You can schedule this operation to<br />

take place immediately before a backup occurs—you would ALTER the table to be NOLOGGING,<br />

move it, rebuild the indexes (without logging as well), <strong>and</strong> then ALTER the table back to logging<br />

mode. Now, an operation that might have taken X hours can happen in X/2 hours perhaps<br />

(I’m not promising a 50 percent reduction in runtime!). The appropriate use of this feature<br />

includes involvement of the DBA, or whoever is responsible for database backup <strong>and</strong> recovery<br />

or any st<strong>and</strong>by databases. If that person is not aware of the use of this feature, <strong>and</strong> a media<br />

failure occurs, you may lose data, or the integrity of the st<strong>and</strong>by database might be compromised.<br />

This is something to seriously consider.

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

Saved successfully!

Ooh no, something went wrong!