Oracle 11g R2 Data Guard 容災(zāi)系統(tǒng)構(gòu)建Step by Step(一)

目錄

  • 容災(zāi)概述
  • 方案介紹
  • 簡(jiǎn)單data guard集群的構(gòu)建

容災(zāi)概述

很少有企業(yè)很坦然面對(duì)這樣的問(wèn)題,“您的數(shù)據(jù)中心停運(yùn)怎么辦?“;”您的信息中心大樓遭到破壞怎么保證正常運(yùn)營(yíng)?”等等諸多的問(wèn)題。在IT領(lǐng)域,業(yè)務(wù)連續(xù)性(BC)指的就是在主業(yè)務(wù)系統(tǒng)發(fā)生人為的或不可預(yù)知的故障時(shí),為確保關(guān)鍵業(yè)務(wù)服務(wù)不中斷而包含的一套標(biāo)準(zhǔn)、流程和系統(tǒng)。 災(zāi)難恢復(fù)(DR)指的是在主數(shù)據(jù)中心遭受災(zāi)難時(shí),導(dǎo)致核心業(yè)務(wù)系統(tǒng)停用,將IT資源復(fù)制到可繼續(xù)運(yùn)行的遠(yuǎn)程站點(diǎn)。

業(yè)務(wù)連續(xù)性和災(zāi)難恢復(fù)之間有不少交叉點(diǎn),具體到企業(yè)時(shí),往往面對(duì)成本和復(fù)雜性兩方面挑戰(zhàn)。

  • 復(fù)雜性
    災(zāi)難恢復(fù)由于涉及到太多的元素,覆蓋企業(yè)全部流程管理幾乎不可能。DR環(huán)節(jié)中關(guān)鍵的切換演練涉及到多方面的人,財(cái),物協(xié)調(diào)。準(zhǔn)備工作尤其復(fù)雜。近年來(lái)得益于虛擬化技術(shù)的快速演變,企業(yè)服務(wù),桌面,存儲(chǔ)的跨距離全面移動(dòng)能力大大增強(qiáng)。在危機(jī)時(shí)刻,企業(yè)得以保持業(yè)務(wù)連續(xù)運(yùn)營(yíng)。
    另一方面,自動(dòng)化維運(yùn)工具的不斷成熟,也簡(jiǎn)化了,災(zāi)難恢復(fù)過(guò)程中面臨的大量復(fù)雜操作,避免了進(jìn)一步的人為錯(cuò)誤和干擾。
  • 成本
    對(duì)于由人為錯(cuò)誤或技術(shù)故障導(dǎo)致的數(shù)據(jù)丟失來(lái)說(shuō),本地恢復(fù)通常是最經(jīng)濟(jì)的選擇。而對(duì)于自然災(zāi)害等導(dǎo)致的不可控災(zāi)難來(lái)說(shuō),遠(yuǎn)程恢復(fù)依然是最佳方案。當(dāng)企業(yè)數(shù)據(jù)中心受到廣泛災(zāi)難影響,其IT團(tuán)隊(duì)必須考慮所提供的服務(wù)的重要性等級(jí)問(wèn)題。并非所有數(shù)據(jù)服務(wù)都是同等重要的,所以必須要弄清哪些服務(wù)是關(guān)鍵的第一級(jí)服務(wù),哪些是第二級(jí)服務(wù),以及這些應(yīng)用程序關(guān)聯(lián)了哪些不同的服務(wù)級(jí)別協(xié)議(SLA)。根據(jù)SLA對(duì)服務(wù)分級(jí)可確保所有業(yè)務(wù)關(guān)鍵應(yīng)用程序的最佳正常運(yùn)行時(shí)間,同時(shí)又能最有效地保證有限資源的投入。
    普遍采用的WAN優(yōu)化的復(fù)制可以消除物理數(shù)據(jù)運(yùn)輸,節(jié)省數(shù)據(jù)復(fù)制的開(kāi)支。
    為了達(dá)到最高保證的災(zāi)難恢復(fù)能力,需要投入可觀的成本。下圖是關(guān)于災(zāi)備的國(guó)家標(biāo)準(zhǔn):


    image.png

方案介紹

