模擬生產搭建Standby RAC實驗環境(11.2.0.4 DG)

模擬生產搭建Standby RAC實驗環境(11.2.0.4 DG)css

環境:RHEL 6.5 + Oracle 11.2.0.4 GI、DBhtml

1.需求背景介紹

目前,我有一套正常運行的Oracle 11.2.0.4 RAC實驗環境。這是一套VirtualBox的虛擬化環境,整套環境均放在個人臺式機服務器的D盤(SSD固態盤)。也就是說,這套RAC環境的系統磁盤和共享磁盤均在本地D盤。java

目前出於容災的考慮,計劃在個人NAS環境中構造一套DG災備環境,這裏規劃也是一個2節點的Standby RAC.
也就是說,災備環境的這套RAC,系統磁盤和共享磁盤都在NAS環境中,我這裏的NAS映射到臺式機的Z盤。node

整個模擬災備的實驗中,作到了硬件級別的分離,這也就更加真實的模擬了生產中的災備環境。sql

如今咱們來看下現有環境的基本信息:
Primary RAC主要信息以下:數據庫

#public ip
192.168.1.50  jyrac1
192.168.1.52  jyrac2
#virtual ip
192.168.1.51  jyrac1-vip
192.168.1.53  jyrac2-vip
#scan ip
192.168.1.60  jyrac-scan

#private ip
10.10.10.50    jyrac1-priv
10.10.10.52    jyrac2-priv

Primary RAC集羣各資源以下:服務器

