PDB挖掘归档:
由于CDB环境下,所有PDB的变化都会记录在一个redo中,PDB没有权限切换redo日志以及执行挖掘归档操作,所以想要挖掘出单个PDB中的DML语句,还需要在CDB下进行,那么如何区分出该update语句发生在哪个容器中呢或者如何过滤掉日志中其他PDB发生的DML语句。
测试流程如下: 1.CDB开启附加日志:
SQL> select supplemental_log_data_min from v$database; SUPPLEME -------- NO SQL> alter database add supplemental log data; Database altered.2.查看CDB当前redo信息:
SQL> select group#,sequence#,status from v$log; GROUP# SEQUENCE# STATUS ---------- ---------- ---------------- 1 7 CURRENT 2 5 INACTIVE 3 6 INACTIVE //挖掘7号日志。3.用PDB1,PDB3测试:
//模拟两个容器同时进行update语句,判断最终能否识别该update语句发生在哪个容器。 PDB1: SQL> alter session set container=pdb1; Session altered. SQL> create table test_pdb1(id number,name varchar2(20)); SQL> insert into test_pdb1 values(1,'byh'); 1 row created. SQL> commit; SQL> update test_pdb1 set id=2 where id=1; 1 row updated. SQL> commit; PDB3: SQL> alter session set container=pdb3; Session altered. SQL> create table test_pdb3(id number,name varchar2(20)); SQL> insert into test_pdb3 values(1,'byh'); 1 row created. SQL> commit; SQL> update test_pdb3 set id=2 where id=1; 1 row updated. SQL> commit;4.CDB下再次查看当前redo信息:
SQL> select group#,sequence#,status from v$log; GROUP# SEQUENCE# STATUS ---------- ---------- ---------------- 1 7 CURRENT 2 5 INACTIVE 3 6 INACTIVE //还是7号日志5.CDB下进行日志切换:
SQL> alter system switch logfile; select name from v$archived_log /oracle/app/fast_recovery_area/orcl/ORCL/archivelog/2020_09_03/o1_mf_1_7_ho1rz210_.arc //挖掘7号归档6.根容器执行挖掘队列:
exec dbms_logmnr.add_logfile('/oracle/app/fast_recovery_area/orcl/ORCL/archivelog/2020_09_03/o1_mf_1_7_ho1rz210_.arc'); exec dbms_logmnr.start_logmnr(options=>dbms_logmnr.dict_from_online_catalog);7.获取挖掘结果: 获取归档日志中的update语句:
SQL> select SRC_CON_DBID,con_id,sql_undo from v$logmnr_contents where lower(sql_redo) like 'update%test_pdb%'; SRC_CON_DBID CON_ID SQL_UNDO ------------ ---------- -------------------------------------------------- 0 0 update "SYS"."TEST_PDB1" set "ID" = '1' where "ID" = '2' and ROWID = 'AAAR6OAABAAAHtBAAA'; 0 0 update "SYS"."TEST_PDB3" set "ID" = '1' where "ID" = '2' and ROWID = 'AAAR6YAABAAALFZAAA'; //出现反update结果8.问题:
如何区分出该update语句发生在哪个容器中呢。v$logmnr_contents的con_id字段以及con_dbid字段都显示为0根容器.