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_PROCESSED,
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
其他方法:
查找前十条性能差的sql.
查看占io较大的正在运行的session