[grid@jyrac1 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATA1.dg
               ONLINE  ONLINE       jyrac1                                       
               ONLINE  ONLINE       jyrac2                                       
ora.FRA1.dg
               ONLINE  ONLINE       jyrac1                                       
               ONLINE  ONLINE       jyrac2                                       
ora.LISTENER.lsnr
               ONLINE  ONLINE       jyrac1                                       
               ONLINE  ONLINE       jyrac2                                       
ora.OCR1.dg
               ONLINE  ONLINE       jyrac1                                       
               ONLINE  ONLINE       jyrac2                                       
ora.asm
               ONLINE  ONLINE       jyrac1                   Started             
               ONLINE  ONLINE       jyrac2                   Started             
ora.gsd
               OFFLINE OFFLINE      jyrac1                                       
               OFFLINE OFFLINE      jyrac2                                       
ora.net1.network
               ONLINE  ONLINE       jyrac1                                       
               ONLINE  ONLINE       jyrac2                                       
ora.ons
               ONLINE  ONLINE       jyrac1                                       
               ONLINE  ONLINE       jyrac2                                       
ora.registry.acfs
               ONLINE  ONLINE       jyrac1                                       
               ONLINE  ONLINE       jyrac2                                       
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       jyrac1                                       
ora.cvu
      1        ONLINE  ONLINE       jyrac1                                       
ora.jyrac1.vip
      1        ONLINE  ONLINE       jyrac1                                       
ora.jyrac2.vip
      1        ONLINE  ONLINE       jyrac2                                       
ora.jyzhao.db
      1        ONLINE  ONLINE       jyrac1                   Open                
      2        ONLINE  ONLINE       jyrac2                   Open                
ora.oc4j
      1        ONLINE  ONLINE       jyrac1                                       
ora.scan1.vip
      1        ONLINE  ONLINE       jyrac1

2.準備工做

目前須要在NAS環境中進行災備環境RAC的集羣軟件GI安裝配置和RAC數據庫軟件的安裝。
關於安裝部分這裏不在贅述,若是有問題能夠參考官檔或者我以前總結的Oracle 11g RAC的安裝部署相關章節。session

最終這套Oracle 11.2.0.4 Standby RAC實驗環境,主要信息以下:oracle

#public ip
192.168.1.61  jystdrac1
192.168.1.63  jystdrac2
#virtual ip
192.168.1.62  jystdrac1-vip
192.168.1.64  jystdrac2-vip
#scan ip
192.168.1.65  jystdrac-scan

#private ip
10.10.10.61    jystdrac1-priv
10.10.10.63    jystdrac2-priv

Standby RAC集羣各資源以下:app

[grid@jystdrac1 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATA.dg
               ONLINE  ONLINE       jystdrac1                                    
               ONLINE  ONLINE       jystdrac2                                    
ora.FRA.dg
               ONLINE  ONLINE       jystdrac1                                    
               ONLINE  ONLINE       jystdrac2                                    
ora.LISTENER.lsnr
               ONLINE  ONLINE       jystdrac1                                    
               ONLINE  ONLINE       jystdrac2                                    
ora.OCR.dg
               ONLINE  ONLINE       jystdrac1                                    
               ONLINE  ONLINE       jystdrac2                                    
ora.asm
               ONLINE  ONLINE       jystdrac1                Started             
               ONLINE  ONLINE       jystdrac2                Started             
ora.gsd
               OFFLINE OFFLINE      jystdrac1                                    
               OFFLINE OFFLINE      jystdrac2                                    
ora.net1.network
               ONLINE  ONLINE       jystdrac1                                    
               ONLINE  ONLINE       jystdrac2                                    
ora.ons
               ONLINE  ONLINE       jystdrac1                                    
               ONLINE  ONLINE       jystdrac2                                    
ora.registry.acfs
               ONLINE  ONLINE       jystdrac1                                    
               ONLINE  ONLINE       jystdrac2                                    
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       jystdrac1                                    
ora.cvu
      1        ONLINE  ONLINE       jystdrac1                                    
ora.jystdrac1.vip
      1        ONLINE  ONLINE       jystdrac1                                    
ora.jystdrac2.vip
      1        ONLINE  ONLINE       jystdrac2                                    
ora.oc4j
      1        ONLINE  ONLINE       jystdrac1                                    
ora.scan1.vip
      1        ONLINE  ONLINE       jystdrac1

能夠看到,Standby RAC集羣各資源除了還未創建的數據庫和實例資源,其餘一切正常,至此,準備工做結束。

3.主庫配置

以前在《Oracle 11g DG配置簡明版》文章中,已經簡明介紹過單實例11g DG的搭建過程。
這裏是RAC環境,其實基本思路同樣的,但我這裏實驗更真實模擬生產實施標準,細化描述下整個過程。

主庫配置操做主要有:

  • 數據庫歸檔模式
  • Force Logging
  • 主庫參數文件修改
  • 建立SRLs
  • 備份數據庫
  • 建立備庫參數文件
  • 更新tnsnames.ora文件

3.1 數據庫歸檔模式
我這裏主庫的RAC環境已是歸檔模式。
若是不是,這樣修改:

srvctl stop database -d jyzhao
sqlplus / as sysdba
startup mount
alter database archivelog;
alter database open;
srvctl start database -d jyzhao

3.2 Force Logging
這個步驟對於DG來講很是重要,且須要確認是在Force Logging以後備份數據庫,防止使用以前的備份出現缺失nologging操做的部分,形成數據庫的數據不一致。

alter database force logging;
select FORCE_LOGGING FROM V$DATABASE;

3.3 主庫參數文件修改
使用下面語句查詢如今DG相關參數的設置狀況:

set linesize 500
col value for a70
col name for a50
 
select name, value
from v$parameter
where name in ('db_name','db_unique_name','log_archive_config', 'log_archive_dest_1','log_archive_dest_2',
               'log_archive_dest_state_1','log_archive_dest_state_2', 'remote_login_passwordfile',
               'log_archive_format','log_archive_max_processes','fal_server','db_file_name_convert',
                     'log_file_name_convert', 'standby_file_management');

參數設定值:

DB_NAME=jyzhao
DB_UNIQUE_NAME=jyzhao
LOG_ARCHIVE_CONFIG='DG_CONFIG=(jyzhao,mynas)'
LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=jyzhao'
LOG_ARCHIVE_DEST_2='SERVICE=mynas ARCH VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=mynas'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=8
FAL_SERVER=mynas
DB_FILE_NAME_CONVERT='+data/mynas','+data1/jyzhao'
LOG_FILE_NAME_CONVERT='+data/mynas','+data1/jyzhao','+fra/mynas','+fra1/jyzhao'
STANDBY_FILE_MANAGEMENT=AUTO

注:對於db_unique_name,我這裏開始規劃的主備庫分別是pcssd和mynas。
pcssd:說明這個庫在個人PC機上的SSD存儲上。
mynas:說明這個庫在個人NAS存儲上。
最後,因爲考慮到生產環境通常要求對主庫環境影響最小,因此主庫的db_unique_name最終選擇不更改,仍是保留jyzhao。
此外,這裏LOG_ARCHIVE_DEST_2使用的是歸檔進程傳輸,後續能夠根據須要改爲LGWR傳輸,這樣主備庫的延遲能夠更低。

修改參數值:

--alter system set db_unique_name='jyzhao' scope=spfile;  
alter system set log_archive_config= 'DG_CONFIG=(jyzhao,mynas)';
alter system set log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=jyzhao';
alter system set log_archive_dest_2='SERVICE=mynas ARCH VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=mynas';
alter system set log_archive_dest_state_1=enable;
alter system set log_archive_dest_state_2=enable;
alter system set FAL_SERVER='mynas';
alter system set db_file_name_convert='+data/mynas','+data1/jyzhao' scope=spfile;
alter system set log_file_name_convert='+data/mynas','+data1/jyzhao','+fra/mynas','+fra1/jyzhao' scope=spfile;
alter system set standby_file_management=AUTO;

3.4 建立SRLs
確認當前v$log信息:

SYS@jyzhao1 >select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME   NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------ ------------ ------------
         1          1        121   52428800        512          2 YES INACTIVE               3784808 08-AUG-17         3822869 09-AUG-17
         2          1        122   52428800        512          2 NO  CURRENT                3822869 09-AUG-17      2.8147E+14
         3          2         97   52428800        512          2 YES INACTIVE               3822868 09-AUG-17         3841980 09-AUG-17
         4          2         98   52428800        512          2 NO  CURRENT                3841980 09-AUG-17      2.8147E+14

建立存放SRL的目錄並添加SRLs:

ASMCMD> mkdir +fra1/jyzhao/STANDBYLOG

--alter system set standby_file_management=manual scope=both sid='*';
 
alter database add standby logfile thread 1 group 11 '+fra1/jyzhao/standbylog/standby_group_11.log' size 52428800;
alter database add standby logfile thread 1 group 12 '+fra1/jyzhao/standbylog/standby_group_12.log' size 52428800;
alter database add standby logfile thread 1 group 13 '+fra1/jyzhao/standbylog/standby_group_13.log' size 52428800;
alter database add standby logfile thread 2 group 21 '+fra1/jyzhao/standbylog/standby_group_21.log' size 52428800;
alter database add standby logfile thread 2 group 22 '+fra1/jyzhao/standbylog/standby_group_22.log' size 52428800;
alter database add standby logfile thread 2 group 23 '+fra1/jyzhao/standbylog/standby_group_23.log' size 52428800;
 
--alter system set standby_file_management=auto scope=both sid='*';

添加完SRLs以後,能夠查詢到:

SYS@jyzhao1 >select * from v$standby_log;

    GROUP# DBID                                        THREAD#  SEQUENCE#      BYTES  BLOCKSIZE       USED ARC STATUS     FIRST_CHANGE# FIRST_TIME   NEXT_CHANGE# NEXT_TIME    LAST_CHANGE# LAST_TIME
---------- ---------------------------------------- ---------- ---------- ---------- ---------- ---------- --- ---------- ------------- ------------ ------------ ------------ ------------ ------------
        11 UNASSIGNED                                        1          0   52428800        512          0 YES UNASSIGNED
        12 UNASSIGNED                                        1          0   52428800        512          0 YES UNASSIGNED
        13 UNASSIGNED                                        1          0   52428800        512          0 YES UNASSIGNED
        21 UNASSIGNED                                        2          0   52428800        512          0 YES UNASSIGNED
        22 UNASSIGNED                                        2          0   52428800        512          0 YES UNASSIGNED
        23 UNASSIGNED                                        2          0   52428800        512          0 YES UNASSIGNED

6 rows selected.

3.5 備份數據庫

mkdir -p /public/hotback/jyzhao/standby
 
rman target / 
run
{
     allocate channel ch1 type disk;
     backup database format '/public/hotback/jyzhao/standby/dbbackup_for_stndby_%U';
     backup current controlfile for standby format '/public/hotback/jyzhao/standby/control_for_standby.ctl';
     release channel ch1;
}

3.6 建立備庫參數文件

create pfile='pfile_for_standby.txt' from spfile;

3.7 更新tnsnames.ora文件

JYZHAO =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.51)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.53)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jyzhao)
    )
  )

