
LOGGING versus NOLOGGING
Despite the importance of the redo entries, Oracle gives users the ability to limit redo generation on tables, partitions, tablespaces, and indexes by setting them in the NOLOGGING
mode. NOLOGGING affects the recoverability of a database and before going into how to limit the redo generation, it is important to clear the misunderstanding that NOLOGGING is the way out of redo generation. The following are some interesting points regarding this topic:
- NOLOGGING is designed to handle bulk inserts of data which can be easily reproduced. (Remember that the
UPDATE
andDELETE
operations will always be logged.) - Regardless of the LOGGING status, writing to the
UNDO
blocks will always cause generation of redo. - LOGGING should not be disabled on a primary database if it has one or more standby databases. For this reason, Oracle introduced the
ALTER DATABASE FORCE LOGGING
command to place the database in theFORCE LOGGING
mode—meaning that theNOLOGGING
attribute will not have any effect on the segments. TheFORCE LOGGING
mode can also be used at the tablespace level using theALTER TABLESPACE <Tablespace_Name> FORCE LOGGING
command. Use of this option results in some performance degradation, but ensures the recoverability of your primary database and the integrity of your standby database. - Any change to the database dictionary will always cause redo generation. This will happen to protect the data dictionary integrity. For example, if Oracle allocates a space above the high water mark (HWM) for a table, and the system fails in the middle of an
INSERT /*+ APPEND */
command, then Oracle will need to rollback the data dictionary change that was made. There will be a redo generated, but it is only to protect the data dictionary, not your newly inserted data (Oracle will undo the space allocation if it fails, and your newly inserted data will also disappear). - Objects should be set back to the
LOGGING
mode when theNOLOGGING
mode is no longer required. NOLOGGING
is unnecessary for direct path inserts if the database is in theNOARCHIVELOG
mode (see the following table).- Operations involving data that cannot be easily reproduced should always use
LOGGING
operations; avoidNOLOGGING
in such cases! If data is loaded usingNOLOGGING
, the data will not be able to be recovered in a situation of media recovery if no backup is made after the load. NOLOGGING
does not apply to normalUPDATE
,DELETE
, andINSERT
operations.NOLOGGING
will work during specific situations only, but subsequent DML operations over the data will always generate redo (we will see a list of the specific commands that will work in theNOLOGGING
mode a little bit later in this chapter).- If the
LOGGING
orNOLOGGING
clause is not specified when creating a table, partition, or index, the default to theLOGGING
attribute will be theLOGGING
attribute of the database, or if not set, the tablespace in which it resides.
Only a few operations cannot make use of the NOLOGGING
mode benefits. They are:
- Table redefinition cannot be done in
NOLOGGING
, in other words, it will need to be in theLOGGING
mode and will always generate redo. - Temp files are always set to the
NOLOGGING
mode, but any non-direct path operation on them such asINSERT
/UPDATE
/DELETE
will generate redo since they do generate undo.
The database mode FORCE LOGGING
(introduced with 9i R2) when set is a persistent attribute for the database (initialization parameter), meaning that the NOLOGGING operations will not have any effect if used. If the database is shut down and restarted, it remains in the same logging mode state (FORCE LOGGING
).
If your database has a physical or logical standby database and is not set in the FORCE LOGGING
mode, then NOLOGGING operations in the primary database will render data blocks in the standby database to become logically corrupt because of the missing redo log entries. If the standby database ever switches to the primary role, errors will occur when trying to access data in objects that were previously written with the NOLOGGING
option. In this case, you will see an error like the following:
ORA-01578: ORACLE data block corrupted (file # 3, block # 2527) ORA-01110: data file 1: '/u1/oracle/dbs/stdby/tbs_nologging_1.dbf' ORA-26040: Data block was loaded using the NOLOGGING option"
This doesn't sound good and I certainly can't imagine a happy DBA when called at 3:00 A.M. if this kind of error message has come up.
You can check if your database is using the FORCE LOGGING
mode with the following command:
SQL> SELECT force_logging FROM v$database; FORCE_LOGGING --------------------------------------- NO
Note
The options UNRECOVERABLE
(introduced in Oracle 7) and NOLOGGING
(introduced in Oracle 8) can be used to avoid the redo log entries being generated for certain operations that can be easily recovered without using the database recovery mechanism. Do remember that the UNRECOVERABLE
option is deprecated and is replaced by the NOLOGGING
option.