使用RMAN duplicate 建立standby資料庫(RAC或單機)

tolywang發表於2010-01-04


Linux AS 5.3
Oracle 10.2.0.4 RAC , 2個節點
要做兩個節點的Standby RAC 或單機的Standby .


1. 在RAC節點1上建立一個/u01/backup目錄用於儲存primary db的rman備份集。
 

[oracle@chicago_host1 stage]$ rman target /
RMAN> BACKUP DEVICE TYPE DISK FORMAT '/u01/backup/%U' DATABASE PLUS ARCHIVELOG;
RMAN> BACKUP DEVICE TYPE DISK FORMAT '/u01/backup/%U' CURRENT CONTROLFILE FOR STANDBY;

 

2. 安裝Standby的RAC系統,包括cluster, db software, dbca建庫,取同樣的db名稱,
在 Standby RAC節點1 上將資料庫shutdown 然後置為
SQL> startup nomount

 

3. 在RAC Standby 節點1上建立 /u01/backup 同樣的目錄,複製primary db上的rman備份集到
Standby節點1的這個目錄。

 

4. 在Standby節點1上tnsnames.ora 中加入連線primary db節點1的別名比如orcl_pri .

 

5. 準備開始恢復RMAN備份集到Standby 節點1上。

 

在主庫上執行      SQL> alter system archive log current ;

檢查是否有將spfile 及 orapwd  同步到 standby上  。  


rac01sty$cd  backup/

rac01sty$ls
01l277gl_1_1  03l277i0_1_1  05l277jq_1_1  listener.ora
02l277h6_1_1  04l277i9_1_1  initORCL.ora  tnsnames.ora


rac01sty$rman target   auxiliary /

Recovery Manager: Release 10.2.0.4.0 - Production on Wed Dec 30 05:50:35 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

connected to target database: ORCL (DBID=1234616916)
connected to auxiliary database: ORCL (not mounted)

 

 

RMAN> duplicate target database for standby nofilenamecheck; 

 


Starting Duplicate Db at 30-DEC-09
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=149 instance=orcl1 devtype=DISK

contents of Memory Script.:
{
   restore clone standby controlfile;
   sql clone 'alter database mount standby database';
}
executing Memory Script

Starting restore at 30-DEC-09
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/backup/05l277jq_1_1
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/backup/05l277jq_1_1 tag=TAG20091230T143642
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output filename=/ocfs_data/orcl/control01.ctl
output filename=/ocfs_data/orcl/control02.ctl
output filename=/ocfs_data/orcl/control03.ctl
Finished restore at 30-DEC-09 

sql statement: alter database mount standby database
released channel: ORA_AUX_DISK_1

contents of Memory Script.:
{
   set newname for tempfile  1 to
 "/ocfs_data/orcl/temp01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to
 "/ocfs_data/orcl/system01.dbf";
   set newname for datafile  2 to
 "/ocfs_data/orcl/undotbs01.dbf";
   set newname for datafile  3 to
 "/ocfs_data/orcl/sysaux01.dbf";
   set newname for datafile  4 to
 "/ocfs_data/orcl/users01.dbf";
   set newname for datafile  5 to
 "/ocfs_data/orcl/undotbs02.dbf";
   restore
   check readonly
   clone database
   ;
}
executing Memory Script

executing command: SET NEWNAME

renamed temporary file 1 to /ocfs_data/orcl/temp01.dbf in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 30-DEC-09
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=149 instance=orcl1 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /ocfs_data/orcl/system01.dbf
restoring datafile 00002 to /ocfs_data/orcl/undotbs01.dbf
restoring datafile 00003 to /ocfs_data/orcl/sysaux01.dbf
restoring datafile 00004 to /ocfs_data/orcl/users01.dbf
restoring datafile 00005 to /ocfs_data/orcl/undotbs02.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backup/02l277h6_1_1
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/backup/02l277h6_1_1 tag=TAG20091230T143518
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 30-DEC-09

contents of Memory Script.:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy recid=6 stamp=706945969 filename=/ocfs_data/orcl/system01.dbf
datafile 2 switched to datafile copy
input datafile copy recid=7 stamp=706945969 filename=/ocfs_data/orcl/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=8 stamp=706945969 filename=/ocfs_data/orcl/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=9 stamp=706945969 filename=/ocfs_data/orcl/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=10 stamp=706945969 filename=/ocfs_data/orcl/undotbs02.dbf
Finished Duplicate Db at 30-DEC-09

 