數(shù)據(jù)復(fù)制技術(shù)是容災(zāi)的關(guān)鍵,不同于傳統(tǒng)的基于SAN鏡像、基于LVM鏡像的災(zāi)備方案,Oracle Data Gurad提供自底向上的有效的災(zāi)難恢復(fù)解決方案,該方案基于數(shù)據(jù)庫(kù)的redo log復(fù)制。保證了用戶在幾分鐘內(nèi)就能恢復(fù)業(yè)務(wù),最高能6級(jí)的災(zāi)難恢復(fù)能力。有如下示意圖。


image.png

Data Gurad 通過(guò)在遠(yuǎn)端保存與原數(shù)據(jù)庫(kù)事務(wù)一致的數(shù)據(jù)庫(kù)備份,提供了有效的災(zāi)難恢復(fù)解決方案。按照redo log的應(yīng)用方式不同,可以分為物理類型、邏輯類型和快照類型。我們這里先討論物理類型的。
物理類型的有以下一些優(yōu)點(diǎn):

  • 快速有效的錯(cuò)誤恢復(fù)
  • 能從主庫(kù)卸載掉報(bào)表
  • 能以只讀方式打備用數(shù)據(jù)庫(kù)。

模擬構(gòu)建

本節(jié)將具體容災(zāi)系統(tǒng)構(gòu)建,整個(gè)工作步驟分為以下幾個(gè)部分:

  • 容災(zāi)環(huán)境模擬準(zhǔn)備
  • 主數(shù)據(jù)庫(kù)配置
  • 物理備機(jī)創(chuàng)建

虛擬機(jī):VMware? Workstation 12 Pro或更高版本。
操作系統(tǒng):Oracle Linux 7.6
數(shù)據(jù)庫(kù):Oracle 11g R2

- 容災(zāi)環(huán)境模擬準(zhǔn)備
  1. 主機(jī)環(huán)境配置
    模擬了一個(gè)主備機(jī)的虛擬場(chǎng)景,如圖:


    image.png

實(shí)際應(yīng)用中,要考慮到實(shí)際的網(wǎng)絡(luò),主機(jī)等情況進(jìn)行適當(dāng)相應(yīng)調(diào)整,本方案僅僅是一個(gè)簡(jiǎn)化版本的data guard實(shí)現(xiàn)。

為模擬實(shí)現(xiàn),我們用虛擬機(jī)搭建兩臺(tái)服務(wù)器,主機(jī)的基本系統(tǒng)的準(zhǔn)備工作我們這里省略了。配置好的結(jié)果要求如下:
位于北京的主數(shù)據(jù)庫(kù)服務(wù)器:
hostname :beijing
databasetype:primary
db_unique_name: BEIJING
db_name=orcl
tns alias:BEIJING
ipaddr:192.168.1.30

[oracle@beijing dbs]$ cat /etc/hostname
beijing
[root@beijing ~]# cat /etc/hosts
192.168.1.30    beijing
192.168.1.40    chengdu

防火墻關(guān)閉

[root@beijing ~]# systemctl stop firewalld

位于成都的備份數(shù)據(jù)庫(kù)服務(wù)器:
hostname:chengdu
databasetype:standby
db_unique_name:chengdu
db_name:orcl
tns alias:chengdu

防火墻關(guān)閉

[root@chengdu ~]# systemctl stop firewalld
[oracle@chengdu dbs]$ cat /etc/hostname 
chengdu

[root@chengdu ~]# cat /etc/hosts
192.168.1.30    beijing
192.168.1.40    chengdu

2.數(shù)據(jù)庫(kù)復(fù)制環(huán)境準(zhǔn)備:

  • 主備機(jī)oracle數(shù)據(jù)庫(kù)軟件的安裝,我們這里選用11gr2版本進(jìn)行測(cè)試和安裝。(具體步驟省略)

安裝中,主服務(wù)器安裝并運(yùn)行企業(yè)版數(shù)據(jù)庫(kù),備份服務(wù)器僅僅安裝軟件即可。
北京服務(wù)器oracle用戶配置文件如下:

[oracle@beijing admin]$ cd
[oracle@beijing ~]$  cat .bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export ORACLE_SID=orcl
export ORACLE_BASE=/home/oracle/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
PATH=$PATH:$ORACLE_HOME/bin
export PATH
export DISPLAY=localhost:10.0

成都服務(wù)器oracle用戶配置文件如下:

[oracle@chengdu ~]$ cat .bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export ORACLE_SID=orcl
export ORACLE_BASE=/home/oracle/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
PATH=$PATH:$ORACLE_HOME/bin
export PATH
export DISPLAY=localhost:10.0

