Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3561733
  • 博文数量: 715
  • 博客积分: 1860
  • 博客等级: 上尉
  • 技术积分: 7745
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-07 08:51
个人简介

偶尔有空上来看看

文章分类

全部博文(715)

文章存档

2023年(75)

2022年(134)

2021年(238)

2020年(115)

2019年(11)

2018年(9)

2017年(9)

2016年(17)

2015年(7)

2014年(4)

2013年(1)

2012年(11)

2011年(27)

2010年(35)

2009年(11)

2008年(11)

最近访客

分类: Oracle

2023-07-03 11:53:43

定位导致temp消耗过大的sql,优化即可


  1. --检查temp大小
  2. set lin 200 pages 100
  3. col tablespace_name for a20
  4. col FILE_NAME for a40
  5. select tablespace_name,file_name,round(bytes/1024/1024)m from dba_temp_files order by 1,2;

  6. col TABLESPACE_NAME for a20
  7. select TABLESPACE_NAME,file_id,round(BYTES_USED/1024/1024,2) BYTES_USED_mb,
  8. round(BLOCKS_USED*8/1024,2) BLOCKS_USED_m,BYTES_FREE/1024/1024 free_mb from v$temp_space_header;

  9. --检查当前使用情况
  10. col username for a15
  11. col TABLESPACE for a18
  12. col EVENT for a30
  13. select s.sid,s.username,s.state,s.event,s.sql_id,u.tablespace,u.contents,u.segtype,round(((u.blocks*p.value)/1024/1024),2) mb
  14. from v$session s ,v$sort_usage u,v$parameter p
  15. where s.saddr=u.session_addr
  16. and upper(p.name)='DB_BLOCK_SIZE'
  17. order by mb desc;

  18. --检查历史使用情况
  19. select *
  20. from (select instance_number, sql_id, max(temp_sum_mb) temp_max
  21.         from (select instance_number, sample_time, sql_id, round(sum(nvl(temp_space_allocated, 0))/1024/1024) temp_sum_mb
  22.                 from dba_hist_active_sess_history
  23.                where sample_time between sysdate-1/24 and sysdate
  24.             group by instance_number, sample_time, sql_id)
  25.        group by instance_number, sql_id
  26.        order by temp_max desc)
  27. where rownum <= 10;


--看看sql 内容
col sql_text for a80
set lin 80 pages 1000
select sql_text from v$sqltext where sql_id='&sql_id' order by piece;

--看看sql计划
set long 1000000
set longchunksize 1000000
set lin 300 pages 1000
set trim on
set trimspool on
set echo off
set feedback off
select dbms_sqltune.report_sql_monitor(sql_id=>'&sqlid',type=>'TEXT',report_level=>'ALL') mon_rpt from dual;




参考:

  1. http://blog.chinaunix.net/uid-20687159-id-5853939.html

阅读(250) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~