首页 » ORACLE [C]系列, ORACLE 9i-23c » Oracle logminer笔记(四) 19c 多租户

Oracle logminer笔记(四) 19c 多租户

10多年前测试过10g的logmnr用于从redo或archivelog中分析DDL DML记录, 当做一些误操作无法flashback技术恢复或无备份时,可以尝试用来从redo log中恢复一些操作, 最近测试了一个19c多租户环境中的logmnr,在supplemental_log_data_min是N时也是可以分析DML记录,(记的之前是IOT表记录无,现在不确认),但是session machine信息是空的,简单记录,区别不大。

–环境19c rac 多租户

Note: 注意logmnr需要在ROOT$CDB中进行,记录如何恢复某个PDB中deleted 记录。

比如本地归档配置为log_archive_dest_1

1, 确认时间范围内归档

select thread#,to_char(first_time,'yyyymmdd hh24:mi:ss') ftime,name,SEQUENCE#, DELETED 
FROM v$archived_log where DELETED='NO' and first_time >sysdate-1 and dest_id=1;

2, 生成第一条归档日志

select 'execute dbms_logmnr.add_logfile(LOGFILENAME=>'''||name||''',options=>dbms_logmnr.new);' 
from v$archived_log where DELETED='NO' and first_time >sysdate-1 and dest_id=1  and rownum<=1;

3, 追加归档日志

select 'execute dbms_logmnr.add_logfile(LOGFILENAME=>'''||name||''',options=>dbms_logmnr.addfile);' 
from v$archived_log where DELETED='NO' and first_time >sysdate-1 and dest_id=1;

4, 本机使用在线字典

EXECUTE DBMS_LOGMNR.start_logmnr(options=>dbms_logmnr.dict_from_online_catalog);

5, 过滤表记录

create table logmnr_tmp tablespace users  as 
select * from v$logmnr_contents where SRC_CON_ID=4 AND  table_name like  'tab%';

Note:
logmnr的记录仅对当前会话生效;注意表名大小写,有些表可能是带“号小写; 表名时使用like ,=值后可能有不可见字符;
过滤条件 PDB 使用src_con_id或src_con_name而不是con_id, owner使用seg_owner

6, 分析日志和记录数据

select min(timestamp),max(timestamp),operation,count(*) from logmnr_tmp
 where seg_owner='ANBOB' and table_name like  'tab%'
 group by operation;

7, 创建同结构表 恢复delete on xx pdb

select
	dbms_metadata.get_ddl( object_type, object_name, owner ) 
from dual;

--在CDB中创建

8, 使用logmnr创建记录表中的sql_undo恢复

declare
cnt number:=0;
vsql varchar2(32760);
begin
for c in(select sql_undo from logmnr_tmp where seg_owner='ANBOB' and  operation='DELETE' ) loop
  begin
     vsql:=replace(replace(c.sql_undo,'"ANBOB".',''),';','');
     dbms_output.put_line(vsql);
     execute immediate vsql;
     cnt:=cnt+1;
     
     if mod(cnt,1000)=0 
       then
          commit;
     end if;
  end;
end loop;
 commit;
end;

Note:
因为临时表创建在sys下,这里把owner和sql结尾的;去掉,用游标动态执行SQL.

9, 在pdb中创建到cdb的dblink

--on cdb
create user  c##test identified by test1234 ;
grant dba to c##test ;

-- on pdb
create database link dl_root connect to c##test identified by test1234 using '172.***.**.**:1521/ORACLE_SID';

SQL> select count(*) from sys."tabxx"@dl_root;

  COUNT(*)
----------
   1394871

SQL> create table ANBOB.tabxx_restore as select * from sys."tabxx"@dl_root;

然后权限给业务或熟悉数据的人员,从创建的临时表中去过滤恢复数据,insert回正式表

— over —

打赏

对不起,这篇文章暂时关闭评论。