Oracle临时表空间过大怎么办
来源:优易学  2011-12-30 15:43:19   【优易学:中国教育考试门户网】   资料下载   IT书店
  查询数据库服务器时,发现数据库服务器磁盘使用空间达到了98%,分析总共的数据文件也不可能达到如此大,经过查询发现原来临时表空间的使用情况达到了 32G,导致磁盘空间使用紧张。搜索了相应的文档与资料后,查出临时表空间主要使用在:
  - 索引创建或重创建。
  - ORDER BY or GROUP BY (这个是‘罪魁祸首’)
  - DISTINCT 操作。
  - UNION & INTERSECT & MINUS - Sort-Merge joins. - Analyze 操作
  - 有些异常将会引起temp暴涨(这个也很有可能)
  下面是重新创建一个临时表空间,把原来的默认临时表空间drop掉(包括里面的临时数据文件)再重新建立
  SQL> create temporary tablespace temp2
  2 tempfile '/home/oracle/oracle/product/10.2.0/oradata/hatest/temp02.pdf' size 512M reuse
  3 autoextend on next 640k maxsize unlimited;
  Tablespace created.
  SQL> alter database default temporary tablespace temp2;
  Database altered.
  SQL> drop tablespace temp including contents and datafiles;
  Tablespace dropped.
  (注意:由于临时表空间的数据文件比较大,所以这步可能会花费比较长的时间)
  SQL> create temporary tablespace temp
  2 tempfile '/home/oracle/oracle/product/10.2.0/oradata/hatest/temp01.pdf' size 512M reuse
  3 autoextend on next 640K maxsize unlimited;
  Tablespace created.
  SQL> alter database default temporary tablespace temp;
  Database altered.
  SQL> drop tablespace temp2 including contents and datafiles;
  Tablespace dropped.
  SQL> exit
  以上的方法只是暂时释放了临时表空间的磁盘占用空间,是治标但不是治本的方法,真正的治本的方法是找出数据库中消耗资源比较大的sql语句,然后对其进行优化处理。下面是查询在sort排序区使用的执行耗时的SQL
  Select se.username,se.sid,su.extents,su.blocks*to_number(rtrim(p.value))as Space,tablespace,segtype,sql_text
  from v$sort_usage su,v$parameter p,v$session se,v$sql s
  where p.name='db_block_size' and su.session_addr=se.saddr and s.hash_value=su.sqlhash and s.address=su.sqladdr
  order by se.username,se.sid

责任编辑:小草

文章搜索:
 相关文章
热点资讯
热门课程培训