10g Supplemental Log 设置与取消

 

注意正确顺序是先drop 表级的,再drop database 级的 。 如果需要加入,改drop 为 add 就可以了。  

mxb2bcoredbsty$sqlplus / as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on Sat Mar 27 20:46:27 2010

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining Scoring Engine
and Real Application Testing options

SQL> alter database drop supplemental log data;
alter database drop supplemental log data
*
ERROR at line 1:
ORA-32589: unable to drop minimal supplemental logging


SQL> ALTER DATABASE drop SUPPLEMENTAL LOG DATA (PRIMARY KEY, UNIQUE, FOREIGN KEY) COLUMNS;

Database altered.

SQL>  alter database drop supplemental log data;

Database altered.

SQL>

 

 

============================================================

 

具体参考:  

 

 

Supplemental Logging
=====================
P425


v$database 视图可查询的相关信息:

 SUPPLEMENTAL_LOG_DATA_MIN                          VARCHAR2(8)
 SUPPLEMENTAL_LOG_DATA_PK                           VARCHAR2(3)
 SUPPLEMENTAL_LOG_DATA_UI                           VARCHAR2(3)
 SUPPLEMENTAL_LOG_DATA_FK                           VARCHAR2(3)
 SUPPLEMENTAL_LOG_DATA_ALL                          VARCHAR2(3)




Redo log files are generally used for instance recovery and media recovery. The data
needed for such operations is automatically recorded in the redo log files. However,
a redo-based application may require that additional columns be logged in the redo log
files. The process of logging these additional columns is called supplemental logging.


缺省情况下,数据库没有打开对supplemental logging的支持。


The following are examples of situations in which additional columns may be needed:

(1) An application that applies reconstructed SQL statements to a different database
must identify the update statement by a set of columns that uniquely identify the row
(for example, a primary key), not by the ROWID shown in the reconstructed SQL returned
by the V$LOGMNR_CONTENTS view, because the ROWID of one database will be different and
therefore meaningless in another database.


(2) An application may require that the before-image of whole row be logged, not just
the modified columns, so that tracking of row changes is more efficient.


A supplemental log group is the set of additional columns to be logged when supplemental
logging is enabled. There are two types of supplemental log groups that determine when
columns in the log group are logged:


(1) 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 is sometimes referred to as an ALWAYS log group.

(2) Conditional supplemental log groups: The befre-images of all specified columns are logged
only if at least one of the columns in the log group is updated.


Supplemental log groups can be system-generated or user-defined.


In addition to the two types of supplemental logging, there are two levels of supplemental
logging, as described in the following sections:

Database-Level Supplemental Logging
Table-Level Supplemental Logging



Database-Level Supplemental Logging
===================================

There are two types of database-level supplemental logging:
(1) minimal supplemental logging (使用LogMiner的至少要求)
(2) identification key logging

However, enabling database-wide identification key logging can impose overhead on the database
generating the redo log files.


Minimal Supplemental Logging
============================

Minimal supplemental logging logs the minimal amount of information needed for LogMiner to
identify,group, and merge the redo operations associated with DML changes. It ensures that
LogMiner(and any product building on LogMiner technology) has sufficient information to support
chained rows and various storage arrangements, such as cluster tables and index-organized tables.
To enable minimal supplemental logging, execute the following SQL statement:

ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;



添加与删除的测试:

SQL> conn /as sysdba
Connected.
SQL> select supplemental_log_data_min from v$database;

SUPPLEME
--------
NO

SQL> alter database add supplemental log data;

Database altered.

SQL> select supplemental_log_data_min from v$database;

SUPPLEME
--------
YES

SQL> alter database drop supplemental log data;

Database altered.

SQL> select supplemental_log_data_min from v$database;

SUPPLEME
--------
NO

SQL>


警告日志的变化:

Tue Jul 21 17:43:00 2009
alter database add supplemental log data
Tue Jul 21 17:43:00 2009
SUPLOG: Updated supplemental logging attributes at scn = 5005756
SUPLOG:  minimal = ON, primary key = OFF
SUPLOG:  unique = OFF, foreign key = OFF, all column = OFF
Completed: alter database add supplemental log data
Tue Jul 21 17:43:18 2009
alter database drop supplemental log data
Tue Jul 21 17:43:18 2009
SUPLOG: Updated supplemental logging attributes at scn = 5005768
SUPLOG:  minimal = OFF, primary key = OFF
SUPLOG:  unique = OFF, foreign key = OFF, all column = OFF
Completed: alter database drop supplemental log data







