標籤:
實驗目的:將oracle資料庫從一台機器遷移到另外的一台機器(同為linux平台),設定為不同的路徑,不同的執行個體名
源端:
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
ORACLE_SID=test
資料檔案位置:/oradata/test
目標端:
ORACLE_BASE=/u02/app/oracle
ORACLE_HOME=/u02/app/oracle/product/10.2.0/db_1
ORALCE_SID=test2
資料檔案位置:/oradata2/test2
註:兩台主機非一台,但是主機名稱一致均為model.rhel5
第一步:在源端取得備份資料
查詢一下MAI使用者下的資料,做最後校正使用
[email protected] > select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BONUS TABLE
DEPT TABLE
EMP TABLE
SALGRADE TABLE
TEST TABLE
TEST01 TABLE
開始備份:
$ [email protected] /mnt/hgfs/software/backup> rmantarget /
RMAN> run{
2> allocate channel c1 device type disk format‘/mnt/hgfs/software/backup/%T_%U‘;
3> backup database;
4> backup current controlfile format‘/mnt/hgfs/software/backup/%T_CTL_%U‘;
5> backup spfile format‘/mnt/hgfs/software/backup/%T_SPFILE_%U‘;
6> release channel c1;
7> }
備份組資訊:
$ [email protected] /mnt/hgfs/software/backup> ls-lh
total 304M
-rwxrwxrwx 1 root root 594M Aug 29 20:3120120829_02njsrtb_1_1*
-rwxrwxrwx 1 root root 6.9M Aug 29 20:3120120829_03njss0b_1_1*
-rwxrwxrwx 1 root root 6.8M Aug 29 20:3120120829_CTL_04njss0k_1_1*
-rwxrwxrwx 1 root root 96K Aug 29 20:3120120829_SPFILE_05njss0m_1_1*
第二步:備端的準備
1、安裝資料庫軟體,基礎位置參考上文說明。
2、建立相關的目錄:
$ [email protected] ~> env | grep ORACLE
ORACLE_BASE=/u02/app/oracle
ORACLE_HOME=/u02/app/oracle/product/10.2.0/db_1
$ [email protected] ~> cd $ORACLE_BASE
$ [email protected] /u02/app/oracle> mkdirflash_recovery_area
$ [email protected] /u02/app/oracle> mkdir -padmin/test2
$ [email protected] /u02/app/oracle> cd admin/test2
$ [email protected] /u02/app/oracle/admin/test2> mkdir{a,b,c,d,u}dump
第三步:開始恢複,此時恢複的執行個體名為test
$ [email protected] ~> export ORACLE_SID=test
$ [email protected] ~> rman target /
RMAN> startup nomount
1、恢複spfile:
RMAN> restore spfile from‘/mnt/hgfs/software/backup/20120829_SPFILE_05njss0m_1_1‘;
RMAN> shutdown immediate;
2、編輯參數檔案,使參數中的相關路徑變更為新路徑
$ [email protected] ~> sqlplus / as sysdba
[email protected] > create pfile from spfile;
編輯產生的$ORACLE_HOME/dbs/inittest.ora檔案,將檔案中的路徑改為新的路徑,即:
/oradata/test/修改為/oradata2/test2/
/u01/app/oracle/修改為/u02/app/oracle
/u01/app/oracle/admin/test修改為/u02/app/oracle/admin/test2
$ [email protected] ~> sqlplus / as sysdba
[email protected] > create spfile from pfile;
3、恢複控制檔案:
$ [email protected] ~> rman target /
RMAN> startup nomount
RMAN> restore controlfile from‘/mnt/hgfs/software/backup/20120829_CTL_04njss0k_1_1‘;
4、恢複資料檔案:
RMAN> alter database mount;
RMAN> run {
2> set newname for datafile 1 to‘/oradata2/test2/system01.dbf‘;
3> set newname for datafile 2 to‘/oradata2/test2/undotbs01.dbf‘;
4> set newname for datafile 3 to‘/oradata2/test2/sysaux01.dbf‘;
5> set newname for datafile 4 to‘/oradata2/test2/users01.dbf‘;
6> set newname for datafile 5 to‘/oradata2/test2/example01.dbf‘;
7> restore database;
8> }
5、重建控制檔案,更新控制檔案中的資料檔案路徑
$ [email protected] ~> sqlplus / as sysdba
[email protected] > alter database backup controlfile totrace;
到$ORACLE_BASE/admin/udump中找到剛才產生的TRACE檔案,複製出其中的建立檔案集的片段,修改其中的路徑資訊為新的路徑資訊,備用
[email protected] > shutdown immediate;
[email protected] > startup nomount
利用剛才修改過的控制檔案建立指令碼重建控制檔案:
[email protected] > CREATE CONTROLFILE REUSE DATABASE "TEST"RESETLOGS ARCHIVELOG
2 MAXLOGFILES 16
3 MAXLOGMEMBERS 3
4 MAXDATAFILES 100
5 MAXINSTANCES 8
6 MAXLOGHISTORY 292
7 LOGFILE
8 GROUP 1‘/oradata2/test2/redo01.log‘ SIZE 50M,
9 GROUP 2‘/oradata2/test2/redo02.log‘ SIZE 50M,
10 GROUP 3 ‘/oradata2/test2/redo03.log‘ SIZE50M
11 -- STANDBY LOGFILE
12 DATAFILE
13 ‘/oradata2/test2/system01.dbf‘,
14 ‘/oradata2/test2/undotbs01.dbf‘,
15 ‘/oradata2/test2/sysaux01.dbf‘,
16 ‘/oradata2/test2/users01.dbf‘,
17 ‘/oradata2/test2/example01.dbf‘
18 CHARACTER SET ZHS16GBK
19 ;
[email protected] > alter database open resetlogs;
至此,資料庫已經能夠正常啟動了,但是此時的執行個體名以及資料庫名均為test,需要將其更改為test2,繼續向下走
第四部分:修改執行個體名,以及資料庫名
相關內容可以參見先前的文章:ORACLE資料庫執行個體的重新命名( http://blog.sina.com.cn/s/blog_67be3b4501016dgu.html)
[email protected] > shutdown immediate;
[email protected] > startup mount
修改資料檔案、控制檔案中的資料庫名稱,修改之後會關閉資料庫
[email protected] > !nid target=sys/oracle dbname=test2logfile=/tmp/change_name2test2.log
啟動資料庫,這個時候會報資料庫名稱不一致的錯誤,不去管他(ORA-01103: database name ‘MAI‘ incontrol file is not ‘TEST‘)
[email protected] > startup mount
將資料庫名更新到spfile檔案中
[email protected] > alter system set db_name=‘test2‘scope=spfile;
[email protected] > create pfile from spfile;
[email protected] > shutdown immediate;
$ [email protected] ~> export ORACLE_SID=test2
$ [email protected] ~> sqlplus / as sysdba
[email protected] > startuppfile=‘/u02/app/oracle/product/10.2.0/db_1/dbs/inittest.ora‘
[email protected] > create spfile frompfile=‘/u02/app/oracle/product/10.2.0/db_1/dbs/inittest.ora‘;
[email protected] > shutdown immediate;
[email protected] > startup mount;
[email protected] > create pfile from spfile;
[email protected] > alter database open resetlogs;
將ORACLE_SID=test2寫入到oracle使用者的.bash_profile檔案中:
$ [email protected] ~> echo export ORACLE_SID=test2>> .bash_profile
至此呢,資料庫遷移才算是徹底的完成了。
第五部分:最後的校正
1、MAI使用者驗證:
[email protected] > select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BONUS TABLE
DEPT TABLE
EMP TABLE
SALGRADE TABLE
TEST TABLE
TEST01 TABLE
2、資料庫名驗證:
[email protected] > select name,open_mode fromv$database;
NAME OPEN_MODE
--------- ----------
TEST2 READ WRITE
3、執行個體名驗證:
[email protected] > select instance_name,status fromv$instance;
INSTANCE_NAME STATUS
---------------- ------------
test2 OPEN
4、進程驗證:
$ [email protected] ~> ps aux | grep ora_ | grep -vgrep
oracle 25592 0.0 1.2 261864 12756? Ss 00:23 0:00 ora_pmon_test2
oracle 25594 0.0 1.0 261252 11104? Ss 00:23 0:00 ora_psp0_test2
oracle 25596 0.0 1.3 261252 13848? Ss 00:23 0:00 ora_mman_test2
oracle 25598 0.0 1.3 263320 13708? Ss 00:23 0:00 ora_dbw0_test2
oracle 25600 0.0 2.9 276804 30644? Ss 00:23 0:00 ora_lgwr_test2
oracle 25602 0.0 1.6 261236 16956? Ss 00:23 0:00 ora_ckpt_test2
oracle 25604 0.0 3.4 261784 35812? Ss 00:23 0:00 ora_smon_test2
oracle 25606 0.0 1.6 261252 17224? Ss 00:23 0:00 ora_reco_test2
oracle 25608 0.0 2.2 262812 22948? Ss 00:23 0:00 ora_cjq0_test2
oracle 25610 0.1 4.2 262988 43768? Ss 00:23 0:00 ora_mmon_test2
oracle 25612 0.0 1.2 261252 12832? Ss 00:23 0:00 ora_mmnl_test2
oracle 25614 0.0 1.0 261248 10672? Ss 00:23 0:00 ora_d000_test2
oracle 25616 0.0 1.0 261248 10656? Ss 00:23 0:00 ora_d001_test2
oracle 25626 0.0 2.6 276804 27168? Ss 00:24 0:00 ora_arc0_test2
oracle 25628 0.0 2.6 276804 27040? Ss 00:24 0:00 ora_arc1_test2
oracle 25630 0.0 2.6 276804 26920? Ss 00:24 0:00 ora_arc2_test2
oracle 25632 0.0 1.5 261252 15660? Ss 00:24 0:00 ora_qmnc_test2
oracle 25638 0.0 1.1 261248 11656? Ss 00:24 0:00 ora_q000_test2
oracle 25640 0.0 1.3 261248 13912? Ss 00:24 0:00 ora_q001_test2
5、oracle使用者的變數驗證:
$ [email protected] ~> env | grep ORACLE
ORACLE_SID=test2
ORACLE_BASE=/u02/app/oracle
ORACLE_HOME=/u02/app/oracle/product/10.2.0/db_1
驗證完成,驗證的結果表明,遷移確實已經成功,並且已經達到了預期的目的。
Linux平台下使用rman進行oracle資料庫遷移