最近測試環境需要把一些現有的存儲空間勻出一部分來給新增的環境使用。
unix組的人很快就空間按照指定的比例重新切分好了。環境交給我的時候,我先把資料庫起來,沒有任何問題,因為需要到處一個建立使用者的語句,就簡單執行了一個查詢。
select dbms_metadata.get_ddl('USER',u.username) from dba_users u WHERE USERNAME in('TEST');
但是讓我意外的,報了如下的錯誤。
SQL> select dbms_metadata.get_ddl('USER',u.username) from dba_users u WHERE USERNAME in('TEST');
ERROR:
ORA-01157: cannot identify/lock data file 201 - see DBWR trace file
ORA-01110: data file 201: '/u01/oracle/TEST/oratmp01/temp/temp01.dbf'
ORA-06512: at "SYS.DBMS_METADATA", line 4018
ORA-06512: at "SYS.DBMS_METADATA", line 5843
ORA-06512: at line 1
no rows selected
想資料檔案被清掉了,先給offline了重新配置一下。
offline不可以,offline drop也不行。
SQL> alter database datafile '/u01/oracle/TEST/oratmp01/temp/temp01.dbf' offline;
alter database datafile '/u01/oracle/TEST/oratmp01/temp/temp01.dbf' offline
*
ERROR at line 1:
ORA-01516: nonexistent log file, data file, or temporary file
"/u01/oracle/TEST/oratmp01/temp/temp01.dbf"
SQL> alter database datafile '/u01/oracle/TEST/oratmp01/temp/temp01.dbf' offline drop;
alter database datafile '/u01/oracle/TEST/oratmp01/temp/temp01.dbf' offline drop
我說不能offline,offline drop,有的人說得放在mount狀态下執行,我試了也不行。
我直接删除表空間重建立得了,oracle已經開始給我哭窮了,說不能删除預設的臨時表空間。
SQL> drop tablespace temp including contents and datafiles;
drop tablespace temp including contents and datafiles
ORA-12906: cannot drop default temporary tablespace
那我删除這個臨時檔案,oracle又說這個臨時表空間裡隻有一個資料檔案。
SQL> alter tablespace temp drop tempfile '/u01/oracle/TEST/oratmp01/temp/temp01.dbf';
alter tablespace temp drop tempfile '/u01/oracle/TEST/oratmp01/temp/temp01.dbf'
ORA-03261: the tablespace TEMP has only one file
我還是自己檢視下檔案夾到底在不在。一查檔案夾都被清掉了。
SQL> !ls -l /dbusgsPT1/oracle/PETUSG1/oratmp01/temp
ls: /dbusgsPT1/oracle/PETUSG1/oratmp01/temp: No such file or directory
先把檔案夾給補上
SQL> !mkdir -p /u01/oracle/TEST/oratmp01/temp
建立一個别名的臨時檔案,馬上見temp01的臨時資料檔案還不行。
SQL> alter tablespace temp add tempfile '/u01/oracle/TEST/oratmp01/temp/temp02.dbf' size 20G;
Tablespace altered.
然後再去删除其實不存在的臨時資料檔案。從資料字典裡進行更新。
後續就如果需要可以把臨時資料檔案的名字從temp02.dbf改成temp01.dbf