Database-Level Identification Key Logging
=========================================

Identification key logging is necessary when redo log files will not be mined at the source
database instance, for example, when the redo log files will be mined at a logical standby
database.

(1) ALL system-generated unconditional supplemental log group

This option specifies that when a row is updated, all columns of that row(except for LOBs,
LONGS, and ADTs) are placed in the redo log file.

To enable all column logging at the database level, execute the following statement:

SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;

(2) PRIMARY KEY system-generated unconditional supplemental log group

This option causes the database to place all columns of a row's primary key in the redo log file
whenever a row containning a primary key is updated(even if no value in the primary key has changed).

If a table does not have a primary key, but has one or more non-null unique index key constrains or
index keys, then one of the unique index keys is chosen for logging as a means of uniquely identifying
the row being updated.

If the table has neither a primary key nor non-null unique index key, then all columns except LONG
and LOB are supplementally logged; this is equivalent to specifying ALL supplemental logging for that
row.

注意:
Therefore, Oracle recommends that when you use database-level primary key supplemental logging, all
or most tables be defined to have primary or unique index keys.


To enable primary key logging at the database level, execute the following statement:

SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;


(3) UNIQUE system-generated conditional supplemental log group

This option causes the database to place all columns of a row's composite unique key or bitmap index
in the redo log file if any column belonging to the composite unique key or bitmap index is modified.

SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (UNIQUE) COLUMNS;


(4) FOREIGN KEY  system-generated conditional supplemental log group

This option causes the database to place all columns of row's foreign key in the redo log
file if any column belonging to the foreign key is modified.

SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (FOREIGN KEY) COLUMNS;


当使用键值表示记录时需要谨记以下几条:
(1) If the database is open when you enable identification key logging, all DML cursors in the
cursor cache are invalidated. This can affect performance until the cursor cache is repopulated.

(2) When you enable identification key logging at the database level, minimal supplemental logging
is enabled implicitly.

(3) Supplemenatl logging statements are cumlative. If you issue the following SQL statements,
both primary key and unique key supplemenatl logging is enabled:

ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (UNIQUE) COLUMNS;




Disabling Database-Level Supplemental Logging
==============================================


开启与关闭的顺序
===============


错误的操作过程:
SQL> alter database add supplemental log data (primary key) columns;
SQL> alter database add supplemental log data (unique) columns;

SQL> alter database drop supplemental log data (primary key) columns;
SQL> alter database drop supplemental log data;
alter database drop supplemental log data
*
ERROR at line 1:
ORA-32589: unable to drop minimal supplemental logging


SQL>



正确的操作过程:
To disable all database supplemental logging, you must first disable any identification key logging
that has been enabled, then disable minimal supplemenatl logging. The following example shows the
correct order:

SQL> alter database add supplemental log data (primary key) columns;
SQL> alter database add supplemental log data (unique) columns;

SQL> alter database drop supplemental log data (primary key) columns;
SQL> alter database drop supplemental log data (unique) columns;
SQL> alter database drop supplemental log data;




详细过程:


SQL> SELECT SUPPLEMENTAL_LOG_DATA_MIN FROM V$DATABASE;

SUPPLEME
--------
NO

SQL> alter database add supplemental log data (primary key) columns;

Database altered.

SQL> SELECT SUPPLEMENTAL_LOG_DATA_MIN FROM V$DATABASE;

SUPPLEME
--------
IMPLICIT

SQL> alter database add supplemental log data (unique) columns;

Database altered.



SQL> alter database drop supplemental log data (primary key) columns;

Database altered.

SQL> alter database drop supplemental log data (unique) columns;

Database altered.

SQL> SELECT SUPPLEMENTAL_LOG_DATA_MIN FROM V$DATABASE;

SUPPLEME
--------
NO

SQL> alter database drop supplemental log data;

Database altered.

