ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Oracle Supplemental logging(zt)

Oracle Supplemental logging(zt)

原创 Linux操作系统 作者:yexichang 时间:2009-05-10 20:11:38 0 删除 编辑
http://space.itpub.net/223555/viewspace-503838

Supplemental Logging具体是做什么用的呢?要回答这个问题,我们就必须先搞明白,为什么我们需要Supplemental Logging!

事实上,目前最有可能用到Supplemental Logging的也只有逻辑standby和streams这两项特性(10g以 后如果希望logminer能够分析出所有操作,建议也要启用Supplemental Logging),我们都知道,这两项特性的数据应用都属于逻辑应用,类似source database执行update语句之类,结果也要反映到target database,如何准确判断出source端修改的列,在target端中应该更新到哪条记录上呢?根据rowid?显然不靠谱啊,都说了是逻辑的, 块的位置完全不一样,rowid已无用武之地~~~你想说,能否通过表中的唯一键?在更新表中记录时,将主键或唯一键做为附加的信息,与被修改的列一起存 入redolog中,对于没有主键唯一键的表,则将表中所有列统统组合做为附加信息存入redolog,这样target端在分析redolog时,就知 道该更新表中的哪些记录了!

哎呀,说到这里我不得不郑重表扬..............oracle,它跟你想到一块去啦,为了彰显其成果,Oracle将这项特性命名为:Supplemental Logging。当然啦,为了这项特性能够工作的更好,oracle深化了你的想法,并将其设计的更加灵活多样。

数据库启 用了Supplemental Logging之后,对于修改操作,oracle就会同时附加一些能够唯一标识修改记录的列到redolog中,对于拥有主键或唯一键的表,这个操作最简 单,只需要附加主键或唯一键即可,这样生成的redo也是最小的,当然这只是一个理想状态,现实情况下某些表可能无法创建主键/唯一键,或者历史原因确无 主键/唯一键,这种情况下oracle会将所有列(提示,非log,long之类大字段类型的列)都做为附加信息记录到redo中,这种情况下redo有 可能增长迅速,并且在target端应用时也会受到一些影响。因此oracle建议最好为每个涉及到复制的表都创建主键或者唯一键。

对于选 择的列和那些用于精确定位的附加列的组合,oracle也对其做了定义叫做supplemental log group。随后oracle又对supplemental log group做了分类,目的是更精确的设置redolog中都记录些什么信息,分如下两类:
a.Unconditional Supplemental Log Groups:无条件记录指定列的前映像,而不管发生修改操作的是不是指定列。因此它还有个外号,叫"老记录日志组"。
b.Conditional Supplemental Log Groups:只有至少一个指定列发生修改操作时被触发,并记录下修改列的前映像。

Supplemental Logging可以在数据库级设置,也可以精确到表级设置,对于数据库级有两种类型:minimal logging和identification key logging,其主要区别就在于写入redolog中的数据详尽程度不同。

以数据库级为例,如何启用Supplemental Logging呢?试试这个命令:
alter database add supplemental log data;
注:这里启用minimal logging,一般做到这一步,logminer就拥有足够的信息分析所有所做过的操作。

Note: In versions 10g and above, prepare_xxx_instantiation procedure implicitly creates supplemenal log groups. Type of supplemental logging that is enabled implicitly using this command can be checked using the sql in the following link to the documentation. However, additional supplemental logging might neeed to be enabled depending on the requirements as mentioned below.

http://download.oracle.com/docs/cd/B19306_01/server.102/b14228/mon_rep.htm#BABGFFDC

SUPPLEMENTAL LOGGING REQUIREMENTS FOR STREAMS REPLICATION

Supplemental logging should always be enabled on the source database. The following types of columns at the APPLY site are candidates for supplemental logging on the source.

1. All columns that are used in Primary keys at the source site for which changes are applied
    on the target  must be unconditionally logged at the table level or at the db level.

2. All columns that are used as substitute columns at the APPLY site must be unconditionally logged .

3. All columns that are used in DML handlers, Error handlers, Rules, Rule based transformations,  virtual dependency definitions, Subset rules must be unconditionally logged.

4. All columns that are used in column list for conflict resolution methods must be conditionally logged,  if more than one column from the source is part of the column list.

5. If Parallelism of APPLY is > 1, then all columns that are part of FOREIGN KEY, UNIQUE KEY constraints that are defined on more than 1 column and BIT MAP indexes that are defined on more than one column at the source must be conditionally logged.

  You can enable table level supplemental logging using the
  following command.
 

alter table  HR.EMPLOYEES
ADD SUPPLEMENTAL LOG GROUP emp_fulltime (EMPLOYEE_ID, LAST_NAME, DEPARTMENT_ID);


Alternately, you can create user-defined log groups using the following command. Omitting the ALWAYS clause creates a conditional log groups.

Alter table HR.EMPLOYEES
add SUPPLEMENTAL LOG data (PRIMARY KEY,UNIQUE,FOREIGN,ALL) columns;

Note: LOB, LONG, and ADT columns cannot be supplementally logged.
These columns will be ignored when an ALL clause if specified in the command.

Alter table HR.EMPLOYEES 
   ADD SUPPLEMENTAL LOG GROUP emp_parttime( 
   DEPARTMENT_ID NO LOG, EMPLOYEE_ID);

如果想禁用Supplemental Logging,drop即可:
alter database drop supplemental log data;

如何查询当前数据库是否启用了Supplemental Logging呢?则可以试试这条语句:
select supplemental_log_data_min,
       supplemental_log_data_pk,
       supplemental_log_data_ui,
       supplemental_log_data_fk,
       supplemental_log_data_all
  from v$database;

注:supp....data_min/pk/ui等等分别表示不同附加列级别。


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/317003/viewspace-594660/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-08-30

  • 博文量
    32
  • 访问量
    35231