【DG】Data Guard搭建(physical standby)

恩強Boy發表於2020-08-03


一、  規劃

說明: Data Guard 中,

- db_name :主備庫必須保持一致 ;

- db_unique_name: 主備庫必須不一致 ;

- service_names instance_name 可以保持一致或不一致。

二、  DG 環境要求

1.  硬體和作業系統要求

Data Guard 允許主備庫有不同的 CPU 型號,不同的作業系統(例如 windows & linux ),不同的作業系統位數( 32-bit/64-bit )或者不同的資料庫位數( 32-bit/64-bit )。

2.  Oracle 軟體要求

Data Guard 只支援 Oracle database 企業版,不支援標準版本。

在物理備庫中,Oracle 主備庫的 compatiable 引數必須保持一致(通常情況下,我們說的 Data Guard 都是指物理備庫)。在邏輯備庫中,備庫的 compatiable 必須大於或等於主庫引數。

主庫可以是單例項庫或者RAC ,備庫也可以是單例項或是 RAC

如果主備庫的作業系統一致,那麼主備庫的儲存路徑必須保持不同,否則,備庫可能會覆蓋主庫檔案。

如果主備庫都是RAC ,主庫使用了 ASM OMF Oracle managed files )命名管理,那麼備庫也應該使用 ASM OMF 管理。

三、  思路清晰

step1: 主庫開啟 force logging

step2: 備庫配置 listener.ora 檔案

step3: 主備庫配置 tnsnames.ora 檔案

step4: 主庫新增 standby logfile

step5: 主備庫修改引數檔案

step6: RMAN 複製資料庫

step7: DG 檢查,應用日誌

step8: 開啟備庫,實時應用日誌

四、 準備工作

1. 關閉防火牆 (主備庫)

# systemctl stop firewalld

# systemctl disable firewalld

2.  (主備庫)

# vi /etc/selinux/config

selinux= disabled

3.  檢查主庫 歸檔設定

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination             /archivelog/ORCL

Oldest online log sequence     26

Next log sequence to archive   28

Current log sequence           28

4.  配置/etc/hosts 檔案(主備庫)

# vi /etc/hosts

# Primary IP

172.16.70.178  primary

#Standby IP

172.16.70.179  standby

五、  搭建DG

1.  開啟強制日誌模式(主庫)

SQL> alter database force logging;

2.  配置listener.ora 檔案(備庫)

O racle 使用者

備庫新增靜態監聽

$ vi $ORACLE_HOME/network/admin/listener.ora

(新增 以下內容

SID_LIST_LISTENER =

 (SID_LIST =

      (SID_DESC =

        (GLOBAL_DBNAME = SBDB )

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

        (SID_NAME = SBDB )

      )

)

開啟監聽

$ lsnrctl start

3.  修改tnsname s .ora 檔案(主備庫

(主備庫一致)

$ vi $ORACLE_HOME/network/admin/tnsnames.ora

ORCL   =

  (DESCRIPTION =

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

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = ORCL )     

    )

  )

SBDB  =

  (DESCRIPTION =

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

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = SBDB )

    )

  )

tns 連通性 檢測

$ tnsping ORCL

$ tnsping SBDB

4.  主庫新增standby logfile;

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

SQL> select member from v$logfile;

 

SQL> alter database add standby logfile '/u01/app/oracle/oradata/ ORCL /redo04.log' size 50m;

SQL> alter database add standby logfile '/u01/app/oracle/oradata/ ORCL /redo0 5 .log' size 50m;

SQL> alter database add standby logfile '/u01/app/oracle/oradata/ ORCL /redo0 6 .log' size 50m;

SQL> alter database add standby logfile '/u01/app/oracle/oradata/ ORCL /redo0 7 .log' size 50m;

檢視日誌組狀態

SQL> select group#,status,type,member from v$logfile;

5.  修改引數檔案

主庫修改 引數

1)  生成引數檔案

SQL> create pfile from spfile;

2)  修改引數檔案

$ cd /u01/app/oracle/prod uct/11.2.0/db_1/dbs

$ vi init ORCL .ora

新增 以下內容

db_unique_name= ORCL

log_archive_config='dg_config=( ORCL , SBDB )'

log_archive_dest_1='location=/archivelog /ORCL  valid_for=(all_logfiles,all_roles) db_unique_name= ORCL '

log_archive_dest_2='service= SBDB  lgwr async valid_for=(online_logfiles,primary_roles) db_unique_name= SBDB '

log_archive_dest_state_1=enable

log_archive_dest_state_2=enable

db_ file_name_convert='/u01/app/oracle/oradata/ SBDB ','/u01/app/oracle/oradata/ ORCL '