SQL> alter database drop supplemental log data;

Database altered.

SQL> SELECT SUPPLEMENTAL_LOG_DATA_MIN FROM V$DATABASE;

SUPPLEME
--------
NO


注意:

(1) 每次添加与删除都会在警告日志中留下信息已被参考

Tue Jul 21 15:36:15 2009
alter database add supplemental log data (unique) columns
Tue Jul 21 15:36:15 2009
SUPLOG: Updated supplemental logging attributes at scn = 5000969
SUPLOG:  minimal = ON, primary key = ON
SUPLOG:  unique = ON, foreign key = OFF, all column = OFF
Completed: alter database add supplemental log data (unique) columns

(2) 可以多次执行 alter database drop supplemental log data;



Table-Level Supplemental Logging
================================

Table-level supplemental logging specifies, at the table level, which columns are to be
supplementally logged.

(1) Table-Level Identification Key Logging

Identification key logging at the table level offers the same options as those provided at
the database level:all, primary key, foreign key, and unique key. However, when you specify
identification key logging at the table level, only the spcified table is affected.


only when a column in the emp table is changed will the entire row (except for LOB, LONGs,
and ADTs) of the table be placed in the redo log file.


SQL> alter table yzhq.emp add supplemental log data (all) columns;


Keep the following in mind when you use table-level identification key logging:

 1) If the database is open when you enable identfication key logging on a table, all
DML cursors for that table in the cursor cache are invalidated. This can affect performance
until the cursor cache is repopulated.

 2) Supplemental logging statements are cumulative. If you issue the following SQL statements,
both primary key and unique index key table-level supplemental logging is enabled:

ALTER TABLE YZHQ.EMP ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;
ALTER TABLE YZHQ.EMP ADD SUPPLEMENTAL LOG DATA (UNIQUE)  COLUMNS;


(2) Table-Level User-Defined Suplemental Log Groups


  1) User-defined unconditional log groups

     To enable supplemental logging that uses user-defined unconditional log groups, use the
     ALWAYS clause as shown in the following example:

    ALTER TABLE HR.EMPLOYEES
    ADD SUPPLEMENTAL LOG GROUP emp_parttime (EMPLOYEE_ID, LAST_NAME,
    DEPARTMENT_ID) ALWAYS;

     This creates a log group named emp_parttime on the hr.employees table that
     consists of the columns employee_id, last_name, and department_id. These
     columns will be logged every time an UPDATE statement is executed on the
     hr.employees table, regardless of whether or not the update affected these
     columns.


   2) User-defined conditional supplemental log groups


    ALTER TABLE HR.EMPLOYEES
    ADD SUPPLEMENTAL LOG GROUP emp_fulltime (EMPLOYEE_ID, LAST_NAME,
    DEPARTMENT_ID);

     This creates a log group named emp_fulltime on table hr.employees. Just like
     the previous example, it consists of the columns employee_id, last_name, and
     department_id. But because the ALWAYS clause was omitted, before-images of
     the columns will be logged only if at least one of the columns is updated.


   3) NO LOG

     For both unconditional and conditional user-defined supplemental log groups, you
     can explicitly specify that a column in the log group be excluded from supplemental
     logging by specifying the NO LOG option. When you specify a log group and use the NO
     LOG option, you must specify at least one column in the log group without the NO LOG
     option, as shown in the following example:

    ALTER TABLE HR.EMPLOYEES
    ADD SUPPLEMENTAL LOG GROUP emp_parttime(
    DEPARTMENT_ID NO LOG, EMPLOYEE_ID);

     This enables you to associate this column with other columns in the named
     supplemental log group such that any modification to the NO LOG column causes the
     other columns in the supplemental log group to be placed in the redo log file. This
     might be useful, for example, if you want to log certain columns in a group if a LONG
     column changes. You cannot supplementally log the LONG column itself; however, you
     can use changes to that column to trigger supplemental logging of other columns in
     the same row.


Usage Notes for User-Defined Supplemental Log Groups

Keep the following in mind when you specify user-defined supplemental log groups:
■ A column can belong to more than one supplemental log group. However, the
before-image of the columns gets logged only once.
■ If you specify the same columns to be logged both conditionally and
unconditionally, the columns are logged unconditionally.


 

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

