oracle最近执行的sql语句

2017-01-13

oracle 查询最近执行过的 SQL语句

1、修改日期显示格式
alter session set nls_date_format=’YYYY-MM-DD HH24:MI:SS’;
2、哪个主机最近执行的sql语句:
SELECT b.sql_text,a.machine,a.username, a.module,c.sofar / totalwork * 100,
c.elapsed_seconds,c.time_remaining
FROM v$session a, v$sqlarea b, v$session_longops c
WHERE a.sql_hash_value = b.hash_value(+) AND a.SID = c.SID(+)
AND a.serial# = c.serial#(+)
--AND a.sid=139
3、最近的sql语句

SELECT sql_text, last_load_time,LAST_ACTIVE_TIME FROM v$sql WHERE LAST_LOAD_TIME > trunc(sysdate) and last_load_time IS NOT NULL ORDER BY last_load_time DESC;
4、正在执行的sql
SELECT a.sid, a.serial#, b.sql_text
FROM v$session a, v$sqltext b
WHERE a.sql_address = b.address
--AND a.sid = <...>
ORDER BY b.piece
5、select sql_text,last_load_time from v$sql order by last_load_time desc;

6、other

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;
7、正在执行的

select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXT
  from v$session a, v$sqlarea 
where a.sql_address b.address 
---执行过的
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 
8、查找前十条性能差的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 

9、查看占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
分类:数据库 | 标签: |

相关日志

评论被关闭!