【RAC】Creating a filesystem physical standby from ASM (RAC ) primary之一

楊奇龍發表於2011-09-09
環境:
版本  11.2.0.1 
1   primary : 
    name: rac 
    ip: 10.250.7.226
    scan ip:10.250.7.200
    使用ASM儲存資料
 2  standby :
    name : yangdb
    ip :10.250.7.241
   使用filesystem 儲存資料
在11gr2 版本中,oracle 提供了duplicate from active database 的功能,也就是可以不用備份源資料庫,就可以直接建立standby 或者複製源庫!相對於單例項使用duplicate建立物理備庫,在建立RAC的standby時 遇到很多錯誤!
比較多的是:
ORA-17629: Cannot connect to the remote database server
ORA-17627: ORA-12154: TNS:could not resolve the connect identifier specified
ORA-17629: Cannot connect to the remote database server
安裝完成後遇到:
ORA-00313: open failed for members of log group 3 of thread 2
ORA-00312: online log 3 thread 2: '/opt/oracle/oradata/yangdb/group_3.259.761070477'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
這裡先給出整個安裝的步驟:
1 在目標庫上安裝oracle 資料庫軟體,僅僅安裝軟體不建立資料庫。將rac 節點的密碼檔案複製到目標庫,並命重新命名為orapw,保持主庫和備庫的密碼一致

2 建立資料庫的對應檔案目錄:oracle 對應的跟蹤檔案目錄,資料檔案存放的目錄,閃回恢復區,歸檔目錄
audit_file_dest='/opt/oracle/admin/yangdb/adump'
diagnostic_dest='/opt/oracle'
db_create_file_dest='/opt/oracle/oradata/yangdb'
db_recovery_file_dest='/opt/oracle/flash_recovery_area'
log_archive_dest_1='LOCATION=/opt/oracle/arch'
否則,在重啟stanby庫的時候會報錯說沒有對應檔案或目錄!

3 配置主庫和備庫的tnsnames.ora檔案
# tnsnames.ora Network Configuration File: /opt/oracle/11.2.0/yangdb/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
yangdb =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.250.7.241)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = yangdb)
    )
  )
rac =
  (DESCRIPTION =
    (ADDRESS_LIST =
    #  (ADDRESS = (PROTOCOL = TCP)(HOST = 10.250.7.226)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.250.7.200)(PORT = 1521))
      
    )
    (CONNECT_DATA =
      (SERVICE_NAME = rac)
    )
  )

在主庫中新增備庫的tns連線
#scan 對應的IP為:10.250.7.200
RAC =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = scan)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rac)
    )
  )
yangdb =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.250.7.241)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = yangdb)
    )
  )

主庫和備庫配置好以後,要使用tnsping 命令檢視是否能夠ping通(在我的實踐中,tnsping能透過,但是卻報錯ORA-17629: Cannot connect to the remote database server),最後重啟監聽!生產環境中可以使用lsnrctl 的reload命令。
我在搭建的過程中,實際在oracle的TNS_HOME/admin 下的tnsnams.ora 和grid 的NET_HOME/admin 下的tnsnames.ora 分別都新增了備庫的tns 連線!!

4 建立備庫的引數檔案,非常簡單隻需要一個db_name引數就可以了
oracle@rac3:/opt/oracle/11.2.0/yangdb/dbs>cat inityangdb.ora 
*.db_name=rac
使用duplicate方式建立備庫或者複製資料庫的時候,oracle會自動從源庫中複製spfile到目標庫,其中需要修改的引數則透過指定的spfile引數下使用set 命令重新命名!

5 修改主庫引數檔案:
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(rac,yangdb)' scope=both sid='*';
alter system set log_archive_dest_2='SERVICE=yangdb  ARCH SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=yangdb' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE; 

記得一定要both,自己當時在主庫沒有設定 
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(rac,yangdb)' scope=both sid='*'; 
結果提示:
ORA-16057: server not in Data Guard configuration
PING[ARC2]: Heartbeat failed to connect to standby 'yangdb'. Error is 16057.

6 啟動備庫到nomount狀態 

oracle@rac3:/opt/oracle/11.2.0/yangdb/dbs>sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production on Thu Sep 8 15:12:36 2011
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup nomount pfile='/opt/oracle/11.2.0/yangdb/dbs/inityangdb.ora';
ORACLE instance started.
Total System Global Area  217157632 bytes
Fixed Size                  2211928 bytes
Variable Size             159387560 bytes
Database Buffers           50331648 bytes
Redo Buffers                5226496 bytes
SQL> 
SQL> 
SQL> exit
記得:一定要退出!!否則rman 會hang在執行一個指令碼的地方!