為簡(jiǎn)化后面的數(shù)據(jù)庫(kù)復(fù)制過(guò)程,我們?cè)O(shè)計(jì)主備的用戶,目錄完全相同。

  • 靜態(tài)偵聽(tīng)配置
    考慮到使用RMAN來(lái)復(fù)制數(shù)據(jù)庫(kù),需要為數(shù)據(jù)庫(kù)配置靜態(tài)偵聽(tīng)。
    成都服務(wù)器的靜態(tài)偵聽(tīng)配置:
[oracle@chengdu admin]$ cat listener.ora 
SID_LIST_LISTENER =
 (SID_LIST =
  (SID_DESC =
    (GLOBAL_DBNAME = chengdu)
    (ORACLE_HOME = /home/oracle/app/oracle/product/11.2.0/dbhome_1)
    (SID_NAME = orcl)
  )
 )
  • 配置口令文件

日志傳輸會(huì)用到口令文件。要求是主備機(jī)口令一致。
配置成都數(shù)據(jù)庫(kù)口令文件

[oracle@chengdu dbs]$ cd $ORACLE_HOME/dbs
[oracle@chengdu dbs]$ orapwd file=orapworcl
Enter password for SYS: 

配置北京數(shù)據(jù)庫(kù)口令文件

[oracle@beijing ~]$ cd $ORACLE_HOME/dbs
[oracle@beijing dbs]$ orapwd file=orapworcl force=y
Enter password for SYS: 
  • 為備用機(jī)創(chuàng)建初始化參數(shù)文件
    我們使用主數(shù)據(jù)庫(kù)參數(shù)文件為模板,修改生成備用機(jī)的參數(shù)文件,具體見(jiàn)后面的主數(shù)據(jù)庫(kù)參數(shù)配置中的具體內(nèi)容。

  • 配置tns alias
    為北京服務(wù)器配置網(wǎng)絡(luò)別名:

[oracle@beijing admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
beijing =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.30)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = beijing)
    )
  )
chengdu =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.40)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = chengdu)
    )
  )

為成都服務(wù)器配置網(wǎng)絡(luò)別名:

[oracle@chengdu admin]$ cat tnsnames.ora 
beijing =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.30)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = beijing)
    )
  )
chengdu =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.40)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = chengdu)
    )
  )

兩邊實(shí)例都啟動(dòng)起來(lái),測(cè)試下連通性。
北京服務(wù)器:
啟動(dòng)實(shí)例

[oracle@beijing ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Fri Jun 14 11:32:36 2019
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area  709836800 bytes
Fixed Size                  2231752 bytes
Variable Size             436208184 bytes
Database Buffers          264241152 bytes
Redo Buffers                7155712 bytes
Database mounted.
Database opened.
SQL> exit

啟動(dòng)偵聽(tīng)

[oracle@beijing ~]$ lsnrctl start
[oracle@beijing ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 14-JUN-2019 11:33:11
Copyright (c) 1991, 2011, Oracle.  All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                14-JUN-2019 11:26:53
Uptime                    0 days 0 hr. 6 min. 17 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /home/oracle/app/oracle/diag/tnslsnr/beijing/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=beijing)(PORT=1521)))
Services Summary...
Service "beijing" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully

成都服務(wù)器啟動(dòng)實(shí)例:

[oracle@chengdu ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Fri Jun 14 11:36:13 2019
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> startup pfile=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora nomount
ORACLE instance started.
Total System Global Area  250560512 bytes
Fixed Size                  2227256 bytes
Variable Size             192938952 bytes
Database Buffers           50331648 bytes
Redo Buffers                5062656 bytes
SQL> exit

啟動(dòng)偵聽(tīng):

[oracle@chengdu ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 14-JUN-2019 11:37:04
Copyright (c) 1991, 2011, Oracle.  All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                14-JUN-2019 11:33:42
Uptime                    0 days 0 hr. 3 min. 22 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /home/oracle/app/oracle/diag/tnslsnr/chengdu/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=chengdu)(PORT=1521)))
Services Summary...
Service "chengdu" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
  Instance "orcl", status BLOCKED, has 1 handler(s) for this service...
The command completed successfully

互通性測(cè)試
北京服務(wù)器:

[oracle@beijing ~]$ tnsping beijing

TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 14-JUN-2019 11:45:23
Copyright (c) 1997, 2011, Oracle.  All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.30)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
OK (0 msec)
[oracle@beijing ~]$ tnsping chengdu
TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 14-JUN-2019 11:45:27
Copyright (c) 1997, 2011, Oracle.  All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.40)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
OK (10 msec)
[oracle@beijing ~]$

成都服務(wù)器

[oracle@chengdu ~]$ tnsping beijing
TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 14-JUN-2019 11:46:55
Copyright (c) 1997, 2011, Oracle.  All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.30)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
OK (0 msec)
[oracle@chengdu ~]$ tnsping chengdu
TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 14-JUN-2019 11:46:58
Copyright (c) 1997, 2011, Oracle.  All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.40)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
OK (0 msec)
[oracle@chengdu ~]$ 
- 主數(shù)據(jù)庫(kù)配置

1.啟用歸檔模式

[oracle@beijing ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Fri Jun 14 11:54:50 2019
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>exit

[oracle@beijing ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Wed Jun 12 21:15:28 2019

Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> startup mount;
ORACLE instance started.
Total System Global Area  709836800 bytes
Fixed Size                  2231752 bytes
Variable Size             440402488 bytes
Database Buffers          260046848 bytes
Redo Buffers                7155712 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter database  open;
Database altered.
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     60
Next log sequence to archive   62
Current log sequence           62
SQL>
  1. 強(qiáng)制日志模式啟動(dòng)

允許不進(jìn)行日志記錄的操作,但是改變?nèi)匀粫?huì)放到重做日志流中。

[oracle@beijing dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Wed Jun 12 21:26:23 2019

Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> alter database force logging;

Database altered.

SQL>
  1. 主數(shù)據(jù)庫(kù)的初始化參數(shù)配置
    可以直接創(chuàng)建pfile文件,然后修改,也可以使用alter system修改。
[oracle@beijing dbs]$ cat initorcl.ora
orcl.__db_cache_size=436207616
orcl.__java_pool_size=16777216
orcl.__large_pool_size=16777216
orcl.__oracle_base='/home/oracle/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=469762048
orcl.__sga_target=671088640
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=184549376
orcl.__streams_pool_size=0
*.audit_file_dest='/home/oracle/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/home/oracle/app/oracle/oradata/ORCL/controlfile/o1_mf_gj7n6w3b                                                                                             _.ctl','/home/oracle/app/oracle/fast_recovery_area/ORCL/controlfile/o1_mf_gj7n6w                                                                                             3q_.ctl'
*.db_block_size=8192
*.db_create_file_dest='/home/oracle/app/oracle/oradata'
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='/home/oracle/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4322230272
*.db_unique_name='BEIJING'
*.diagnostic_dest='/home/oracle/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.log_archive_config='DG_CONFIG=(beijing,chengdu)'
*.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST db_unique_name=beijing'
*.log_archive_dest_2='service=chengdu valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) d                                                                                             b_unique_name=chengdu'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='DEFER'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=1135607808
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.service_names='BEIJING'
*.undo_tablespace='UNDOTBS1'

我們對(duì)data guard需要的幾個(gè)參數(shù)做下說(shuō)明:

*.db_unique_name='BEIJING'

用于在data guard中區(qū)分不同數(shù)據(jù)庫(kù)。

*.log_archive_config='DG_CONFIG=(beijing,chengdu)'

用于定義Data Guard中的各個(gè)數(shù)據(jù)庫(kù)的db_unique_name列表,也可用于控制向遠(yuǎn)端數(shù)據(jù)庫(kù)發(fā)送日志或從遠(yuǎn)端接收日志。

*.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST db_unique_name=beijing'

配置本地日志文件歸檔,這里使用默認(rèn)的FRA。因?yàn)槭莑ocation本地歸檔,所以db_unique_name是可選的,放這里可以清楚的表明各個(gè)數(shù)據(jù)庫(kù)的關(guān)系。

*.log_archive_dest_2='service=chengdu valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) d                                                                                             
b_unique_name=chengdu'