log_file_name_convert='/u01/app/oracle/oradata/ SBDB ','/u01/app/oracle/oradata/ ORCL '

fal_server= SBDB

fal_client= ORCL

standby_file_management=auto    

3)  生成spfile ,重啟庫使引數生效

SQL> shutdown immediate;

SQL> create spfile from pfile;

SQL> st artup ;

(備庫修改)

1)  將主庫pfile 傳到備庫

$ scp initORCL.ora standby:$ORACLE_HOME/dbs/initSBDB.ora

2)  修改引數檔案

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

$ vi init SBDB .ora

執行以下命令

:%s/ORCL/AAAA/g

:%s/SBDB/ORCL/g

:%s/AAAA/SBDB/g

最後將db_name 修改回 ORCL

最後結果如下:

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

*.audit_trail='db'

*.compatible='11.2.0.4.0'

*.control_files='/u01/app/oracle/oradata/SBDB/control01.ctl','/u01/app/oracle/oradata/SBDB/control02.ctl'

*.db_block_size=8192

*.db_domain=''

*.db_name='ORCL'

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

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

*.log_archive_dest_1='LOCATION=/archivelog/SBDB'

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

*.memory_target=769654784

*.open_cursors=300

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.undo_tablespace='UNDOTBS1'

db_unique_name= SBDB

log_archive_config='dg_config=( SBDB,ORCL )'

log_archive_dest_1='location= /archivelog/SBDB valid_for=(all_logfiles,all_roles) db_unique_name= SBDB '

log_archive_dest_2='service= ORCL  lgwr async valid_for=(online_logfiles,primary_roles) db_unique_name= ORCL '

log_archive_dest_state_1=enable

log_archive_dest_state_2=enable

db_file_name_convert='/u01/app/oracle/oradata/ ORCL ','/u01/app/oracle/oradata/ SBDB '

log_file_name_convert='/u01/app/oracle/oradata/ ORCL ','/u01/app/oracle/oradata/ SBDB '

fal_server= ORCL

fal_client= SBDB

standby_file_management=auto

3)  備庫建立上述目錄

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

$ mkdir -p /u01/app/oracle/oradata/SBDB

$ mkdir -p /archivelog/SBDB

4)  備庫建立密碼檔案

$ cd $ORACLE_HOME/dbs/

$ orapwd file=orapwSBDB password=oracle

6.  複製資料庫

1) 備庫開啟到nomount狀態

SQL> create spfile from pfil e;

SQL > startup nomount;

2)RMAN複製資料庫(主庫執行)

$   rman target / auxiliary sys/oracle@ SBDB

RMAN>   duplicate target database for standby from active database;

 

此時 ,已經完成了 D ata   Guard 搭建 部分

六、  配置ADG

1) 查詢主備庫狀態

(主庫)

SQL> col db_unique_name for a15

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

 

DB_UNIQUE_NAME OPEN_MODE           DATABASE_ROLE    SWITCHOVER_STATUS

--------------- ------------------ ---------------- --------------------

ORCL                 READ WRITE          PRIMARY               FAILED DESTINATION

(備庫)

DB_UNIQUE_NAME  OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS

-------------- ------------------ ---------------- --------------------

SBDB                MOUNTED              PHYSICAL STANDBY   SESSIONS ACTIVE

2)  備庫應用日誌

SQL> alter database recover managed standby database using current logfile disconnect from session;

此時注意檢查備庫SWITCHOVER_STATUS 狀態,直到 SWITCHOVER_STATUS NOT ALLOWED 為正常

3)  備庫取消應用日誌

SQL> alter database recover managed standby database cancel;

4)  開啟備庫

SQL> alter database open;

5)  備庫開啟實時應用

SQL> alter database recover managed standby database using current logfile disconnect from session;

6)  再次檢查備庫狀態

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

DB_UNIQUE_NAME     OPEN_MODE                DATABASE_ROLE       SWITCHOVER_STATUS

--------------- -------------------- ---------------- --------------------

SBDB                  READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED

7)  檢視備庫程式狀態

SQL> select process, pid, status, client_process from v$managed_standby;

 

PROCESS          PID STATUS       CLIENT_P

--------- ---------- ------------ --------

ARCH           24183 CONNECTED    ARCH

ARCH           24186 CONNECTED    ARCH

ARCH           24188 CLOSING      ARCH

ARCH           24190 CONNECTED    ARCH

RFS            24533 IDLE         LGWR

RFS            24527 IDLE         UNKNOWN

RFS            24529 IDLE         ARCH

RFS            24707 IDLE         UNKNOWN

MRP0           24918 APPLYING_LOG N/A

 

此時,備庫已經是實時應用狀態( Active Data Guard

 

 

 

 

 

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


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

相關文章