Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005
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.
- Page 306 and 307: CHAPTER 8 ■ TRANSACTIONS 261 X --
- Page 308 and 309: CHAPTER 8 ■ TRANSACTIONS 263 “s
- Page 310 and 311: CHAPTER 8 ■ TRANSACTIONS 265 busi
- Page 312 and 313: CHAPTER 8 ■ TRANSACTIONS 267 Many
- Page 314 and 315: CHAPTER 8 ■ TRANSACTIONS 269 ops$
- Page 316 and 317: CHAPTER 8 ■ TRANSACTIONS 271 last
- Page 318 and 319: CHAPTER 8 ■ TRANSACTIONS 273 Dist
- Page 320 and 321: CHAPTER 8 ■ TRANSACTIONS 275 Auto
- Page 322 and 323: CHAPTER 8 ■ TRANSACTIONS 277 3 Au
- Page 324 and 325: CHAPTER 8 ■ TRANSACTIONS 279 5 pr
- Page 326: CHAPTER 8 ■ TRANSACTIONS 281 scot
- Page 329 and 330: 284 CHAPTER 9 ■ REDO AND UNDO cri
- Page 331 and 332: 286 CHAPTER 9 ■ REDO AND UNDO Fir
- Page 333 and 334: 288 CHAPTER 9 ■ REDO AND UNDO The
- Page 335 and 336: 290 CHAPTER 9 ■ REDO AND UNDO We
- Page 337 and 338: 292 CHAPTER 9 ■ REDO AND UNDO Wha
- Page 339 and 340: 294 CHAPTER 9 ■ REDO AND UNDO row
- Page 341 and 342: 296 CHAPTER 9 ■ REDO AND UNDO If
- Page 343 and 344: 298 CHAPTER 9 ■ REDO AND UNDO ops
- Page 345 and 346: 300 CHAPTER 9 ■ REDO AND UNDO Inv
- Page 347 and 348: 302 CHAPTER 9 ■ REDO AND UNDO The
- Page 349 and 350: 304 CHAPTER 9 ■ REDO AND UNDO 41
- Page 351 and 352: 306 CHAPTER 9 ■ REDO AND UNDO ins
- Page 353 and 354: 308 CHAPTER 9 ■ REDO AND UNDO So,
- Page 355: 310 CHAPTER 9 ■ REDO AND UNDO ops
- Page 359 and 360: 314 CHAPTER 9 ■ REDO AND UNDO •
- Page 361 and 362: 316 CHAPTER 9 ■ REDO AND UNDO ...
- Page 363 and 364: 318 CHAPTER 9 ■ REDO AND UNDO •
- Page 365 and 366: 320 CHAPTER 9 ■ REDO AND UNDO bac
- Page 367 and 368: 322 CHAPTER 9 ■ REDO AND UNDO As
- Page 369 and 370: 324 CHAPTER 9 ■ REDO AND UNDO ops
- Page 371 and 372: 326 CHAPTER 9 ■ REDO AND UNDO wil
- Page 373 and 374: 328 CHAPTER 9 ■ REDO AND UNDO Thi
- Page 375 and 376: 330 CHAPTER 9 ■ REDO AND UNDO ops
- Page 377 and 378: 332 CHAPTER 9 ■ REDO AND UNDO Whe
- Page 379 and 380: 334 CHAPTER 9 ■ REDO AND UNDO Tha
- Page 381 and 382: 336 CHAPTER 9 ■ REDO AND UNDO tou
- Page 383 and 384: 338 CHAPTER 10 ■ DATABASE TABLES
- Page 385 and 386: 340 CHAPTER 10 ■ DATABASE TABLES
- Page 387 and 388: 342 CHAPTER 10 ■ DATABASE TABLES
- Page 389 and 390: 344 CHAPTER 10 ■ DATABASE TABLES
- Page 391 and 392: 346 CHAPTER 10 ■ DATABASE TABLES
- Page 393 and 394: 348 CHAPTER 10 ■ DATABASE TABLES
- Page 395 and 396: 350 CHAPTER 10 ■ DATABASE TABLES
- Page 397 and 398: 352 CHAPTER 10 ■ DATABASE TABLES
- Page 399 and 400: 354 CHAPTER 10 ■ DATABASE TABLES
- Page 401 and 402: 356 CHAPTER 10 ■ DATABASE TABLES
- Page 403 and 404: 358 CHAPTER 10 ■ DATABASE TABLES
- Page 405 and 406: 360 CHAPTER 10 ■ DATABASE TABLES
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.