【DG】MAA-RAC to RAC ADG配置

恩強Boy發表於2020-07-18

一、  環境規劃

primary db name: ORCL

instance_name:   ORCL1,ORCL2

standby db_unique_name:  SBDB

instance_name:   SBDB1,SBDB2

主庫RAC VIP:   172.16.70.172/173

SCAN-IP:   172.16.70.175

備庫RAC IP:   172.16.70.152/153

SCAN-IP:   172.16.70.154

二、  前提條件

ü  主庫RAC 處於歸檔模式

ü  主庫RAC 使用 ASM 例項

ü  備庫RAC 已經安裝完 GI Grid Infrastructure )、 ASM 例項, Oracle 資料庫軟體

ü  使用OMF Oracle Managed Files )命名格式

三、  思路清晰

step1: 主庫配置

step2: 主庫收集檔案、執行備份

step3: 主備庫配置 Oracle Net(listener.ora,tnsnames.ora)

step4: 建立備庫 instance database

step5: 備庫開啟實時應用

step6: 確認 Data Guard 配置

四、  實施過程

1.  主庫配置

1)  主庫開啟force_logging

SQL> alter database force logging;

2)  主庫新增standby logfile

SQL> select group#,thread#,bytes/1024/1024 m,members,status from v$log;

SQL>   alter database add standby logfile thread 1 group 5 size 50m ;

SQL>  alter database add standby logfile thread 1 group 6  size 50m ;

SQL>  alter database add standby logfile thread 1 group 7 size 50m ;

SQL>  alter database add standby logfile thread 2  group 8  size 50m ;

SQL>  alter database add standby logfile thread 2  group 9  size 50m ;

SQL>  alter database add standby logfile thread 2 group 10  size 50m ;

standby 日誌組應比每個節點多一組,大小保持一致)

3)  主庫修改pfile 引數

SQL> alter system set db_unique_name=ORCL scope= spfile  sid='*' ;

SQL> alter system set log_archive_config='DG_CONFIG= ( ORCL ,SBDB) ' scope=both sid='*' ;

SQL> alter system set log_archive_dest_2='SERVICE= SBDB _STANDBY  LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME= SBDB ' scope=both sid='*';

SQL> alter system set DB_FILE_NAME_CONVERT='+DATA/SBDB','+DATA/ORCL'   scope=spfile sid='*';

SQL> alter system set LOG_FILE_NAME_CONVERT='+DATA/SBDB','+DATA/ORCL'   scope=spfile sid='*';

SQL> alter system set standby_file_management=AUTO scope=both sid='*' ;

SQL> alter system set fal_ client =' ORCL_PRIMARY ' scope=both sid='*';

SQL>   alter system set fal_server=' SBDB _STANDBY ' scope=both sid='*';

4)  重啟db ,使引數生效

grid 使用者)

$ srvctl stop database -d ORCL

$ srvctl start database -d ORCL

2.  主庫收集檔案、執行備份

1)  主庫建立臨時資料夾

$ mkdir -p /home/oracle/temp

2)  備庫建立相同資料夾

$ mkdir -p /home/oracle/temp

3)  主庫建立pfile

SQL> create pfile='/home/oracle/temp/initORCL.ora' from spfile;

4)  主庫執行RMAN 備份,並將備份集放在 temp 目錄下

RMAN> backup format '/home/oracle/temp/db_arch_%U' database plus archivelog;

RMAN> backup format '/home/oracle/temp/control_%U' current controlfile for standby;

5)  Oracle 使用者複製 tnsnames.ora 放在 temp 目錄下

$ cp $ORACLE_HOME/network/admin/ tnsnames .ora /home/oracle/temp/

6)  grid 使用者複製 listener.ora 放在 temp 目錄下

$ cp $ORACLE_HOME/network/admin/listener.ora /home/oracle/temp/

7)  temp 資料夾所有東西傳輸到備庫 temp 資料夾

