码迷,mamicode.com
首页 > 数据库 > 详细

监控sql运行时剩余时间

时间:2017-05-23 11:24:40      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:信息   style   using   like   查询   and   trace   data-   art   


--监控sql执行时剩余时间
你知道正在执行的sql大概须要多长时间么?
你知道正在执行的sql大概完毕了百分之几么?
你知道正在执行的sql大概还要多长时间完毕么?
V$SESSION_LONGOPS帮你忙。


V$SESSION_LONGOPS在<span style="font-family: Arial, Helvetica, sans-serif;">官方文档中的描写叙述:</span>

V$SESSION_LONGOPS displays the status of various operations that run for longer than 6 seconds (in absolute time). These operations currently include many backup and recovery functions, statistics gathering, and query execution, and more operations are added for every Oracle release.

To monitor query execution progress, you must be using the cost-based optimizer and you must:

Set the TIMED_STATISTICS or SQL_TRACE parameters to true
Gather statistics for your objects with the DBMS_STATS package





--意义:
统计各个操作时间大于6s的语句

--前提条件:
基于成本的优化器cbo
TIMED_STATISTICS或SQL_TRACE为true
对象有统计信息

測试:

select * from v$version;
--Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

select * from v$parameter where name like ‘%timed_statistics%‘
VALUE
TRUE

select last_analyzed from user_tables where table_name=‘LHJ_1G‘
LAST_ANALYZED
2013-12-10 PM 01:19:36


--session1:
drop table t;
create table t as 
select * from lhj_1g;

--session2:
select a.username,
       a.target,
       a.sid,
       a.SERIAL#,
       a.opname,
       round(a.sofar * 100 / a.totalwork, 0) || ‘%‘ as progress, --进度条
       time_remaining second, --剩余时间:秒
       trunc(a.time_remaining / 60, 2) minute,--剩余时间:分钟
       b.sql_text,
       b.LAST_ACTIVE_TIME
  from v$session_longops a, v$sqlarea b
 where a.time_remaining <> 0
   and a.sql_address = b.address
   and a.sql_hash_value = b.hash_value
   and a.username = ‘GGS‘ 



技术分享


过一会再反复运行上面语句:

技术分享


sql语句运行完毕或者取消后。以上查询为空

监控sql运行时剩余时间

标签:信息   style   using   like   查询   and   trace   data-   art   

原文地址:http://www.cnblogs.com/liguangsunls/p/6892841.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!