配置遠(yuǎn)端的日志傳輸參數(shù)。

  • service指向遠(yuǎn)端的Net Service Name。我們通過(guò)chengdu這個(gè)Net Service Name將日志傳送到成都遠(yuǎn)端。
  • valid_for基于數(shù)據(jù)庫(kù)擔(dān)當(dāng)?shù)慕巧腿罩疚募愋蛠?lái)決定是否生效,它的用法是:
    valid_for=(redo_log_type,database_role)
    其中redo_log_type=(ONLINE_LOGFILE | STANDBY_LOGFILE | ALL_LOGFILES)
    database_role=(PRIMARY_ROLE | STANDBY_ROLE | ALL_ROLES)
    這里參數(shù)的意義就是如果是主數(shù)據(jù)庫(kù),就將ONLINE_LOGFILES類型的日志發(fā)送到遠(yuǎn)端。ONLINE_LOGFILES也即是數(shù)據(jù)庫(kù)正常工作時(shí)產(chǎn)生的日志。STANDBY_LOGFILE指的是額外建立的用于保存接收到的ONLINE_LOGFILES的日志。
  • db_unique_name 用于明確指出將發(fā)送至的備用數(shù)據(jù)庫(kù)。
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='DEFER'

分別表示dest_1和dest_2的啟用狀態(tài),本地歸檔當(dāng)然要啟動(dòng),遠(yuǎn)程歸檔我們等備用數(shù)據(jù)庫(kù)啟用后,再啟動(dòng)。

  1. 備庫(kù)的初始化參數(shù)配置
    為省略部分參數(shù)的修改,簡(jiǎn)化安裝,我們假設(shè)兩臺(tái)機(jī)器的目錄都相同。我們采用基于主數(shù)據(jù)庫(kù)配置文件進(jìn)行修改,這樣不容易出錯(cuò)。
    修改好的pfile如下:
orcl.__db_cache_size=436207616
orcl.__java_pool_size=16777216
orcl.__large_pool_size=16777216
orcl.__oracle_base='/home/oracle/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=469762048
orcl.__sga_target=671088640
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=184549376
orcl.__streams_pool_size=0
*.audit_file_dest='/home/oracle/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/home/oracle/app/oracle/oradata/ORCL/controlfile/o1_mf_gj7n6w3b_.ctl','/home/oracle/app/oracle/fast_recovery_area/ORCL/controlfile/o1_mf_gj7n6w3q_.ctl'#Set by RMAN
*.db_block_size=8192
*.db_create_file_dest='/home/oracle/app/oracle/oradata'
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='/home/oracle/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4322230272
*.db_unique_name='chengdu'
*.diagnostic_dest='/home/oracle/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.fal_client='chengdu'
*.fal_server='beijing'
*.log_archive_config='DG_CONFIG=(beijing,chengdu)'
*.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST db_unique_name=chengdu'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=1135607808
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.service_names='chengdu'
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'

需要保留和修改的參數(shù)我們說(shuō)明下

*.log_archive_config='DG_CONFIG=(beijing,chengdu)'

用于表示data guard的組成,這個(gè)必須有的,而且每臺(tái)機(jī)器都配置相同。如果有不一致,會(huì)提示 ORA-16047: DGID mismatch between destination setting and target database。

*.db_unique_name='chengdu'
  • data guard中用于唯一標(biāo)識(shí)本數(shù)據(jù)庫(kù)。
*.fal_client='chengdu'
*.fal_server='beijing'
  • 配置Fetch Archive Log方法,用于消除可能出現(xiàn)的日志gap。
    在這里我們從beijing取得日志,所以fal_server=beijing。同理fal_client=chengdu。
*.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST db_unique_name=chengdu'
*.log_archive_dest_state_1='ENABLE'
  • 配置本地的歸檔日志參數(shù),我們定義為使用FRA。
  • 最后還需要將相應(yīng)的目錄參數(shù)做一個(gè)調(diào)整,比如目錄名中是beijing的要替換成chengdu。
  1. 使用rman復(fù)制備用數(shù)據(jù)庫(kù)。
    為簡(jiǎn)化過(guò)程,我們采用from active database直接從主數(shù)據(jù)庫(kù)將控制文件,數(shù)據(jù)庫(kù)文件推送到備用服務(wù)器,以創(chuàng)建一個(gè)新備用數(shù)據(jù)庫(kù)。
    考慮到我們已經(jīng)配置好備用數(shù)據(jù)庫(kù)的pfile了。所以我們就省略掉讓rman拷貝spfile,然后修改這一步驟。
  • 首先使用備用數(shù)據(jù)庫(kù)參數(shù)文件啟動(dòng)實(shí)例
