簡(jiǎn)單介紹
在 Oracle 10g 以前的版本,更改表空間名字是幾乎不可能的事情,除非刪除,重新創(chuàng)建,大費(fèi)周章。Oracle 10g 新添加了一項(xiàng)更改表空間名字的功能,使得更改表空間名字瞬間即可完成。是個(gè)較為人性化的功能。 SQL> COL FILE_NAME format a70
SQL> SET linesize 120 SQL> SET pagesize 99 SQL> COL TABLESPACE_NAME format a10 SQL> SQL> SELECT file_name, tablespace_name FROM dba_data_files; FILE_NAME TABLESPACE ---------------------------------------------------------------------- ---------- /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/users01.dbf USERS /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/sysaux01.dbf SYSAUX /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/undotbs01.dbf UNDOTBS1 /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/system01.dbf SYSTEM /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/example01.dbf EXAMPLE /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/foo1.dbf FOO 6 rows selected. 該命令的語(yǔ)法很簡(jiǎn)單: ALTER TABLESPACE tablespacename RENAME TO newtablespacename;
tablespacename 和newtablespacename 分別對(duì)應(yīng)原來(lái)的表空間名字和更改后的表空間名字: 實(shí)戰(zhàn)演練 注意:在操作前后都請(qǐng)做好控制文件的備份工作 SQL>ALTER TABLESPACE foo RENAME TO test;
Tablespace altered. SQL> SELECT file_name, tablespace_name FROM dba_data_files; FILE_NAME TABLESPACE ---------------------------------------------------------------------- ---------- /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/users01.dbf USERS /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/sysaux01.dbf SYSAUX /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/undotbs01.dbf UNDOTBS1 /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/system01.dbf SYSTEM /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/example01.dbf EXAMPLE /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/foo1.dbf TEST 因?yàn)?system 和 sysaux 這兩個(gè)表空間的特殊性,是不可以更名的: SQL> ALTER TABLESPACE system RENAME TO mysystem;
ALTER TABLESPACE system RENAME TO mysystem * ERROR at line 1: ORA-00712: cannot rename system tablespace SQL> ALTER TABLESPACE sysaux RENAME TO mysysaux; ALTER TABLESPACE sysaux RENAME TO mysysaux * ERROR at line 1: ORA-13502: Cannot rename SYSAUX tablespace 可以對(duì) undo tablespace 重新命名,如果使用的是 spfile ,而不是 pfile, Oracle 會(huì)自動(dòng)對(duì) spfile 中的 undo_tablespace 進(jìn)行更改(不過(guò)要在數(shù)據(jù)庫(kù)重新啟動(dòng)之后才可以觀察到), 如果使用的是 pfile ,要對(duì)其進(jìn)行手工更改。我們看看 spfile 的變化情況: SQL> ALTER tablespace undotbs1 RENAME TO undotbs;
Tablespace altered. SQL> SQL> show parameter pfile NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ spfile string /u01/app/oracle/product/10.1.0 /db_1/dbs/spfileTEST.ora SQL> show parameters undo NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ undo_management string AUTO undo_retention integer 900 undo_tablespace string UNDOTBS1 SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 180355072 bytes Fixed Size 777996 bytes Variable Size 128983284 bytes Database Buffers 50331648 bytes Redo Buffers 262144 bytes Database mounted. Database opened. SQL> show parameters undo NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ undo_management string AUTO undo_retention integer 900 undo_tablespace string UNDOTBS SQL> 對(duì)脫機(jī)表空間的更名是不允許的: SQL> ALTER TABLESPACE TEST OFFLINE; Tablespace altered. SQL> ALTER TABLESPACE test RENAME TO testoffline; ALTER TABLESPACE test RENAME TO testoffline * ERROR at line 1: ORA-01135: file 6 accessed for DML/query is offline ORA-01110: data file 6: '/u01/app/oracle/product/10.1.0/db_1/oradata/TEST/foo1.dbf' 給出的提示信息很有參考價(jià)值:更名操作是要對(duì)表空間進(jìn)行 DML/query 操作的,表空間offline的話,則不可以。 那么如果表空間是只讀的會(huì)怎么樣呢? SQL> ALTER TABLESPACE TEST ONLINE;
Tablespace altered. SQL> ALTER TABLESPACE TEST READ ONLY; Tablespace altered. SQL> ALTER TABLESPACE test RENAME TO testreadonly; Tablespace altered. SQL> list 1* SELECT file_name, tablespace_name FROM dba_data_files SQL> / FILE_NAME TABLESPACE ---------------------------------------------------------------------- ---------- /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/users01.dbf USERS /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/sysaux01.dbf SYSAUX /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/undotbs01.dbf UNDOTBS /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/system01.dbf SYSTEM /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/example01.dbf EXAMPLE /u01/app/oracle/product/10.1.0/db_1/oradata/TEST/foo1.dbf TESTREADONLY 6 rows selected. 看來(lái)數(shù)據(jù)字典已經(jīng)更新,不過(guò)Oracle會(huì)向alert_SID.log 中寫(xiě)入類(lèi)似如下的日志: ALTER TABLESPACE test RENAME TO testreadonly
Sat Nov 13 16:15:21 2004 Tablespace 'TEST' is renamed to 'TESTREADONLY'. Tablespace name change is not propagated to file headersbecause the tablespace is read only. Completed: ALTER TABLESPACE test RENAME TO testreadonly 注意Log里有個(gè)細(xì)微的小Bug:headersbecause。這是兩個(gè)詞,應(yīng)該空開(kāi)的 :-) 更名對(duì) Bigfile 表空間一樣有效。 限制條件 應(yīng)用這個(gè)特性有個(gè)主要的限制條件:COMPATIBLE 初始化參數(shù)要求為 10.0 或者更高才可以 參考信息 Oracle Database Administrator's Guide 10g Release 1 (10.1) Part Number B10739-01 ( Note 62294.1 ) |
|