使用stream实现DML的审计功能
Dear All:
Hi. 当前环境:Window XP + Oracle Database 10g Enterprise Edition Release 10.1.0.2.0
最近遇到一个需求如下:
Schema的表的DML操作记录到日志表。(例如:update t set col1 = col1+5 )。
记录到日志的信息包括: 当前用户名:schema name,DML操作类型:update,DML操作的具体列名:col1 等等。
因为DML操作的列是动态的,所以考虑使用stream的capture来捕获DML的信息。
1、已经配置stream的帐号 strmadmin
2、strmadmin 已正确授权
3、需捕获DML的schema为scott
一、登入strmadmin
1、建立队列
begin
dbms_streams_adm.set_up_queue(
queue_table => 'prod_queue_table',
queue_name => 'prod_queue',
queue_user => 'strmadmin');
end;
2、创建capture进程
begin
dbms_streams_adm.add_schema_rules(
schema_name => 'scott',
streams_type => 'capture',
streams_name => 'capture_prod',
queue_name => 'strmadmin.prod_queue',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => null,
inclusion_rule => true);
end;
3、创建apply进程
begin
dbms_streams_adm.add_schema_rules(
schema_name => 'scott',
streams_type => 'apply',
streams_name => 'apply_prod',
queue_name => 'strmadmin.prod_queue',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => null,
inclusion_rule => true);
end;
4、启动capture进程
begin
dbms_capture_adm.start_capture(capture_name => 'capture_prod');
end;
5、启动apply进程
begin
dbms_apply_adm.start_apply(apply_name => 'apply_prod');
end;
6、设置DML操作的Handler
begin
dbms_apply_adm.set_dml_handler(
object_name => 'scott.dept',
object_type => 'TABLE',
operation_name => 'UPDATE',
error_handler => false,
user_procedure => 'strmadmin.dml_handler',
apply_database_link => null);
end;
问题1:
在步骤6中的 “user_procedure => 'strmadmin.dml_handler' ”。
我已经在strmadmin中建立了一个存储过程dml_handler,用来处理scott的dept的DML操作(UPDATE操作)。
测试中,对scott的dept表,进行UPDATA操作后,发现dml_handler没有被调用。
在dml_handler中使用dbms_output.putline('procedure had been fired!');
发现控制台并未打印出该条信息。
问题2:
在启动apply进程后,查看状态。
SELECT apply_name, apply_captured, status FROM dba_apply;
发现该进程状态为aborted.
请教大家:上面设置capture和apply的过程,是否正确。不甚感激。