[oracle@chengdu dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Sat Jun 15 17:39:44 2019

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

Connected to an idle instance.

SQL> startup pfile='?/dbs/initorcl.ora' nomount;
ORA-09925: Unable to create audit trail file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 9925
SQL>

提示無(wú)法創(chuàng)建審計(jì)文件,因?yàn)闆](méi)有建目錄。

SQL> host mkdir -p /home/oracle/app/oracle/admin/orcl/adump
SQL> shutdown
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup pfile='?/dbs/initorcl.ora' nomount;
ORACLE instance started.
Total System Global Area 1135747072 bytes
Fixed Size                  2227664 bytes
Variable Size             687866416 bytes
Database Buffers          436207616 bytes
Redo Buffers                9445376 bytes
SQL>

好了,備庫(kù)實(shí)例成功建立并處于nomount狀態(tài)了。

  • 復(fù)制數(shù)據(jù)庫(kù)
    復(fù)制之前我們檢查下兩邊的偵聽(tīng)是否正常啟動(dòng)并運(yùn)行。
    檢查備用數(shù)據(jù)庫(kù)。
[oracle@chengdu dbs]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-JUN-2019 17:44:25

Copyright (c) 1991, 2011, Oracle.  All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                15-JUN-2019 17:43:54
Uptime                    0 days 0 hr. 0 min. 31 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /home/oracle/app/oracle/diag/tnslsnr/chengdu/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=chengdu)(PORT=1521)))
Services Summary...
Service "chengdu" has 2 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
  Instance "orcl", status BLOCKED, has 1 handler(s) for this service...
The command completed successfully
[oracle@chengdu dbs]$

檢查下主數(shù)據(jù)庫(kù)。

[oracle@beijing dbs]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-JUN-2019 17:45:01

Copyright (c) 1991, 2011, Oracle.  All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                15-JUN-2019 12:22:46
Uptime                    0 days 5 hr. 22 min. 15 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Log File         /home/oracle/app/oracle/diag/tnslsnr/beijing/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=beijing)(PORT=1521)))
Services Summary...
Service "BEIJING" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@beijing dbs]$

我們可以在主、備數(shù)據(jù)庫(kù)來(lái)操作復(fù)制,啟動(dòng)rman。

[oracle@beijing dbs]$ rman
Recovery Manager: Release 11.2.0.3.0 - Production on Sat Jun 15 17:46:39 2019
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
RMAN> connect target sys/123456@beijing
connected to target database: ORCL (DBID=1538750300)
RMAN> connect auxiliary sys/123456@chengdu
connected to auxiliary database: ORCL (not mounted)
RMAN> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE
DORECOVER 
PFILE ?/dbs/initorcl.ora
NOFILENAMECHECK 

過(guò)程提示錯(cuò)誤,復(fù)制控制文件錯(cuò)誤。

Starting backup at 15-JUN-19
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying standby control file
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 06/15/2019 17:50:36
RMAN-05501: aborting duplication of target database
RMAN-03015: error occurred in stored script Memory Script
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 06/15/2019 17:50:36
ORA-17628: Oracle error 19505 returned by remote Oracle server

RMAN> exit

我們首先還是需要保證目錄是創(chuàng)建好的,因?yàn)榈谝徊骄褪菍⒖刂莆募?fù)制到備用數(shù)據(jù)庫(kù)上,我們檢查下目錄,修補(bǔ)一下。

[oracle@chengdu dbs]$ ll /home/oracle/app/oracle/oradata/ORCL/controlfile/
ls: cannot access /home/oracle/app/oracle/oradata/ORCL/controlfile/: No such file or directory
[oracle@chengdu dbs]$ mkdir -p /home/oracle/app/oracle/oradata/ORCL/controlfile/
[oracle@chengdu dbs]$

重新來(lái)過(guò)。好了一切順利,備用庫(kù)創(chuàng)建起來(lái)了。

[oracle@beijing dbs]$ rman
Recovery Manager: Release 11.2.0.3.0 - Production on Sat Jun 15 18:02:08 2019
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
RMAN> connect target sys@beijing
target database Password:
connected to target database: ORCL (DBID=1538750300)
RMAN> connect auxiliary sys@chengdu
auxiliary database Password:
connected to auxiliary database: ORCL (not mounted)
RMAN> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE
PFILE ?/dbs/initorcl.ora
DORECOVER
NOFILENAMECHECK 2> 3> 4>
5>
6> ;
Starting Duplicate Db at 15-JUN-19
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=134 device type=DISK
contents of Memory Script:
{
   backup as copy reuse
   targetfile  '/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/orapworcl' auxiliary format
 '/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/orapworcl'   ;
}
executing Memory Script

