oracle 清理和重建表空间

先声明一点,本篇文章是参照站长学院网站的,如有版权侵犯问题,立刻删除。

一般正常情况下oracle是会自动释放临时表空间的,但在有些情况下tem表空间不会释放,出现满的情况,昨天在数据中心生产环境上,就出现这个问题。所以通过上网找资料,也写一下了。感觉站长学院的这边文章挺好的,在这写一个,方便自己以后阅读。

方法一

重启数据库,这种方法很多时候是不可行的,因为生产库,数据在随时变换的,根本不允许重启,这种方法虽然简单好用,但是缺少应用的机会。

方法二

修改一下TEMP表空间的storage参数,让Smon进程观注一下临时段,从而达到清理和TEMP表空间的目的。

SQL>alter tablespace temp increase 1;

SQL>alter tablespace temp increase 0;

方法三

1.使用下列语句查看谁在用临时段

SELECT username,

sid,

serial#,

sql_address,

machine,

program,

tablespace,

segtype,

contents

FROM v$session se,

v$sort_usage su

WHERE se.saddr=su.session_addr

2.然后杀掉正在使用临时段的进程

alter system kill session 'sid,serial#';

3.把temp表空间回缩一下

alter tablespace temp coalesce;

方法四

使用诊断事件来处理

1.确定tem表空间的ts#

select ts#, name from sys.ts$ ;

2.执行清理操作

alter session set events 'immediate trace name DROP_SEGMENTS level 4' ;

emp表空间的TS# 为 3*, So TS#+ 1= 4

重建临时表空间

1.创建中转站表空间

create temporary tablespace TEMP1 TEMPFILE 'E:ORACLEORADATAORCL9temp02.DBF' SIZE 512M REUSE AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED;

2.改变缺省表空间为刚刚创建的temp1

alter database default temporary tablespace temp1;

3.删除原来的临时表空间

drop tablespace temp including contents and datafiles;

4.重新创建临时表空间(和上面创建表空间语句一样)

5.重置缺省表空间为temp(和上面的重置语句一样);

6.删掉中转站临时表空间

drop tablespace temp1 including contents and datafiles;

7.有时还需要重新为用户指定

alter user scott temporary tablespace temp;

原文地址:https://www.cnblogs.com/wujin/p/2346353.html