Inside Oracle supplemental logging

来源:互联网 发布:古汉语词典软件离线 编辑:程序博客网 时间:2024/05/19 16:22

Question:  What is supplemental logging, and how does supplemental logging work?

 

Answer:  Database-level supplemental logging must be enabled for any Change Data Capture source database.  You can see if supplemental logging is enabled with these queries:

 

 select
   SUPPLEMENTAL_LOG_DATA_MIN,
   SUPPLEMENTAL_LOG_DATA_PK,
   SUPPLEMENTAL_LOG_DATA_UI
from
   v$database;

Supplemental logging is also a column in dba_tables.

Supplemental logging places additional column data into the redo log file whenever an UPDATE operation is performed. At the least, minimal database-level supplemental logging must be enabled for any Change Data Capture source database:

SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
Database altered.

When Supplemental Logging is enabled, either some selected columns or all columns are specified for extra logging. They are called asupplemental log group and consist of nothing but a set of additional columns that are being logged.

 

When the supplemental logging is active on a database, the redo logs contain other columns from tables to uniquely identify a row. If the table has a primary key or unique index defined, the only columns involved in the primary key or unique index will be registered in the redo logs along with the actual column(s) that has changed.

If the table does not have any primary keys or unique index defined, Oracle will write all scalar columns from the table to identify the row. This may significantly increase the size of redo logs and will impact the log apply services on the logical standby site.
 

There are two types of supplemental log groups that determine when columns in the log group are logged:

  • Unconditional Supplemental Log Groups - The before-images of specified columns are logged any time a row is updated, regardless of whether the update affected any of the specified columns. This can be referred to as an ALWAYS log group.
     

  • Conditional Supplemental Log Groups - The before-images of all specified columns are logged only if at least one of the columns in the log group is updated.

Supplemental Logging can be enabled at database level or at the table level. When it is enabled at database level, there are two types, minimal logging and identification key logging.


Streams supplemental logging places additional column data into the redo log file whenever an UPDATE operation is performed. At the least, minimal database-level supplemental logging must be enabled for any Change Data Capture source database:

ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
 

Why is supplemental logging needed? When a particular column is updated at the source database table for a set of rows, the values in the column or columns are logged by default. When these values are moved to the destination side, to which rows does Oracle apply them, or how does Oracle identify the rows to be updated? Supplemental logging provides the answers to these questions.

 

Reference books on supplemental logging

 

For complete information on Streams and Data Guard supplemental logging, see these resources, with working code examples in the code depot:

 

  • Oracle Data Guard - Bipul Kumar
     

  • Oracle Streams - High speed replication and data sharing - Madhu Tumma