中間日志省略掉了,繼續(xù)到日志末尾了。

List of Cataloged Files
=======================
File Name: /home/oracle/app/oracle/fast_recovery_area/CHENGDU/archivelog/2019_06_15/o1_mf_1_12_0hu467b6_.arc

datafile 1 switched to datafile copy
input datafile copy RECID=7 STAMP=1011031399 file name=/home/oracle/app/oracle/oradata/CHENGDU/datafile/o1_mf_system_0du467al_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=8 STAMP=1011031399 file name=/home/oracle/app/oracle/oradata/CHENGDU/datafile/o1_mf_sysaux_0eu467as_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=9 STAMP=1011031399 file name=/home/oracle/app/oracle/oradata/CHENGDU/datafile/o1_mf_undotbs1_0fu467b3_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=10 STAMP=1011031399 file name=/home/oracle/app/oracle/oradata/CHENGDU/datafile/o1_mf_users_0gu467b4_.dbf

contents of Memory Script:
{
   set until scn  1057096;
   recover
   standby
   clone database
    delete archivelog
   ;
}
executing Memory Script
executing command: SET until clause
Starting recover at 15-JUN-19
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=133 device type=DISK
starting media recovery
archived log for thread 1 with sequence 12 is already on disk as file /home/oracle/app/oracle/fast_recovery_area/CHENGDU/archivelog/2019_06_15/o1_mf_1_12_0hu467b6_.arc
archived log file name=/home/oracle/app/oracle/fast_recovery_area/CHENGDU/archivelog/2019_06_15/o1_mf_1_12_0hu467b6_.arc thread=1 sequence=12
media recovery complete, elapsed time: 00:00:00
Finished recover at 15-JUN-19
Finished Duplicate Db at 15-JUN-19
RMAN>

最后一步還根據(jù)命令行參數(shù)dorecover做了recovery。

  • 我們檢查下備用數(shù)據(jù)庫(kù)狀態(tài)。
