签到成功

知道了

CNDBA社区CNDBA社区

12c 新特性--Real-Time Database Operation Monitoring

2016-10-18 09:38 3853 0 原创 Oracle 12C
作者: Expect-乐

这个新特性是11g sql monitor的高级版。sql_monitor是监控一定时间内执行的sql,或者是

hint监控sql。12c中,该特性允许你监控混合的操作包括一些SQL和PL/SQL。通过DBMS_SQL_MONITOR 

这个包去实现。

通过BEGIN_OPERATION 和 END_OPERATION存储过程去标识监控的开始和结束。

如:

#创建测试表http://www.cndba.cn/Expect-le/article/293http://www.cndba.cn/Expect-le/article/293

DROP TABLE t1 PURGE;
DROP TABLE t2 PURGE;
CREATE TABLE t1 AS
SELECT level AS id,
  'Description for ' || level AS description
FROM   dual
CONNECT BY level <= 1000000;
CREATE TABLE t2 AS
SELECT level AS id,
  'Description for ' || level AS description
FROM   dual
CONNECT BY level <= 1000000;

#开始监控操作

VARIABLE l_dbop_eid NUMBER;
BEGIN
  :l_dbop_eid := DBMS_SQL_MONITOR.begin_operation (
    dbop_name       => 'db_op_1',
    dbop_eid        => :l_dbop_eid,
    forced_tracking => DBMS_SQL_MONITOR.force_tracking
  );
END;
/

#DBMS_SQL_MONITOR.begin_operation几个参数说明:

1)DBOP_NAME : A user-defined name for the composite database operation.
2)DBOP_EID : An optional unique identifier for the current execution of the composite database operation. If it is NULL, a unique execution identifier is created.
3)FORCED_TRACKING : When set to the constant FORCE_TRACKING (Y), the operation is tracked. When set to NO_FORCE_TRACKING (N), the default, the operation is only tracked if it has consumed 5 seconds of CPU or I/O time.
4)ATTRIBUTE_LIST : An optional comma-separated list of name-value pairs of attributes to restrict the calls that are monitored during the operating period.


http://www.cndba.cn/Expect-le/article/293

#对表进行一些操作

http://www.cndba.cn/Expect-le/article/293

BEGIN
  FOR cur_rec IN (SELECT * FROM t1) LOOP
    NULL;
  END LOOP;
  FOR cur_rec IN (SELECT * FROM t2) LOOP
    NULL;
  END LOOP;
END;
/

#结束监控操作

BEGIN
  DBMS_SQL_MONITOR.end_operation (
    dbop_name       => 'db_op_1',
    dbop_eid        => :l_dbop_eid
  );
END;
/

#查看被监控的操作在V$SQL_MONITOR视图中

SET LINESIZE 200
SELECT dbop_name, dbop_exec_id, status
FROM   v$sql_monitor
WHERE  username = 'LEI';
DBOP_NAME                      DBOP_EXEC_ID STATUS
------------------------------ ------------ -------------------
db_op_1                                   3 DONE
db_op_1                                   2 DONE
db_op_1                                   1 DONE
SQL>


#REPORT_SQL_MONITOR

--这里和11g没有区别,只是包不同了。从DBMS_SQLTUNE 换到了DBMS_SQL_MONITORhttp://www.cndba.cn/Expect-le/article/293

--可以指定dbop_name来获得最新的数据库操作的报告。http://www.cndba.cn/Expect-le/article/293http://www.cndba.cn/Expect-le/article/293

--也可以指定DBOP_EXEC_ID来获得指定的操作执行的报告。

SET LONG 1000000
SET LONGCHUNKSIZE 1000000
SET LINESIZE 1000
SET PAGESIZE 0
SET TRIM ON
SET TRIMSPOOL ON
SET ECHO OFF
SET FEEDBACK OFF
SPOOL /home/oracle/report_sql_monitor.htm
SELECT DBMS_SQL_MONITOR.report_sql_monitor(
  dbop_name    => 'db_op_1',
  type         => 'HTML',
  report_level => 'ALL') AS report
FROM dual;
SPOOL OFF

#REPORT_SQL_MONITOR_LIST

--和11g也无区别,只是支持了active report

SET LONG 1000000
SET LONGCHUNKSIZE 1000000
SET LINESIZE 1000
SET PAGESIZE 0
SET TRIM ON
SET TRIMSPOOL ON
SET ECHO OFF
SET FEEDBACK OFF
SPOOL /home/oracle/report_sql_monitor_list.htm
SELECT DBMS_SQL_MONITOR.report_sql_monitor_list(
  type         => 'HTML',
  report_level => 'ALL') AS report
FROM dual;
SPOOL OFF

#REPORT_SQL_DETAIL

--这个过程还是在包DBMS_SQLTUNE 中

注意:ACTIVE需要联网下载相关模板才能查看。所以需要联网。

http://www.cndba.cn/Expect-le/article/293

SET LONG 1000000
SET LONGCHUNKSIZE 1000000
SET LINESIZE 1000
SET PAGESIZE 0
SET TRIM ON
SET TRIMSPOOL ON
SET ECHO OFF
SET FEEDBACK OFF
SPOOL /home/oracle/report_sql_monitor_detail.htm
SELECT DBMS_SQLTUNE.REPORT_SQL_DETAIL(
  sql_id       => 'fvwfrjnducq4b',
  type         => 'ACTIVE',
  report_level => 'ALL') AS report
FROM dual;
SPOOL OFF

#相关视图http://www.cndba.cn/Expect-le/article/293

V$SQL_MONITOR
V$SQL_PLAN_MONITOR

更多信息请参考官方文档:http://www.cndba.cn/Expect-le/article/293

http://docs.oracle.com/database/121/TGSQL/tgsql_monit.htm#TGSQL94605


版权声明:本文为博主原创文章,未经博主允许不得转载。

12c Real-Time Database Operation Monitoring

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
Expect-乐

Expect-乐

关注

Without the continuous bitter cold, there can be no fragrant plum blossom

  • 336
    原创
  • 6
    翻译
  • 100
    转载
  • 41
    评论
  • 访问:1594972次
  • 积分:1957
  • 等级:核心会员
  • 排名:第4名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