当前位置:   article > 正文

查询Oracle正在执行和执行过的SQL语句_sql查询oracle命令执行状态

sql查询oracle命令执行状态

正在执行的

select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXT
  from v$session a, v$sqlarea b 
where a.sql_address = b.address 
  • 1
  • 2
  • 3

执行过的

select b.SQL_TEXT,b.FIRST_LOAD_TIME,b.SQL_FULLTEXT
  from v$sqlarea b
where b.FIRST_LOAD_TIME between '2009-10-15/09:24:47' and
       '2009-10-15/09:24:47' order by b.FIRST_LOAD_TIME 
  • 1
  • 2
  • 3
  • 4

(此方法好处可以查看某一时间段执行过的sql,并且 SQL_FULLTEXT 包含了完整的 sql 语句)

其他

select OSUSER,PROGRAM,USERNAME,SCHEMANAME,B.Cpu_Time,STATUS,B.SQL_TEXT 
from V$SESSION A LEFT JOIN V$SQL B ON A.SQL_ADDRESS=B.ADDRESS 
AND A.SQL_HASH_VALUE=B.HASH_VALUE order by b.cpu_time desc 
  • 1
  • 2
  • 3
select address, sql_text, piece 
  from v$session, v$sqltext 
where address = sql_address 
  -- and machine = < you machine name > 
order by address, piece 
  • 1
  • 2
  • 3
  • 4
  • 5

查找前十条性能差的sql.

SELECT * FROM (select PARSING_USER_ID,EXECUTIONS,SORTS, 
COMMAND_TYPE,DISK_READS,sql_text FROM v$sqlarea 
order BY disk_reads DESC )where ROWNUM<10 ; 
  • 1
  • 2
  • 3

查看占io较大的正在运行的session

SELECT se.sid,se.serial#,pr.SPID,se.username,se.status, 
se.terminal,se.program,se.MODULE,、se.sql_address,st.event,st. 
p1text,si.physical_reads, 
si.block_changes FROM v$session se,v$session_wait st, 
v$sess_io si,v$process pr WHERE st.sid=se.sid AND st. 
sid=si.sid AND se.PADDR=pr.ADDR AND se.sid>6 AND st. 
wait_time=0 AND st.event NOT LIKE '%SQL%' ORDER BY physical_reads DESC
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

查询被锁表的数据库表:

select sess.sid, sess.serial#, lo.oracle_username, lo.os_user_name, ao.object_name, lo.locked_mode 
from v$locked_object lo, dba_objects ao, v$session sess 
where ao.object_id = lo.object_id and lo.session_id = sess.sid; 
  • 1
  • 2
  • 3

强制删除锁表的进程:

alter system kill session 'sid,serial#'
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/278422
推荐阅读
相关标签
  

闽ICP备14008679号