[oracle@chengdu dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Sat Jun 15 18:05:52 2019
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>  select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/home/oracle/app/oracle/oradata/ORCL/controlfile/o1_mf_gj7n6w3b_.ctl
/home/oracle/app/oracle/fast_recovery_area/ORCL/controlfile/o1_mf_gj7n6w3q_.ctl

SQL> select name from v$dbfile;

NAME
--------------------------------------------------------------------------------
/home/oracle/app/oracle/oradata/CHENGDU/datafile/o1_mf_users_0gu467b4_.dbf
/home/oracle/app/oracle/oradata/CHENGDU/datafile/o1_mf_undotbs1_0fu467b3_.dbf
/home/oracle/app/oracle/oradata/CHENGDU/datafile/o1_mf_sysaux_0eu467as_.dbf
/home/oracle/app/oracle/oradata/CHENGDU/datafile/o1_mf_system_0du467al_.dbf

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/home/oracle/app/oracle/oradata/CHENGDU/onlinelog/o1_mf_3_gj9jm8sf_.log
/home/oracle/app/oracle/fast_recovery_area/CHENGDU/onlinelog/o1_mf_3_gj9jm8ym_.log

/home/oracle/app/oracle/oradata/CHENGDU/onlinelog/o1_mf_2_gj9jm8dd_.log
/home/oracle/app/oracle/fast_recovery_area/CHENGDU/onlinelog/o1_mf_2_gj9jm8kk_.log

/home/oracle/app/oracle/oradata/CHENGDU/onlinelog/o1_mf_1_gj9jm7yo_.log
/home/oracle/app/oracle/fast_recovery_area/CHENGDU/onlinelog/o1_mf_1_gj9jm83r_.log
6 rows selected.

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     0
Next log sequence to archive   0
Current log sequence           0
SQL>

除了沒(méi)有歸檔,貌似所有文件都過(guò)來(lái)了。

  • 啟用歸檔傳送
[oracle@beijing dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Sat Jun 15 18:10:47 2019

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> col error for a30
SQL> col dest_name for a40
SQL> set linesize 150
SQL> SELECT  DEST_ID, error, DEST_NAME,  STATUS,  TYPE,  SRL,  RECOVERY_MODE FROM  V$ARCHIVE_DEST_STATUS WHERE  DEST_ID in (1,2);

   DEST_ID ERROR                          DEST_NAME                                STATUS    TYPE           SRL RECOVERY_MODE
---------- ------------------------------ ---------------------------------------- --------- -------------- --- -----------------------
         1                                LOG_ARCHIVE_DEST_1                       VALID     LOCAL          NO  IDLE
         2                                LOG_ARCHIVE_DEST_2                       DEFERRED  PHYSICAL       YES IDLE

SQL>
SQL> alter system set log_archive_dest_state_2=enable;

System altered.

SQL> SELECT  DEST_ID, error, DEST_NAME,  STATUS,  TYPE,  SRL,  RECOVERY_MODE FROM  V$ARCHIVE_DEST_STATUS WHERE  DEST_ID in (1,2);

   DEST_ID ERROR                          DEST_NAME                                STATUS    TYPE           SRL RECOVERY_MODE
---------- ------------------------------ ---------------------------------------- --------- -------------- --- -----------------------
         1                                LOG_ARCHIVE_DEST_1                       VALID     LOCAL          NO  IDLE
         2                                LOG_ARCHIVE_DEST_2                       VALID     PHYSICAL       NO  IDLE

SQL>
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     12
Next log sequence to archive   14
Current log sequence           14
SQL>

好了,我們上備用數(shù)據(jù)庫(kù)檢查下日志情況。

[oracle@chengdu dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Sat Jun 15 18:17:19 2019

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     13
Next log sequence to archive   0
Current log sequence           14
SQL>

好了,成功傳送日志了。

  • 啟用托管恢復(fù)MRP
SQL>
SQL> alter database recover managed standby database disconnect;

Database altered.

SQL>

看看alert日志。

Sat Jun 15 18:20:04 2019
alter database recover managed standby database disconnect
Attempt to start background Managed Standby Recovery process (orcl)
Sat Jun 15 18:20:04 2019
MRP0 started with pid=27, OS id=22405
MRP0: Background Managed Standby Recovery process started (orcl)
 started logmerger process
Sat Jun 15 18:20:09 2019
Managed Standby Recovery not using Real Time Apply
Parallel Media Recovery started with 2 slaves
Waiting for all non-current ORLs to be archived...
All non-current ORLs have been archived.
Media Recovery Log /home/oracle/app/oracle/fast_recovery_area/CHENGDU/archivelog/2019_06_15/o1_mf_1_13_gj9k9obc_.arc
Media Recovery Waiting for thread 1 sequence 14 (in transit)
Completed: alter database recover managed standby database disconnect

貌似成功結(jié)束了。

  • 簡(jiǎn)單做個(gè)日志傳輸測(cè)試。
    在主數(shù)據(jù)庫(kù)上創(chuàng)建個(gè)測(cè)試表
[oracle@beijing dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Sat Jun 15 18:20:40 2019

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create table tttt as select * from dba_users;

Table created.

SQL> select count(*) from tttt;

  COUNT(*)
----------
        30

SQL>

我們上備機(jī)看看。咦,沒(méi)有顯示出期望的結(jié)果。

SQL>
SQL> select count(*) from tttt;
select count(*) from tttt
                     *
ERROR at line 1:
ORA-00942: table or view does not exist

我們?cè)谥鳈C(jī)上做個(gè)日志切換

SQL> alter system switch logfile;

System altered.

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     13
Next log sequence to archive   15
Current log sequence           15

再看看備機(jī)

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     13
Next log sequence to archive   0
Current log sequence           15
SQL> select count(*) from tttt;

  COUNT(*)
----------
        30

SQL>

終于有同步結(jié)果了,不過(guò)這需要日志切換后才能看結(jié)果呀。按照文章前面的災(zāi)難備份級(jí)別中也就差不多位于4級(jí)。
確實(shí),缺省配置的備機(jī),只能應(yīng)用歸檔日志,也就無(wú)法實(shí)時(shí)同步主機(jī)的數(shù)據(jù)變化。日志切換期間如果出現(xiàn)故障,會(huì)丟掉所有數(shù)據(jù),不能算是安全級(jí)別高的方案。而且本文中也沒(méi)有配置主備切換的選項(xiàng),無(wú)法實(shí)現(xiàn)主備的切換。
不過(guò),下一篇data guard文章中,我們計(jì)劃實(shí)現(xiàn)更多高級(jí)的data guard功能。

chimpansee 06-15

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容