$ scp /home/oracle/temp/* 172.16.70.150:/home/oracle/temp/

3.  配置listener.ora tnsnames.ora

1)  備庫grid 使用者複製 listener.ora 到兩節點 $ORACLE_HOME/network/admin/

2)  備庫兩節點修改listener.ora ,新增以下內容

(備庫 1 節點

SID_LIST_LISTENER =

   (SID_LIST =

        (SID_DESC =

          (GLOBAL_DBNAME = SBDB )

        (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)

          (SID_NAME = SBDB1 )

        )

)

(備庫 2 節點

SID_LIST_LISTENER =

   (SID_LIST =

        (SID_DESC =

          (GLOBAL_DBNAME = SBDB )

        (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)

          (SID_NAME = SBDB2 )

        )

)

開啟備庫監聽

grid 使用者

$ srvctl stop listener

$ srvctl start listener

3)  主備庫兩節點修改tnsnames.ora

Oracle 使用者)

主備庫(1&2 節點)

ORCL =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.70.175 )(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = ORCL)

    )

  )

ORCL_PRIMARY =

  (DESCRIPTION =

     (ADDRESS_LIST =

     (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.70.173)(PORT = 1521))

     (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.70.174)(PORT = 1521))

     )

     (CONNECT_DATA =

       (SERVER = DEDICATED)

       (SERVICE_NAME = ORCL)

    )

  )

 

SBDB =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.70.154 )(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = SBDB)

    )

  )

SBDB_STANDBY =

  (DESCRIPTION =

     (ADDRESS_LIST =

     (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.70.152 )(PORT = 1521))

     (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.70.153 )(PORT = 1521))

     )

     (CONNECT_DATA =

       (SERVER = DEDICATED)

       (SERVICE_NAME = SBDB)

    )

  )

4.  建立備庫instance database

1)  備庫建立密碼檔案

(備庫1 節點)

$ cd /u01/app/oracle/product/11.2.0/db_1/dbs

$ orapwd file=orapwSBDB 1  password=oracle

(備庫2 節點)

$ cd /u01/app/oracle/product/11.2.0/db_1/dbs

$ orapwd file=orapwSBDB 2  password=oracle

2)  複製並且重新命名備庫pfile

(備庫1 節點)

$ cp /home/oracle/temp/initORCL.ora /u01/app/oracle/product/11.2.0/db_1/dbs/initSBDB.ora

3)  修改initSBDB.ora

執行以下命令:

$ vi initSBDB.ora

:%s# ORCL #AAAA#g

:%s# SBDB # ORCL #g

:%s#AAAA#SBDB#g

:%s#ORCL_PRIMARY#AAAA#g

:%s#SBDB_STANDBY#ORCL_PRIMARY#g

:%S#AAAA#SBDB_STANDBY#g

注意 db_name 修改回 ORCL ,主備庫的 db_name 應保持一致。

最後結果如下:

*.db_unique_name=SBDB

*.audit_file_dest='/u01/app/oracle/admin/SBDB/adump'

*.audit_trail='db'

*.cluster_database=true

*.compatible='11.2.0.4.0'

*.control_files='+DATA/orcl/controlfile/current.260.1045841213'

*.db_block_size=8192

*.db_create_file_dest='+DATA'

*.db_domain=''

*.db_file_name_convert='+DATA/ORCL','+DATA/SBDB'

*.db_name=' ORCL '

*.diagnostic_dest='/u01/app/oracle'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=SBDBXDB)'

*.fal_client='SBDB_STANDBY'

*.fal_server='ORCL_PRIMARY'

SBDB1.instance_number=1

SBDB2.instance_number=2

*.log_archive_config='DG_CONFIG=(SBDB,ORCL)'

*.log_archive_dest_1='LOCATION=+ARCH'

*.log_archive_dest_2='SERVICE=ORCL_PRIAMRY LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCL'

*.log_archive_format='%t_%s_%r.dbf'

*.log_file_name_convert='+DATA/ORCL','+DATA/SBDB'

*.memory_target=3279945728

*.open_cursors=300

*.processes=150

*.remote_listener='cluster-scan-ip:1521'

*.remote_login_passwordfile='exclusive'

*.standby_file_management='AUTO'

SBDB2.thread=2

SBDB1.thread=1

SBDB1.undo_tablespace='UNDOTBS1'

SBDB2.undo_tablespace='UNDOTBS2'

4)  給備庫新增磁碟組目錄

grid 使用者)

(備庫1 節點)

$ sqlplus / as sysasm

SQL> alter diskgroup DATA add directory'+DATA/SBDB';

5)  備庫建立spfile

Oracle 使用者)

(備庫1 節點)

SQL> create spfile='+DATA/SBDB/spfileSBDB.ora' from pfile='?/dbs/initSBDB.ora';

6)  備庫兩節點建立pfile

(備庫1 節點)

$ cd $ORACLE_HOME/dbs/

$ echo "SPFILE='+DATA/SBDB/spfileSBDB.ora'" > initSBDB1.ora

(備庫2 節點)

$ cd $ORACLE_HOME/dbs/

$ echo "SPFILE='+DATA/SBDB/spfileSBDB.ora'" > initSBDB 2 .ora

7)  備庫兩節點建立目錄

$ mkdir -p /u01/app/oracle/admin/SBDB/adump

8)  備庫開啟到nomount 狀態

(備庫1 節點)

$ export ORACLE_SID=SBDB1

$ sqlplus / as sysdba

SQL> startup nomount;

9)  備庫進行RMAN 複製

(備庫1 節點)

$ export ORACLE_SID=SBDB1

$ rman target sys/oracle@ORCL auxiliary /

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jul 16 15:28:59 2020

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1573621948)

connected to auxiliary database: ORCL (not mounted)

 

RMAN> duplicate target database for standby;

注:對於11g 和以後的版本,我們可以使用以下命令:

RMAN> duplicate target database for standby  from avtive database;

5.  備庫開啟實時應用

1)  備庫查詢database 狀態

SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;

2)  備庫開啟實時應用

SQL> ALTER  DATABASE RECOVER MANAGED STANDBY  DATABASE DISCONNECT FROM SESSION;

3)  備庫取消實時應用

SQL> ALTER  DATABASE RECOVER MANAGED STANDBY  DATABASE cancel;

4)  開啟備庫

SQL> alter database open read only;

5)  備庫再次開啟實時應用

SQL> ALTER  DATABASE RECOVER MANAGED STANDBY  DATABASE DISCONNECT FROM SESSION;

6)  開啟備庫2 節點

SQL> startup;

7)  SBDB 新增到 GI 中( Oracle 使用者)

$ srvctl add database -d SBDB -o /u01/app/oracle/product/11.2.0/db_1

$ srvctl add instance -d SBDB -i SBDB1 -n rac1

$ srvctl add instance -d SBDB -i SBDB2 -n rac2

6.  確定Dataguard 配置

1) 備庫查詢

SQL> select sequence#, first_time, next_time

from v$archived_log order by sequence#;

2) 主庫切換日誌

SQL> alter system archive log current;

3) 備庫再次查詢

SQL> select sequence#, first_time, next_time

from v$archived_log order by sequence#;

 

 

 

 

--------- end ----------


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

相關文章