JYZHAO1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.51)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jyzhao)
      (SID = jyzhao1)
    )
  )

JYZHAO2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.53)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jyzhao)
      (SID = jyzhao2)
    )
  )

LISTENER_JYZHAO1=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = jyrac1-vip)(PORT = 1521)))
LISTENER_JYZHAO2=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = jyrac2-vip)(PORT = 1521)))

MYNAS =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.62)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.64)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = mynas)
    )
  )


MYNAS1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.62)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = mynas)
      (SID = jyzhao1)
    )
  )


MYNAS2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.64)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = mynas)
      (SID = jyzhao2)
    )
  )

4.備庫配置

備庫配置操做主要有:

  • 拷貝主庫RMAN備份和參數文件
  • 拷貝密碼文件
  • 建立備庫須要的目錄
  • 修改備庫參數文件
  • 拷貝tnsnames.ora文件
  • 建立ASM相關目錄

4.1 拷貝主庫RMAN備份和參數文件
我這裏備份所在的空間能夠直接nfs掛載到備庫,不須要拷貝。

4.2 拷貝密碼文件

scp $ORACLE_HOME/dbs/orapwjyzhao1 192.168.1.61:$ORACLE_HOME/dbs/orapwjyzhao1
scp $ORACLE_HOME/dbs/orapwjyzhao1 192.168.1.63:$ORACLE_HOME/dbs/orapwjyzhao2

