oracle测试环境表空间清理

测试场景下,使用的oralce遇到表空间的占用超大,可以采用如下的方式进行空间的清理

 

首先使用sqlplus连接数据库
sqlplus sys/password@orcl as sysdba 之类进行数据库的连接没然后进行如下的操作

##创建表空间
对于自己的测试库和表等最好都建立自己的表空间,以方便清理和删除

    create tablespace abc datafile '/opt/oracle/app/oradata/orcl/users02.dbf' size 1024m autoextend on next 100m maxsize 10240m extent management local;      创建表空间

##查看表空间的情况
oracle查询表空间文件所在路径 

        select * from dba_data_files
       
通过这个命令可以查看各表空间所在的路径位置

##temp表空间的重建
+ 新建1个

        当数据库进行索引重建,或者大量数据导入导出时,会使得temp表空间暴增,很可能撑满数据文件,因为数据库安装的时候,temp表空间默认很自由一个数据文件
        并且数据库中单个数据文件最大只能自增到32G,当超过32G时就不可用了,为了防止此故障发生,在做索引重建或者大量数据导入导出时,需要关注temp表空间
        的增长情况,temp表空间过大时,可通过如下方法重建
        SQL> create temporary tablespace temp2 tempfile 'C:\oracle\product\10.2.0\oradata\ORCL\temp2.dbf' size 200M autoextend off;
        SQL> alter database default temporary tablespace temp2;
        SQL> drop tablespace temp;
        或者SQL> drop tablespace temp including contents and datafiles cascade constraints(彻底删除包括操作系统中的临时表空间的数据文件)
        最后在操作系统上把temp的文件删除,就可以释放空间。

+ 还原回来

        还可以改为原来的temp
        SQL> create temporary tablespace temp tempfile 'C:\oracle\product\10.2.0\oradata\ORCL\temp.dbf' size 200M autoextend off;
        SQL> alter database default temporary tablespace temp;
        SQL> drop tablespace temp2;
        最后在操作系统上把temp的文件删除,就可以释放空间。

如上就可以把非常大temp表空间清理掉

##system表空间用满解决
        alter database datafile 'C:\oracle\product\10.2.0\oradata\ORCL\system01.dbf' autoextend on; 
        alter database datafile 'C:\oracle\product\10.2.0\oradata\ORCL\system01.dbf' resize 2096M;
如果出现“ORA-03297: 文件包含在请求的 RESIZE 值以外使用的数据”这个错误,调整表空间的大小即可,
完成后即可释放多余的表空间

posted @ 2017-09-05 18:24  2012  阅读(633)  评论(0编辑  收藏  举报