1. 程式人生 > >Oracle 11g R2資料庫檔案遷移案例

Oracle 11g R2資料庫檔案遷移案例

資料庫檔案存放在儲存上,當需要更換新儲存時,就需要變更新的儲存路徑,遷移原有的資料檔案,本文件介紹兩種資料檔案遷移的方法。省略輸出結果。

一、RMAN遷移資料檔案 步驟:

1.修改引數檔案中控制檔案的存放位置

SQL>alter system set control_files='/newdirect/control01.ctl' scope=spfile

2.備份控制檔案

RMAN>backup current controlfile format '/任意的備份路徑/control01.ctl'

3.關閉資料庫並啟動到nomount狀態,恢復按“步驟1”中新設定的控制檔案位置恢復控制檔案

RMAN>restore controlfile from '/任意的備份路徑/control01.ctl'

4.備份現有的資料庫檔案原儲存位置至新儲存路徑間進行轉換

RMAN>backup as copy db_file_name_convent('/新的儲存路徑','/舊儲存路徑')  tablespace system, users,sysaux, undotbs01; 

RMAN>switch database to copy;

RMAN>recover database;

RMAN>alter database open resetlogs; 

5.新建線上重做日誌檔案

SQL>alter database add logfile thread 1 group 4 ('/新儲存路徑/redo04.log') size 1024m;

6.刪除舊的線上重做日誌檔案,刪除前一定要確認日誌組為inactive狀態

SQL>alter database drop logfile group 1;

7.新建臨時表空間,刪除舊的臨時表空間

SQL>alter tablespace temp add tempfile '/新儲存路徑/temp01.dbf' size 1G;

SQL>alter tablespace temp drop tempfile '/舊儲存路徑下的/temp01.dbf';

二、通過拷貝資料檔案再rename的方式遷移資料檔案

1.修引數檔案中控制檔案儲存位置

SQL>alter system set control_files='/新儲存位置/ocntrol01.ctl' scope=spfile;

2.一致性關閉資料庫,拷貝資料檔案和控制檔案至新的儲存位置

3.開啟資料庫起資料,分別重新命名system,sysaux,undo,users,線上重做日誌檔案的表空間對應資料檔案的名字

SQL>alter database rename file '舊檔案位置' to '新檔案位置'

4.新建新的臨時表空間,刪除舊的臨時表空間

SQL>alter tablespace temp add tempfile '/新路徑下的/temp01.dbf' size 1G;

SQL>alter teblespace temp  drop tempfile  '/舊路徑下的/temp01.dbf';