转载于:http://blog.itpub.net/35489/viewspace-630561/

<think>好的,我现在需要解决用户的问题:如何在数据库中启用SUPPLEMENTAL_LOG_DATA_ALL功能。首先,我要回忆一下关于Oracle数据库的补充日志(Supplemental Logging)的相关知识。 用户提到的是SUPPLEMENTAL_LOG_DATA_ALL,这个应该是补充日志的一种,用于记录所有字段的信息,而不仅仅是主键。根据引用[3],数据库级的补充日志需要先启用最小补充日志,然后才能启用其他类型的,比如主键、唯一键、外键或ALL。SUPPLEMENTAL_LOG_DATA_ALL应该对应的是ALL COLUMNS选项,也就是在日志中记录所有字段的值。 接下来,我需要确认启用步骤是否正确。根据引用[3]中的示例,启用补充日志的命令应该是ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;。但要注意的是,必须先启用最小补充日志,否则可能会失败。因此,步骤应该是:先启用最小补充日志,再启用ALL COLUMNS的补充日志。 然后,检查是否需要重启数据库或者只是修改参数即可生效。通常补充日志的启用是动态的,不需要重启实例,但可能需要确认当前会话或后续操作的影响。此外,用户可能关心启用后的影响,比如对性能的影响。根据引用[2],最小补充日志不会显著增加开销,但启用ALL COLUMNS可能会增加日志量,所以需要考虑存储和性能。 另外,引用[3]提到启用或关闭补充日志会导致所有SQL游标无效,这可能会影响正在运行的查询,需要评估在业务低峰期操作。同时,补充日志的类型可以叠加,所以如果已经启用了其他类型(如主键),再启用ALL也不会冲突,但需要确认是否必要。 最后,用户可能需要验证是否成功启用了该功能。可以通过查询V$DATABASE视图中的SUPPLEMENTAL_LOG_DATA_ALL字段是否为YES来确认。例如执行SELECT supplemental_log_data_all FROM v$database;。 总结步骤: 1. 检查当前补充日志状态。 2. 启用最小补充日志(如果尚未启用)。 3. 启用SUPPLEMENTAL_LOG_DATA_ALL。 4. 验证配置是否生效。 5. 注意事项,如性能影响和游标失效。 确保每一步的命令正确,并引用正确的文档部分。比如引用[3]中的ALTER DATABASE命令,以及引用[2]中关于性能的说明。</think>### 如何启用SUPPLEMENTAL_LOG_DATA_ALL功能 #### 步骤说明 1. **验证当前补充日志状态** 执行以下SQL查询,确认当前数据库的补充日志配置: ```sql SELECT supplemental_log_data_min, supplemental_log_data_all FROM v$database; ``` - `SUPPLEMENTAL_LOG_DATA_MIN`需为"YES"(最小补充日志已启用) - `SUPPLEMENTAL_LOG_DATA_ALL`初始状态可能为"NO" 2. **启用最小补充日志(若未启用)** ```sql ALTER DATABASE ADD SUPPLEMENTAL LOG DATA; ``` 最小补充日志是启用其他补充日志类型(如`ALL`)的前提条件[^3]。 3. **启用SUPPLEMENTAL_LOG_DATA_ALL** ```sql ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS; ``` 此命令会强制所有DML操作记录行的完整数据(包括所有字段值),即使未修改的字段也会记录[^3]。 4. **验证配置生效** 再次执行步骤1的查询,确认`SUPPLEMENTAL_LOG_DATA_ALL`已变为"YES"。 #### 注意事项 1. **性能影响** - `SUPPLEMENTAL_LOG_DATA_ALL`会增加重做日志(Redo Log)的大小,可能对I/O性能产生压力[^2]。 - 建议评估存储容量和业务高峰期,谨慎启用。 2. **SQL游标失效** 启用或关闭补充日志会导致所有SQL游标失效,可能暂时影响正在运行的查询。 3. **应用场景** 该功能通常用于: - 数据复制(如Oracle GoldenGate) - 逻辑备库(Logical Standby) - 需要完整行数据的审计场景 --- 相关问题
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值