【问题标题】:Measuring/Monitoring response time of each execution of a sql测量/监控每次执行 sql 的响应时间
【发布时间】:2018-05-19 01:06:04
【问题描述】:

在Oracle 11g中,我想监控特定sql的响应时间(我知道该sql的sql_id)。意思是,我想知道每次执行sql时的响应时间。我会“打开”一段时间,然后希望看到类似以下的数据:

For sql_id 'abcdefg', following were the execution time (in ms) 10 12 10 13 10 10 10 240 230 10 9 12 … …

我们可以忽略我希望看到的输出的确切格式,但是我有什么方法可以监控,以便我可以获得每次执行我的 sql 的响应时间?

谢谢。

【问题讨论】:

    标签: oracle oracle11g database-performance query-performance


    【解决方案1】:

    首先,你应该跟踪你的sql(假设sql_id:6b0z40gs9m759):

    SQL> ALTER SESSION SET sql_trace=TRUE;
    
    SQL> ALTER SESSION SET EVENTS 'trace[rdbms.SQL_Optimizer.*][sql:6b0z40gs9m759]';
    [ SQL> ALTER SYSTEM SET EVENTS 'sql_trace [sql:&&sql_id] bind=true, wait=true'; ] -- or use this as alternative.
    
    SQL> ALTER SESSION SET TRACEFILE_IDENTIFIER = "TrcSqlParag"; -- adds this text to your trace file and makes it more recognizable by you.
    
    SQL> SHOW PARAMETER user_dump_dest -- trace files are produced in this directory
    
    -- For 11g DB, you may easily query v$diag_info view to see your file destination :
    SQL> SELECT value FROM   v$diag_info WHERE  name = 'Default Trace File';
    
    -- You can identify the trace file for a specific session using the V$SESSION and V$PROCESS views :
    SQL> SELECT p.tracefile FROM v$session s JOIN v$process p ON s.paddr = p.addr WHERE  s.sid = &ses_id;
    
    -- You may finish tracing whenever you want :
    SQL> ALTER SESSION SET sql_trace=FALSE; 
    

    让我们有这样一个转储文件:

    /u01/app/oracle/admin/MYDB11G/udump/mydb11g_ora_TrcSqlParag.trc
    

    trace文件不易读取,需要tkprof utility从OS读取:

    $ cd /u01/app/oracle/admin/MYDB11G/udump/
    $ tkprof mydb11g_ora_TrcSqlParag.trc TrcSqlParag_Translated1.txt explain=<username>/<pwd>@mydb11g table=sys.plan_table sys=no waits=yes
    

    【讨论】:

    • 嗨,Barbaros,虽然 stackoverflow 指南说不要添加评论来表示“谢谢”,但我现在只是这么说。因为我确实尝试过你所说的并且它适用于我的特定会话,但我想为整个应用程序执行此操作(我猜“alter system”而不是“alter session”会这样做)然后看看我是否能够整理数据并最终获得我正在寻找的查询响应时间。感谢您提供如此精美的详细步骤(甚至是“个性化”步骤!)。我会在几天内更新线程。
    • 嗨,Barbaros,我用“alter system”尝试了上述方法并且一切正常 - 尽管识别我的跟踪文件有点痛苦,因为我无法命名它们。我有一个 java 代码在 stmt.executeQuery 之前占用系统时间,就在它之后,然后在循环整个结果集之后占用系统时间。然后它会打印每个步骤花费了多长时间。我正在尝试将从跟踪中获得的数字映射到此,并且在关联这些数字时遇到了一些困难。如果我在那里发现有趣的东西,我会尝试更多并添加到线程中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多