4.3 建立備庫須要的目錄
On jystdrac1:

mkdir -p /opt/app/oracle/admin/mynas/adump
mkdir -p /opt/app/oracle/diag/rdbms/mynas/jyzhao1
cd /opt/app/oracle/diag/rdbms/mynas/jyzhao1
mkdir trace cdump

On jystdrac2:

mkdir -p /opt/app/oracle/admin/mynas/adump
mkdir -p /opt/app/oracle/diag/rdbms/mynas/jyzhao2
cd /opt/app/oracle/diag/rdbms/mynas/jyzhao2
mkdir trace cdump

4.4 修改備庫參數文件

*.audit_file_dest='/opt/app/oracle/admin/mynas/adump'
*.audit_trail='db'
*.cluster_database=true
*.compatible='11.2.0.4.0'
*.control_files='+DATA/mynas/controlfile/current.260.919999027','+FRA/mynas/controlfile/current.256.919999029'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_file_name_convert='+data1/jyzhao','+data/mynas'
*.db_name='jyzhao'
*.db_recovery_file_dest='+FRA'
*.db_recovery_file_dest_size=4621074432
*.db_unique_name='mynas'
*.diagnostic_dest='/opt/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=jyzhaoXDB)'
*.fal_server='jyzhao'
jyzhao2.instance_number=2
jyzhao1.instance_number=1
*.java_jit_enabled=TRUE
jyzhao1.local_listener='LISTENER_JYZHAO1'
jyzhao2.local_listener='LISTENER_JYZHAO2'
*.log_archive_config='DG_CONFIG=(jyzhao,mynas)'
*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=mynas'
*.log_archive_dest_2='SERVICE=jyzhao ARCH VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=jyzhao'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_file_name_convert='+data1/jyzhao','+data/mynas','+fra1/jyzhao','+fra/mynas'
*.memory_target=536870912
*.open_cursors=300
*.processes=150
*.remote_listener='jyrac-scan:1521'
*.remote_login_passwordfile='exclusive'
jyzhao2.thread=2
jyzhao1.thread=1
jyzhao2.undo_tablespace='UNDOTBS2'
jyzhao1.undo_tablespace='UNDOTBS1'

