zoukankan      html  css  js  c++  java
  • 利用sql_trace跟踪一个指定会话的操作

    1.  sys用户给管理用户授权。
    SQL> grant execute on sys.dbms_system to andy;


    Grant succeeded.


    2. 查询被跟踪用户的sid,serial#  
    SQL> select sid,serial# from v$session where username='DBLINK';


           SID    SERIAL#
    ---------- ----------
    31    7
    3.  管理用户andy开始跟踪dblink用户
    SQL> exec sys.dbms_system.set_sql_trace_in_session(31,7,true);


    PL/SQL procedure successfully completed.


    4.  dblink被跟踪用户执行测试语句。
    SQL> select * from user_tables;


    5.  跟踪结束
    SQL> exec sys.dbms_system.set_sql_trace_in_session(31,7,false);


    PL/SQL procedure successfully completed.


    6.  dblink用户查询自己当前trace文件号
    SQL>  select * from v$diag_info where name like 'Default%';


       INST_ID NAME
    ---------- ----------------------------------------------------------------
    VALUE
    --------------------------------------------------------------------------------
    1 Default Trace File
    /home/oracle/app/diag/rdbms/orcl/orcl/trace/orcl_ora_3524.trc


    7. 用tkprof工具生成查看文件
    [oracle@11g ~]$ tkprof /home/oracle/app/diag/rdbms/orcl/orcl/trace/orcl_ora_3524.trc andy2.txt sys=no


    TKPROF: Release 11.2.0.1.0 - Development on Mon Nov 17 16:48:38 2014


    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


    8.  查看跟踪记录
    [oracle@11g ~]$ cat andy2.txt


    TKPROF: Release 11.2.0.1.0 - Development on Mon Nov 17 16:48:38 2014


    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


    Trace file: /home/oracle/app/diag/rdbms/orcl/orcl/trace/orcl_ora_3524.trc
    Sort options: default


    ********************************************************************************
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing 
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    ********************************************************************************


    SQL ID: dtbhjabjx3v1u
    Plan Hash: 4102440123
    select * 
    from                       <--  #刚执行sql找到
     user_tables           




    call     count       cpu    elapsed       disk      query    current        rows
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    Parse        1      0.09       0.10          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2      0.11       0.31        174       1390          0           1
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    total        4      0.21       0.41        174       1390          0           1
    。。。。省略输出。
       


    OK,结束。  转载请标明出处

  • 相关阅读:
    Python+selenium常见报错
    jmeter压力测试指标解释
    jemte自动生成测试报告方法
    iview清空Date-picker组件后请求报错解决方法
    【求助】Django+vue项目时候遇到一个问题,table的data数据怎么更新
    django_数据库操作—增、删、改、查
    django-关于manage.py migrate无效的问题
    python家里的环境和公司环境怎么同步
    python class类的属性应用及init初始化实践 ---勇者斗恶龙
    IDLE与pycharm执行相同代码结果却不同,原因分析
  • 原文地址:https://www.cnblogs.com/andy6/p/6195942.html
Copyright © 2011-2022 走看看