查看占用temp/undo最大的sql

temp

select sess.username, sql.sql_text, sort1.blocks 
  from v$session sess, v$sqlarea sql, v$sort_usage sort1 
where sess.serial# = sort1.session_num 
   and sort1.sqladdr = sql.address 
   and sort1.sqlhash = sql.hash_value  and sort1.blocks > 5
按照hash查找sql语句
select sid || ',' || S.serial# sid_serial,
S.username,t.blocks * tbs.block_size/1024/1024 gb_use,
t.tablespace,q.hash_value,q.sql_text 
from v$sort_usage T,v$session S,v$sqlarea Q,dba_tablespaces TBS
where t.session_addr = s.saddr and t.sqladdr=q.address
and t.sqladdr=q.address(+) and t.tablespace=tbs.tablespace_name order by gb_use desc;

undo

select 
s.sid,s.serial#,
s.sql_id,
v.usn,
segment_name,
r.status, 
v.rssize/1024/1024 mb
     from 
dba_rollback_segs r, 
v$rollstat v,
v$transaction t,
v$session s
     Where 
r.segment_id = v.usn and 
v.usn=t.xidusn and 
t.addr=s.taddr
order by segment_name;

select * from v$sqlarea where sql_id='xxx';

查看归档量大小

SQL> SELECT SUM(block_size*blocks)/1024/1024/1024 "SIZE(GB)"
FROM v$archived_log 
WHERE TRUNC(first_time) >= TRUNC(sysdate-1)
AND TRUNC(first_time) < TRUNC(sysdate);  2    3    4  

  SIZE(GB)
----------
.041360855

查看占用temp/undo最大的sql_第1张图片
查看占用temp/undo最大的sql_第2张图片
查看占用temp/undo最大的sql_第3张图片

你可能感兴趣的:(sql,数据库)