注意:我這裏的環境備庫和主庫的磁盤組名稱有區別,必定要仔細區分清楚,好比控制文件的全路徑確認寫正確。
4.5 拷貝tnsnames.ora文件
拷貝tnsnames.ora文件到備庫2個節點:

scp $ORACLE_HOME/network/admin/tnsnames.ora 192.168.1.61:$ORACLE_HOME/network/admin/tnsnames.ora
scp $ORACLE_HOME/network/admin/tnsnames.ora 192.168.1.63:$ORACLE_HOME/network/admin/tnsnames.ora

注:這裏拷貝後須要修改LOCAL_LISTENER參數 (僅在備庫端全部節點操做).這裏的LOCAL_LISTENER參數是設置的tnsnames中配置的別名。

LISTENER_JYZHAO1=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = jystdrac1-vip)(PORT = 1521)))
LISTENER_JYZHAO2=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = jystdrac2-vip)(PORT = 1521)))

4.6 建立ASM相關目錄

ASMCMD> mkdir +data/MYNAS
ASMCMD> cd +data/MYNAS
ASMCMD> mkdir PARAMETERFILE DATAFILE CONTROLFILE TEMPFILE ONLINELOG
 
ASMCMD> mkdir +fra/MYNAS
ASMCMD> cd +fra/MYNAS
ASMCMD> mkdir ARCHIVELOG CONTROLFILE ONLINELOG STANDBYLOG

5.備庫恢復數據庫

  • 使用啓動實例到nomount狀態
  • 初始化standby數據庫
  • 確認已建立ORLs和SRLs
  • 確認備庫tnsnames.ora
  • 啓動MRP
  • 建立spfile而後使用spfile啓動數據庫

5.1 使用啓動實例到nomount狀態
在備庫節點1操做:

sqlplus / as sysdba
startup nomount pfile=$ORACLE_HOME/dbs/pfile_for_standby.txt

5.2 初始化standby數據庫
這裏經常使用的兩種方案:直接duplicate建立;使用RMAN手工恢復。

①使用duplicate命令建立standby數據庫:

rman target sys/oracle@jyzhao1 auxiliary /
DUPLICATE TARGET DATABASE FOR STANDBY from active database NOFILENAMECHECK;

②使用RMAN恢復standby數據庫:

rman target /
restore controlfile from '/public/hotback/jyzhao/standby/control_for_standby.ctl';
alter database mount;
restore database;

根據實際狀況或本身更熟悉的方式選擇任意一種便可。
這裏的恢復操做實際在實驗過程當中碰到一個問題,具體內容可參考:《案例:Oracle報錯ASM磁盤組不存在或沒有mount》。

5.3 確認已建立ORLs和SRLs
查詢v$logfile

SQL> SELECT MEMBER FROM V$LOGFILE;