7 在主庫或者備庫執行如下命令:
rman>rman  target sys/yang402@rac  auxiliary sys/yang402@yangdb
rman>run {
   allocate channel c1 type disk connect 'sys/yang402@rac';
   allocate channel c2 type disk connect 'sys/yang402@rac';
   allocate auxiliary channel s1 type disk ;
   allocate auxiliary channel s2 type disk ;
   sql channel c1 "alter system archive log current";
   duplicate target database for standby from active database
         spfile
         set db_name='rac' 
         set db_unique_name='yangdb'
         set cluster_database='FALSE'
         set audit_file_dest='/opt/oracle/admin/yangdb/adump'
         set DIAGNOSTIC_DEST='/opt/oracle'
         set db_create_file_dest='/opt/oracle/oradata/yangdb'
         set db_recovery_file_dest='/opt/oracle/flash_recovery_area'
         set control_files='/opt/oracle/oradata/yangdb/control01.ctl','/opt/oracle/oradata/yangdb/control02.ctl','/opt/oracle/oradata/yangdb/control03.ctl'
         set undo_tablespace='UNDOTBS1'
         set service_names='yangdb'
         set standby_file_management='AUTO'
         set log_archive_config='DG_CONFIG=(rac,yangdb)'
         set log_archive_dest_1='LOCATION=/opt/oracle/arch'
         set log_archive_dest_2='service=rac ARCH ASYNC valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=rac'
         set log_archive_dest_state_1='enable'
         set log_archive_dest_state_2='enable'
         set log_archive_format='yangdb%t_%s_%r.log'
         set remote_login_passwordfile='exclusive'
         set LOG_FILE_NAME_CONVERT='+DATA1/rac/onlinelog','/opt/oracle/oradata/yangdb','+DATA2/rac/onlinelog','/opt/oracle/oradata/yangdb'
         set DB_FILE_NAME_CONVERT='+DATA1/rac/datafile','/opt/oracle/oradata/yangdb'
         set remote_listener=''
         set fal_client='yangdb'
         set fal_server='rac' 
         NOFILENAMECHECK;
    sql channel c1 "alter system archive log current";
 }
這裡需要說明的地方是:
由於duplicate 會從源庫的spfile複製新的備庫的引數檔案,源庫的引數檔案中的引數設定很可能不符合備庫的設定,比如:第一次新建立的spfile檔案內容     
oracle@rac3:/home/oracle>cat /tmp/init.ora
rac1.__db_cache_size=553648128
rac2.__db_cache_size=570425344
rac1.__java_pool_size=16777216
rac2.__java_pool_size=16777216
rac1.__large_pool_size=16777216
rac2.__large_pool_size=16777216
rac1.__oracle_base='/opt/rac/grid'#ORACLE_BASE set from environment
rac2.__oracle_base='/opt/rac/grid'#ORACLE_BASE set from environment
rac1.__pga_aggregate_target=671088640
rac2.__pga_aggregate_target=671088640
rac1.__sga_target=989855744
rac2.__sga_target=989855744
rac1.__shared_io_pool_size=0
rac2.__shared_io_pool_size=0
rac1.__shared_pool_size=385875968
rac2.__shared_pool_size=369098752
rac1.__streams_pool_size=0
rac2.__streams_pool_size=0
*.audit_file_dest='/opt/rac/oracle/admin/rac/adump'
*.audit_trail='db'
*.cluster_database=TRUE ##不用,要設定為false
*.compatible='11.2.0.0.0'
*.control_files='+DATA1/rac/controlfile/current.260.761070189','+DATA2/rac/controlfile/current.256.761070191'#要修改
*.db_block_size=8192
*.db_create_file_dest='+DATA1' --對應的值也要修改!
*.db_domain=''
*.db_name='rac'
*.db_recovery_file_dest='+DATA2'
*.db_recovery_file_dest_size=4070572032
*.diagnostic_dest='/opt/rac/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=racXDB)'
rac1.instance_number=1
rac2.instance_number=2
*.log_archive_config='DG_CONFIG=(rac,yangdb)'
*.log_archive_dest_1='LOCATION=/opt/rac/oracle/arch'
*.log_archive_dest_2='SERVICE=yangdb  ARCH ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=yangdb'
*.log_archive_dest_state_2='ENABLE'
*.memory_target=1655701504
*.open_cursors=300
*.processes=150
*.remote_listener='scan:1521'  --這個引數,對於備庫是無用的
*.remote_login_passwordfile='exclusive'
rac2.thread=2
rac1.thread=1
rac2.undo_tablespace='UNDOTBS2'
rac1.undo_tablespace='UNDOTBS1'
oracle@rac3:/home/oracle>
所以要在duplicate同時修改一份和備庫相適應的引數。
測試:
主庫中:
SQL> alter tablespace example add datafile '+DATA1/rac/datafile/example02.dbf' size 500m;
Tablespace altered.
備庫的日誌:
Successfully added datafile 7 to media recovery
Datafile #7: '/opt/oracle/oradata/alifpre/YANGDB/datafile/o1_mf_example_76kp3yqn_.dbf'
Media Recovery Log /opt/oracle/arch/yangdb1_66_761070192.log
Thu Sep 08 23:00:40 2011
Media Recovery Waiting for thread 1 sequence 67

需要注意的是:本來的
DB_FILE_NAME_CONVERT='+DATA1/rac/datafile','/opt/oracle/oradata/yangdb'
到standby 庫應用歸檔日誌時檔案卻為:
/opt/oracle/oradata/yangdb/YANDDB/datafile/o1_mf_example_76kp3yqn_.dbf
不方便管理。

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

相關文章