oracle測試環境表空間清理

測試場景下,使用的oralce遇到表空間的佔用超大,能夠採用以下的方式進行空間的清理sql

 

首先使用sqlplus鏈接數據庫
sqlplus sys/password@orcl as sysdba 之類進行數據庫的鏈接沒而後進行以下的操做數據庫

##建立表空間
對於本身的測試庫和表等最好都創建本身的表空間,以方便清理和刪除oracle

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

##查看錶空間的狀況
oracle查詢表空間文件所在路徑  測試

        select * from dba_data_files
       
經過這個命令能夠查看各表空間所在的路徑位置spa

##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的文件刪除,就能夠釋放空間。索引

+ 還原回來table

        還能夠改成原來的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的文件刪除,就能夠釋放空間。file

如上就能夠把很是大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 值之外使用的數據」這個錯誤,調整表空間的大小便可,完成後便可釋放多餘的表空間

相關文章
相關標籤/搜索