MEMBER
----------------------------------------------------------------
+DATA/mynas/onlinelog/group_2.267.951608745
+FRA/mynas/onlinelog/group_2.258.951608751
+DATA/mynas/onlinelog/group_1.266.951608731
+FRA/mynas/onlinelog/group_1.257.951608737
+DATA/mynas/onlinelog/group_3.268.951608757
+FRA/mynas/onlinelog/group_3.259.951608763
+DATA/mynas/onlinelog/group_4.269.951608769
+FRA/mynas/onlinelog/group_4.260.951608775
+FRA/mynas/standbylog/standby_group_11.log
+FRA/mynas/standbylog/standby_group_12.log
+FRA/mynas/standbylog/standby_group_13.log
+FRA/mynas/standbylog/standby_group_21.log
+FRA/mynas/standbylog/standby_group_22.log
+FRA/mynas/standbylog/standby_group_23.log

14 rows selected.

在ASMCMD中查詢沒有也會後續自動建立的,肯定路徑沒問題就能夠,路徑若是有問題,極可能是以前的convert參數設置有問題。

5.4 確認備庫tnsnames.ora
確認tnsnames.ora配置正確(on all standby nodes):

JYZHAO =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.51)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.53)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jyzhao)
    )
  )

JYZHAO1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.51)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jyzhao)
      (SID = jyzhao1)
    )
  )

JYZHAO2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.53)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jyzhao)
      (SID = jyzhao2)
    )
  )

LISTENER_JYZHAO1=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = jystdrac1-vip)(PORT = 1521)))
LISTENER_JYZHAO2=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = jystdrac2-vip)(PORT = 1521)))

MYNAS =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.62)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.64)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = mynas)
    )
  )

MYNAS1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.62)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = mynas)
      (SID = jyzhao1)
    )
  )


MYNAS2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.64)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = mynas)
      (SID = jyzhao2)
    )
  )

特別要注意LISTENER_JYZHAO1和LISTENER_JYZHAO2的配置是否對應備份的信息。

5.5 啓動MRP

ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

5.6 建立spfile而後使用spfile啓動數據庫
建立spfile

create spfile='+data/mynas/parameterfile/spfileMYNAS.ora' from pfile='/opt/app/oracle/product/11.2.0/dbhome_1/dbs/pfile_for_standby.txt';

在備庫兩個節點修改init .ora,指定spfile位置:

On jystdrac1:
 
[oracle@jystdrac1 dbs]$ cat initjyzhao1.ora 
spfile='+data/mynas/parameterfile/spfileMYNAS.ora'
 
On jystdrac2:
 
[oracle@jystdrac2 dbs]$ cat initjyzhao2.ora
spfile='+data/mynas/parameterfile/spfileMYNAS.ora'

從新啓動到mount狀態能夠再次開啓MRP進程。

6.檢查同步狀態

能夠在備庫根據下面的SQL查詢相關的信息:

select * from v$archive_gap;
select process, client_process, sequence#, status from v$managed_standby;
select sequence#, first_time, next_time, applied from v$archived_log;
select archived_thread#, archived_seq#, applied_thread#, applied_seq# from v$archive_dest_status;
select thread#, max (sequence#) from v$log_history group by thread#;
select thread#, max (sequence#) from v$archived_log where APPLIED='YES' group by thread#;

實際看同步延遲:

SQL>  select * from v$dataguard_stats;

NAME                             VALUE                                                            UNIT                           TIME_COMPUTED                  DATUM_TIME
-------------------------------- ---------------------------------------------------------------- ------------------------------ ------------------------------ ------------------------------
transport lag                    +00 00:04:36                                                     day(2) to second(0) interval   08/10/2017 09:26:06            08/10/2017 09:25:50
apply lag                        +00 00:05:34                                                     day(2) to second(0) interval   08/10/2017 09:26:06            08/10/2017 09:25:50
apply finish time                +00 00:00:05.432                                                 day(2) to second(3) interval   08/10/2017 09:26:06
estimated startup time           26                                                               second                         08/10/2017 09:26:06

由於咱們使用的是歸檔進程傳輸,因此會有一組在線日誌的延遲,若是咱們想在保證不影響主庫業務的同時,儘量更實時的去同步傳輸,那咱們就須要使用LGWR傳輸,只須要去掉ARCH的關鍵字便可:

--以前的設置
alter system set log_archive_dest_2='SERVICE=mynas ARCH VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=mynas';

--修改設置,能夠在線修改:
alter system set log_archive_dest_2='SERVICE=mynas VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=mynas';

實際上默認的就是使用LGWR去ASYNC傳輸,通常這樣延遲會很小,大部分狀態下均可以接近實時同步。關於這兩種方式的差別能夠參考《ARCH和LGWR進程同步DG日誌的區別》。

7.添加資源

最後咱們須要把Standby RAC的數據庫和實例都添加到OCR中,使他們可以方便被CRS所管理:

--oracle user:
srvctl add database -d mynas -n jyzhao -o /opt/app/oracle/product/11.2.0/dbhome_1 -c RAC -p +data/mynas/parameterfile/spfileMYNAS.ora -r physical_standby -a DATA,FRA
srvctl add instance -d mynas -i jyzhao1 -n jystdrac1
srvctl add instance -d mynas -i jyzhao2 -n jystdrac2
srvctl start database -d mynas

參數比較多,能夠參考幫助說明:

[grid@jystdrac1 ~]$ srvctl add database -h

Adds a database configuration to the Oracle Clusterware.

Usage: srvctl add database -d <db_unique_name> -o <oracle_home> [-c {RACONENODE | RAC | SINGLE} [-e <server_list>] [-i <inst_name>] [-w <timeout>]] [-m <domain_name>] [-p <spfile>] [-r {PRIMARY | PHYSICAL_STANDBY | LOGICAL_STANDBY | SNAPSHOT_STANDBY}] [-s <start_options>] [-t <stop_options>] [-n <db_name>] [-y {AUTOMATIC | MANUAL | NORESTART}] [-g "<serverpool_list>"] [-x <node_name>] [-a "<diskgroup_list>"] [-j "<acfs_path_list>"]
    -d <db_unique_name>      Unique name for the database
    -o <oracle_home>         ORACLE_HOME path
    -c <type>                Type of database: RAC One Node, RAC, or Single Instance
    -e <server_list>         Candidate server list for RAC One Node database
    -i <inst_name>           Instance name prefix for administrator-managed RAC One Node database (default first 12 characters of <db_unique_name>)
    -w <timeout>             Online relocation timeout in minutes
    -x <node_name>           Node name. -x option is specified for single-instance databases
    -m <domain>              Domain for database. Must be set if database has DB_DOMAIN set.
    -p <spfile>              Server parameter file path
    -r <role>                Role of the database (primary, physical_standby, logical_standby, snapshot_standby)
    -s <start_options>       Startup options for the database. Examples of startup options are OPEN, MOUNT, or 'READ ONLY'.
    -t <stop_options>        Stop options for the database. Examples of shutdown options are NORMAL, TRANSACTIONAL, IMMEDIATE, or ABORT.
    -n <db_name>             Database name (DB_NAME), if different from the unique name given by the -d option
    -y <dbpolicy>            Management policy for the database (AUTOMATIC, MANUAL, or NORESTART)
    -g "<serverpool_list>"   Comma separated list of database server pool names
    -a "<diskgroup_list>"    Comma separated list of disk groups
    -j "<acfs_path_list>"    Comma separated list of ACFS paths where database's dependency will be set
    -h                       Print usage

最後查看備庫資源狀態:

