Oracle 10g中的Logmnr的使用是本文我們主要要介紹的內容,我們知道,在Oracle9i中,Logmnr工具是DBA用來找回被剔除數據的好措施,利用Logmnr能夠告終以下的任務:
1、查明數據庫的改變登記,可能是舉行改變分析,如有的用戶猜忌自己的利用有什麼問題,發生了許多的失手,能夠用Logmnr來分析這些事務,看看究竟發生了些什麼事情。
2、查明並修改用戶的誤壟斷,如有的用戶一不當心誤剔除非某個表,然而並不確認,這個時候就能夠利用Logmnr來分析是誰厲行的DML可能是DDL壟斷。
3、找回失落的數據,當不能利用flashback可能利用Flashback受到局限的時候,能夠琢磨利用Logmnr工具來找回數據,這個時候,只必需有歸檔日志即可。
Logmnr工具包括的內容與數據字典
dbms_logmnr_d包:用於提取字典消息到表,包括三個過程:
(1)add_logfile:用來增加/剔除用於分析的日志文件。
(2)start_logmnr:用來開啟日志分析,而且在9i/10g中,能夠開啟許多不同的分析選項。
(3)end_logmnr:用來終止分析會話,它將回收LogMiner所挪借的內存。
萬一等閒用戶想利用以上的包,定然目前sys中授權能力夠利用,如:
sys用戶厲行授權:
SQL> grant execute on dbms_logmnr to scott;
與LogMiner相干的數據字典如下:
u v$logmnr_dictionary:LogMiner可能利用的數據字典消息。
u v$logmnr_parameters:目前LogMiner所設定的參數消息。
u v$logmnr_logs:目前用於分析的日志列表。
u v$logmnr_contents:日志分析收獲。
Logmnr分析過程演示
創立一張表,然後插入一些數據,再剔除這些數據。
連接到:
- Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
- With the Partitioning, OLAP and Data Mining options
- SQL> alter system archive log current;
- 系統已改動。
- SQL> create table mytesttab as select * from scott.dept;
- 表已創立。
- SQL> insert into mytesttab values(80,'IT','WA');
- 已創立 1 行。
- SQL> insert into mytesttab values(90,'MGR','YR');
- 已創立 1 行。
- SQL> commit;
- 提交告終。
- SQL> delete from mytesttab;
- 已剔除6行。
- SQL> commit;
- 提交告終。
- SQL> alter system archive log current;
- 系統已改動。
然後找出壟斷過程登記的日志文件
- D:/oracle/Flash_recovery_area/MYOracle/ARCHIVELOG/2007_08_11目錄下的O1_MF_1_4_3CVHLKJM_.ARC文件,我們必需對這個文件舉行分析處理。
- SQL> exec sys.dbms_logmnr.add_logfile(LogFileName=>'D:/oracle/Flash_recovery_area/MYOracle/ARCHIVELO
- G/2007_08_11/O1_MF_1_4_3CVHLKJM_.ARC',options=>dbms_logmnr.new);
- PL/SQL 過程已獲勝告終。
- SQL> exec sys.dbms_logmnr.start_logmnr(options=>sys.dbms_logmnr.dict_from_online_catalog);
- PL/SQL 過程已獲勝告終。
- OK,分析告終。
察看日志登記的內容
- SQL> select t.scn,t.timestamp,t.seg_owner,t.Operation
- 2 from v$logmnr_contents t where t.seg_name='MYTESTTAB';
- SCN TIMESTAMP SEG_OWNE OperaTION
- ---------- -------------- -------- ----------
- 5483840 11-8月 -07 SYS DDL
- 5483863 11-8月 -07 SYS INSERT
- 5483874 11-8月 -07 SYS INSERT
- 5483885 11-8月 -07 SYS DELETE
- 5483885 11-8月 -07 SYS DELETE
- 5483885 11-8月 -07 SYS DELETE
- 5483885 11-8月 -07 SYS DELETE
- 5483886 11-8月 -07 SYS DELETE
- 5483886 11-8月 -07 SYS DELETE
- 已抉擇9行。
- SQL> select t.SQL_REDO from v$logmnr_contents t where t.seg_name='MYTESTTAB';
- SQL_REDO
- ----------------------------------------------------------------------------------------------------
- create table mytesttab as select * from scott.dept;
- insert into "SYS"."MYTESTTAB"("DEPTNO","DNAME","LOC") values ('80','IT','WA');
- insert into "SYS"."MYTESTTAB"("DEPTNO","DNAME","LOC") values ('90','MGR','YR');
- delete from "SYS"."MYTESTTAB" where "DEPTNO" = '10' and "DNAME" = 'ACCOUNTING' and "LOC" = 'NEW
- YORK
- delete from "SYS"."MYTESTTAB" where "DEPTNO" = '20' and "DNAME" = 'RESEARCH' and "LOC" = 'DALLAS' an
- delete from "SYS"."MYTESTTAB" where "DEPTNO" = '30' and "DNAME" = 'SALES' and "LOC" = 'CHICAGO' and
- delete from "SYS"."MYTESTTAB" where "DEPTNO" = '40' and "DNAME" = 'OperaTIONS' and "LOC" = 'BOSTON'
- delete from "SYS"."MYTESTTAB" where "DEPTNO" = '80' and "DNAME" = 'IT' and "LOC" = 'WA' and ROWID =
- delete from "SYS"."MYTESTTAB" where "DEPTNO" = '90' and "DNAME" = 'MGR' and "LOC" = 'YR' and ROWID =
- 已抉擇9行。
- SQL> select t.SQL_UNDO from v$logmnr_contents t where t.seg_name='MYTESTTAB';
- SQL_UNDO
- ----------------------------------------------------------------------------------------------------
- delete from "SYS"."MYTESTTAB" where "DEPTNO" = '80' and "DNAME" = 'IT' and "LOC" = 'WA' and ROWID =
- delete from "SYS"."MYTESTTAB" where "DEPTNO" = '90' and "DNAME" = 'MGR' and "LOC" = 'YR' and ROWID =
- insert into "SYS"."MYTESTTAB"("DEPTNO","DNAME","LOC") values ('10','ACCOUNTING','NEW YORK');
- insert into "SYS"."MYTESTTAB"("DEPTNO","DNAME","LOC") values ('20','RESEARCH','DALLAS');
- insert into "SYS"."MYTESTTAB"("DEPTNO","DNAME","LOC") values ('30','SALES','CHICAGO');
- insert into "SYS"."MYTESTTAB"("DEPTNO","DNAME","LOC") values ('40','OperaTIONS','BOSTON');
- insert into "SYS"."MYTESTTAB"("DEPTNO","DNAME","LOC") values ('80','IT','WA');
- insert into "SYS"."MYTESTTAB"("DEPTNO","DNAME","LOC") values ('90','MGR','YR');
- 已抉擇9行。