oracle正在执行与执行过的sql语句
一,查询正在执行的sql
复制代码 代码示例:
select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXT
from v$session a, v$sqlarea b
where a.sql_address = b.address
二,查询执行过的sql
复制代码 代码示例:
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
(此方法优点:查看某一时间段执行过的sql,并且 SQL_FULLTEXT 包含了完整的sql语句)
select s.SAMPLE_TIME,
sq.SQL_TEXT,
sq.DISK_READS,
sq.BUFFER_GETS,
sq.CPU_TIME,
sq.ROWS_PROCES
sed,
sq.SQL_FULLTEXT,
sq.SQL_ID,
s.program,
s.MACHINE
from v$sql sq, v$active_session_history s
where s.SQL_ID = sq.SQL_ID and sq.SQL_FULLTEXT like '%***%'
order by s.SAMPLE_TIME desc
三,其他:
复制代码 代码示例:
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
select address, sql_text, piece
from v$session, v$sqltext
where address = sql_address
-- and machine = < you machine name >
order by address, piece
四,查找前十条性能差的sql:(www.jb200.com 脚本学堂)
复制代码 代码示例:
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 ;
五,查看占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