資料檔案的遷移

super_sky發表於2014-03-07

現有資料檔案
SYS@testdb>select file#,name from v$datafile;

     FILE# NAME
---------- --------------------------------------------------
         1 /oracle/ora10g/oradata/system01.dbf
         2 /oracle/ora10g/oradata/undotbs01.dbf
         3 /oracle/ora10g/oradata/sysaux01.dbf
         4 /oracle/ora10g/oradata/users01.dbf
         5 /oracle/ora10g/oradata/leo1_01.dbf
         6 /oracle/ora10g/oradata/mssm01.dbf
         7 /oracle/ora10g/oradata/assm01.dbf
         8 /oracle/ora10g/oradata/users02.dbf
         9 /oracle/ora10g/product/10.2.0/db_1/dbs/oracleora10
           goradatatest01.dbf

     FILE# NAME
---------- --------------------------------------------------
        10 /oracle/ora10g/product/10.2.0/db_1/dbs/wangche.bdf
        11 /ora_data/wangche1.bdf

計劃將資料檔案遷移到/ora_data/10g_data,下面我們將使用rman copy 命令來完成這個測試實驗。

tempapp@ora10g[#/ora_data/10g_data]rman target /
RMAN> startup mount;

RMAN> copy datafile 1 to '/ora_data/10g_data/system01.dbf';
RMAN> copy datafile 2 to '/ora_data/10g_data/undotbs01.dbf';
RMAN> copy datafile 3 to '/ora_data/10g_data/sysaux01.dbf';
RMAN> copy datafile 4 to '/ora_data/10g_data/users01.dbf';
RMAN> copy datafile 5 to '/ora_data/10g_data/leo1_01.dbf';
RMAN> copy datafile 6 to '/ora_data/10g_data/mssm01.dbf';
RMAN> copy datafile 7 to '/ora_data/10g_data/assm01.dbf' ;
RMAN> copy datafile 8 to '/ora_data/10g_data/users02.dbf';
RMAN> copy datafile 9 to '/ora_data/10g_data/aaa9.dbf';
RMAN> copy datafile 10 to '/ora_data/10g_data/wangche.bdf';
RMAN> copy datafile 11 to '/ora_data/10g_data/wangche1.bdf';

run{
set newname for datafile 1 to '/ora_data/10g_data/system01.dbf';
set newname for datafile 2 to '/ora_data/10g_data/undotbs01.dbf';
set newname for datafile 3 to '/ora_data/10g_data/sysaux01.dbf';
set newname for datafile 4 to '/ora_data/10g_data/users01.dbf';
set newname for datafile 5 to '/ora_data/10g_data/leo1_01.dbf';
set newname for datafile 6 to '/ora_data/10g_data/mssm01.dbf';
set newname for datafile 7 to '/ora_data/10g_data/assm01.dbf' ;
set newname for datafile 8 to '/ora_data/10g_data/users02.dbf';
set newname for datafile 9 to '/ora_data/10g_data/aaa9.dbf';
set newname for datafile 10 to '/ora_data/10g_data/wangche.bdf';
set newname for datafile 11 to '/ora_data/10g_data/wangche1.bdf';
switch datafile all;
}

RMAN> alter database open;

檢查資料檔案
SYS@testdb>select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME                FILE_NAME
------------------------------ --------------------------------------------------
SYSTEM                         /ora_data/10g_data/system01.dbf
UNDOTBS                        /ora_data/10g_data/undotbs01.dbf
SYSAUX                         /ora_data/10g_data/sysaux01.dbf
USERS                          /ora_data/10g_data/users01.dbf
LEO1                           /ora_data/10g_data/leo1_01.dbf
MSSM                           /ora_data/10g_data/mssm01.dbf
ASSM                           /ora_data/10g_data/assm01.dbf
SYSTEM                         /ora_data/10g_data/users02.dbf
TEST                           /ora_data/10g_data/aaa9.dbf
WANGCHE                        /ora_data/10g_data/wangche.bdf
WANGCHE1                       /ora_data/10g_data/wangche1.bdf

11 rows selected.

檢查沒有問題後,刪除原來的資料檔案
rm -f /oracle/ora10g/oradata/system01.dbf
rm -f /oracle/ora10g/oradata/undotbs01.dbf
rm -f /oracle/ora10g/oradata/sysaux01.dbf
rm -f /oracle/ora10g/oradata/users01.dbf
rm -f /oracle/ora10g/oradata/leo1_01.dbf
rm -f /oracle/ora10g/oradata/mssm01.dbf
rm -f /oracle/ora10g/oradata/assm01.dbf
rm -f /oracle/ora10g/oradata/users02.dbf
rm -f /oracle/ora10g/product/10.2.0/db_1/dbs/oracleora10goradatatest01.dbf
rm -f /oracle/ora10g/product/10.2.0/db_1/dbs/wangche.bdf
rm -f /ora_data/wangche1.bdf

下面使用alter database rename file 命令來修改資料檔名稱
SYS@testdb>select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME                FILE_NAME
------------------------------ --------------------------------------------------
SYSTEM                         /ora_data/10g_data/system01.dbf
UNDOTBS                        /ora_data/10g_data/undotbs01.dbf
SYSAUX                         /ora_data/10g_data/sysaux01.dbf
USERS                          /ora_data/10g_data/users01.dbf
LEO1                           /ora_data/10g_data/leo1_01.dbf
MSSM                           /ora_data/10g_data/mssm01.dbf
ASSM                           /ora_data/10g_data/assm01.dbf
SYSTEM                         /ora_data/10g_data/users02.dbf
TEST                           /ora_data/10g_data/aaa9.dbf
WANGCHE                        /ora_data/10g_data/wangche.bdf
WANGCHE1                       /ora_data/10g_data/wangche1.bdf

11 rows selected.

計劃將 /ora_data/10g_data/users02.dbf 修改為 /ora_data/10g_data/system02.dbf
計劃將 /ora_data/10g_data/aaa9.dbf 修改為 /ora_data/10g_data/test01.dbf

SYS@testdb>shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

將資料檔案使用作業系統命令重新命名。這裡需要注意,我這個是測試系統,正式系統建議使用cp命令
tempapp@ora10g[#/ora_data/10g_data]mv users02.dbf system02.dbf
tempapp@ora10g[#/ora_data/10g_data]mv aaa9.dbf test01.dbf
將資料庫啟動到mount狀態
SYS@testdb>startup mount;
SYS@testdb>alter database rename file '/ora_data/10g_data/users02.dbf' to '/ora_data/10g_data/system02.dbf';
SYS@testdb>alter database rename file '/ora_data/10g_data/aaa9.dbf' to '/ora_data/10g_data/test01.dbf';

啟動資料庫
SYS@testdb>alter database open;
檢查資料檔案遷移情況
SYS@testdb>select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME                FILE_NAME
------------------------------ --------------------------------------------------
SYSTEM                         /ora_data/10g_data/system01.dbf
UNDOTBS                        /ora_data/10g_data/undotbs01.dbf
SYSAUX                         /ora_data/10g_data/sysaux01.dbf
USERS                          /ora_data/10g_data/users01.dbf
LEO1                           /ora_data/10g_data/leo1_01.dbf
MSSM                           /ora_data/10g_data/mssm01.dbf
ASSM                           /ora_data/10g_data/assm01.dbf
SYSTEM                         /ora_data/10g_data/system02.dbf
TEST                           /ora_data/10g_data/test01.dbf
WANGCHE                        /ora_data/10g_data/wangche.bdf
WANGCHE1                       /ora_data/10g_data/wangche1.bdf

11 rows selected.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11590946/viewspace-1102877/,如需轉載,請註明出處,否則將追究法律責任。

相關文章