如遇到無法找到備份集檔案,則可執行如下命令來設定:
RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK  FORMAT   '/ opt/oracle/stage /%U';
(一般在target備份時已經設定過一般是不需要了,只要確保路徑是一致的就OK) 

 

 

 


6. 我們可以在執行dupliate db 的standby 節點1上檢視到資料庫V$database的open_mode 是mounted standby狀態,  檢視
它的alert log 為: 


Wed Dec 30 05:52:19 2009
ARC0: Becoming the 'no FAL' ARCH
ARC0: Becoming the 'no SRL' ARCH
ARC0: Thread not mounted
ARC1 started with pid=25, OS id=10754
ARC1: Becoming the heartbeat ARCH
ARC1: Thread not mounted
Wed Dec 30 05:52:19 2009
Successful mount of redo thread 1, with mount id 1234721550
Wed Dec 30 05:52:19 2009
Physical Standby Database mounted.
Completed: alter database mount standby database
Wed Dec 30 05:52:24 2009
Full restore complete of datafile 4 /ocfs_data/orcl/users01.dbf.  Elapsed time: 0:00:00
  checkpoint is 728032
Full restore complete of datafile 2 /ocfs_data/orcl/undotbs01.dbf.  Elapsed time: 0:00:00
  checkpoint is 728032
  last deallocation scn is 722327
Full restore complete of datafile 5 /ocfs_data/orcl/undotbs02.dbf.  Elapsed time: 0:00:01
  checkpoint is 728032
  last deallocation scn is 668928
Wed Dec 30 05:52:38 2009
Full restore complete of datafile 3 /ocfs_data/orcl/sysaux01.dbf.  Elapsed time: 0:00:14
  checkpoint is 728032
  last deallocation scn is 472064
Full restore complete of datafile 1 /ocfs_data/orcl/system01.dbf.  Elapsed time: 0:00:19
  checkpoint is 728032
  last deallocation scn is 475626
Wed Dec 30 05:52:49 2009
Switch of datafile 1 complete to datafile copy
  checkpoint is 728032
Switch of datafile 2 complete to datafile copy
  checkpoint is 728032
Switch of datafile 3 complete to datafile copy
  checkpoint is 728032
Switch of datafile 4 complete to datafile copy
  checkpoint is 728032
Switch of datafile 5 complete to datafile copy
  checkpoint is 728032
                        

 

7.  ok, 現在已經在RAC Standby 節點1上實現了physical standby, 可以類似單機standby一樣操作 。


SQL> alter database open read only;

Database altered.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.

Total System Global Area  339738624 bytes
Fixed Size                  1267380 bytes
Variable Size             109054284 bytes
Database Buffers          226492416 bytes
Redo Buffers                2924544 bytes

SQL> alter database mount standby database;

Database altered.

SQL>

 

 

8.  如果需要啟用, 可能需要修改一些spfile中的引數,加入或修改 redo, undo 等 。
 

 

9.    當RAC Standby重啟後,crs預設會自動將database開啟成open read only模式,這時如果下recover命令會
報錯無法close database,因此,對於物理standby來說,最好使用以下命令將crs開啟設定為自動開啟為mount狀態:

Srvctl modify database -d orcl -r PHYSICAL_STANDBY-s mount 

 

10.    啟用Physical Standby . 
注意: 啟用physical standby之前, 需要關閉兩個standby RAC例項, 然後在rac1上啟用資料庫並開啟 。

SQL> startup nomount 
SQL> alter database mount standby database;  
SQL> alter database activate standby database;
SQL> alter database mount;
SQL> alter database open ; 
SQL> shutdown immediate ;
SQL> startup 

確認spfile沒有問題後,在第二個Standby RAC節點 SQL> startup 

同樣, 如果沒有使用Data Guard broker,CRS就無法知道primary和standby的角色轉換,可能就需要手工
修改OCR的狀態資訊。 命令如下:

$ srvctl modify database -d wmb2bprd -r PRIMARY -s open 
(standby節點1執行即可, RAC以後開啟都會自動open) 

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

相關文章