[grid@jystdrac1 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATA.dg
               ONLINE  ONLINE       jystdrac1                                    
               ONLINE  ONLINE       jystdrac2                                    
ora.FRA.dg
               ONLINE  ONLINE       jystdrac1                                    
               ONLINE  ONLINE       jystdrac2                                    
ora.LISTENER.lsnr
               ONLINE  ONLINE       jystdrac1                                    
               ONLINE  ONLINE       jystdrac2                                    
ora.OCR.dg
               ONLINE  ONLINE       jystdrac1                                    
               ONLINE  ONLINE       jystdrac2                                    
ora.asm
               ONLINE  ONLINE       jystdrac1                Started             
               ONLINE  ONLINE       jystdrac2                Started             
ora.gsd
               OFFLINE OFFLINE      jystdrac1                                    
               OFFLINE OFFLINE      jystdrac2                                    
ora.net1.network
               ONLINE  ONLINE       jystdrac1                                    
               ONLINE  ONLINE       jystdrac2                                    
ora.ons
               ONLINE  ONLINE       jystdrac1                                    
               ONLINE  ONLINE       jystdrac2                                    
ora.registry.acfs
               ONLINE  ONLINE       jystdrac1                                    
               ONLINE  ONLINE       jystdrac2                                    
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       jystdrac1                                    
ora.cvu
      1        ONLINE  ONLINE       jystdrac1                                    
ora.jystdrac1.vip
      1        ONLINE  ONLINE       jystdrac1                                    
ora.jystdrac2.vip
      1        ONLINE  ONLINE       jystdrac2                                    
ora.mynas.db
      1        ONLINE  ONLINE       jystdrac1                Open                
      2        ONLINE  ONLINE       jystdrac2                Open                
ora.oc4j
      1        ONLINE  ONLINE       jystdrac1                                    
ora.scan1.vip
      1        ONLINE  ONLINE       jystdrac1                                    
[grid@jystdrac1 ~]$

確認開啓ADG實時應用:

SQL> select name, database_role, open_mode from gv$database;

NAME      DATABASE_ROLE    OPEN_MODE
--------- ---------------- --------------------
JYZHAO    PHYSICAL STANDBY READ ONLY
JYZHAO    PHYSICAL STANDBY READ ONLY

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE using current logfile disconnect from session;

Database altered.

SQL> select name, database_role, open_mode from gv$database;

NAME      DATABASE_ROLE    OPEN_MODE
--------- ---------------- --------------------
JYZHAO    PHYSICAL STANDBY READ ONLY WITH APPLY
JYZHAO    PHYSICAL STANDBY READ ONLY WITH APPLY

SQL> set lines 1000                  
SQL> select * from v$dataguard_stats;

NAME                             VALUE                                                            UNIT                           TIME_COMPUTED                  DATUM_TIME
-------------------------------- ---------------------------------------------------------------- ------------------------------ ------------------------------ ------------------------------
transport lag                    +00 00:00:00                                                     day(2) to second(0) interval   08/10/2017 12:40:25            08/10/2017 12:40:22
apply lag                        +00 00:00:00                                                     day(2) to second(0) interval   08/10/2017 12:40:25            08/10/2017 12:40:22
apply finish time                                                                                 day(2) to second(3) interval   08/10/2017 12:40:25
estimated startup time           30                                                               second                         08/10/2017 12:40:25

SQL> /

NAME                             VALUE                                                            UNIT                           TIME_COMPUTED                  DATUM_TIME
-------------------------------- ---------------------------------------------------------------- ------------------------------ ------------------------------ ------------------------------
transport lag                    +00 00:00:00                                                     day(2) to second(0) interval   08/10/2017 12:43:04            08/10/2017 12:43:03
apply lag                        +00 00:00:00                                                     day(2) to second(0) interval   08/10/2017 12:43:04            08/10/2017 12:43:03
apply finish time                +00 00:00:00.000                                                 day(2) to second(3) interval   08/10/2017 12:43:04
estimated startup time           30                                                               second                         08/10/2017 12:43:04

Reference

很是感謝Bhavin Hingu,我在實驗過程當中,不少規範參考了他的文章《Step By Step of Configuring Oracle 11gR2 (11.2.0.1) RAC to RAC Dataguard》,不得不說,這種Standby RAC的施工,最終實施成功很容易,但作到每一步實施都規範就很難,我作的過程當中也在不少細節作了進一步的說明和延伸。

相關文章
相關標籤/搜索