Home > Database > Mysql Tutorial > Oracle 11g之LogMiner常用场景

Oracle 11g之LogMiner常用场景

WBOY
Release: 2016-06-07 14:50:10
Original
1095 people have browsed it

1 LogMiner 常用场景 1.1 用 LogMiner 跟踪特定用户所做的更改 本节例子,查出用户joedevo在特定时间范围内对数据库所做的所有操作,步骤如下: 1.创建LogMiner字典 使用LogMiner分析joedevo相关的数据,必须在joedevo对它的所有表做任何的更改操作前创建Lo

LogMiner常用场景


1.1 LogMiner跟踪特定用户所做的更改


本节例子,查出用户joedevo在特定时间范围内对数据库所做的所有操作,步骤如下:

1.创建LogMiner字典

   使用LogMiner分析joedevo相关的数据,必须在joedevo对它的所有表做任何的更改操作前创建LogMiner字典或者直接使用在线字典,本例使用已提取到重做日志文件中的LogMiner字典。

2.添加重做日志文件

在joedevo对数据库做了一些更改操作之后,可以指定对应的重做日志文件来分析:

SQL> EXECUTE DBMS_LOGMNR.ADD_LOGFILE( -

   LOGFILENAME => 'log1orc1.ora', -

   OPTIONS => DBMS_LOGMNR.NEW);
Copy after login

根据需要添加其他的重做日志文件:

SQL> EXECUTE DBMS_LOGMNR.ADD_LOGFILE( -

   LOGFILENAME => 'log2orc1.ora', -

   OPTIONS => DBMS_LOGMNR.ADDFILE);
Copy after login

3.开启LogMiner并限制查询范围

SQL> EXECUTE DBMS_LOGMNR.START_LOGMNR( -

   DICTFILENAME => 'orcldict.ora', -

   STARTTIME => TO_DATE('01-Jan-1998 08:30:00','DD-MON-YYYY HH:MI:SS'), - ENDTIME => TO_DATE('01-Jan-1998 08:45:00', 'DD-MON-YYYY HH:MI:SS'));
Copy after login

4.查询V$LOGMNR_CONTENTS

SQL> SELECT SQL_REDO, SQL_UNDO FROM V$LOGMNR_CONTENTS

   WHERE USERNAME = 'joedevo' AND SEG_NAME = 'salary';
Copy after login

5.停止LogMiner

SQL> EXECUTE DBMS_LOGMNR.END_LOGMNR();
Copy after login
Copy after login


1.2 LogMiner做表的访问统计


   本节案例中,假设你管理者一个直营数据库,想确定1月份2周内客户带来的生产效益,假定你已经创建了LogMiner字典并添加了相关的重做日志文件,接下来的步骤如下:

1.开始LogMiner并限制查询范围

SQL> EXECUTE DBMS_LOGMNR.START_LOGMNR( -

   STARTTIME => TO_DATE('07-Jan-2003 08:30:00','DD-MON-YYYY HH:MI:SS'), -

   ENDTIME => TO_DATE('21-Jan-2003 08:45:00','DD-MON-YYYY HH:MI:SS'), -

   DICTFILENAME => '/usr/local/dict.ora');
Copy after login

2.查询V$LOGMNR_CONTENTS

查询V$LOGMNR_CONTENTS确定指定时间范围内哪些表发生了变化:

SQL> SELECT SEG_OWNER, SEG_NAME, COUNT(*) AS Hits FROM

   V$LOGMNR_CONTENTS WHERE SEG_NAME NOT LIKE '%$' GROUP BY

   SEG_OWNER, SEG_NAME ORDER BY Hits DESC;
Copy after login

3.停止LogMiner

SQL> EXECUTE DBMS_LOGMNR.END_LOGMNR();
Copy after login
Copy after login



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template