如何查看oracle某用户近期执行的SQL
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何查看oracle某用户近期执行的SQL相关的知识,希望对你有一定的参考价值。
oracle 查询最近执行过的 SQL语句select sql_text,last_load_time from v$sql order by last_load_time desc;SELECT sql_text, last_load_time FROM v$sql WHERE last_load_time IS NOT NULL and sql_text like \'select%\' ORDER BY last_load_time DESC;SELECT sql_text, last_load_time FROM v$sql WHERE last_load_time IS NOT NULL and sql_text like \'update%\' ORDER BY last_load_time DESC;SELECT sql_text, last_load_time FROM v$sql WHERE last_load_time IS NOT NULL and last_load_time like\' 14-06-09%\' ORDER BY last_load_time DESC;---正在执行的
select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXTfrom v$session a, v$sqlarea b
where a.sql_address = b.address
---执行过的
select b.SQL_TEXT,b.FIRST_LOAD_TIME,b.SQL_FULLTEXTfrom 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 OSUSER,PROGRAM,USERNAME,SCHEMANAME,B.Cpu_Time,STATUS,B.SQL_TEXTfrom 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 descselect address, sql_text, piece
from v$session, v$sqltext
where address = sql_address
-- and machine = < you machine name >
order by address, piece
查找前十条性能差的sql.
SELECT * FROM (select PARSING_USER_ID,EXECUTIONS,SORTS,COMMAND_TYPE,DISK_READS,sql_text FROM v$sqlareaorder 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 参考技术A 不能查看近期执行的sql,当前执行的可以查看。
如何查询oracle数据库的操作记录
参考技术A查询视图:v$sqlarea,它是oracle中专门存储操作的视图,可以通过它查询历史操作。
授权某用户,查看动态性能视图的权限(如v$latch,v$lock,v$sqlarea,v$sql,v$sysstat)
grant select any dictionary to xxx;
如通过以下查询语句就可以得知那个用户进行了删除操作。
select t.SQL_TEXT, t.FIRST_LOAD_TIME
from v$sqlarea t
where t.SQL_TEXT like \'delete%\' and t.FIRST_LOAD_TIME like \'2013-03-30%\'
order by t.FIRST_LOAD_TIME desc
以上是关于如何查看oracle某用户近期执行的SQL的主要内容,如果未能解决你的问题,请参考以下文章