Oracle 11g Dataguard Duplicate物理備庫配置

來源:互聯網
上載者:User

Oracle 11g Dataguard Duplicate物理備庫配置(一)之物理備庫建立配置
# ver:1.5 第五次修改
# modify: 2013.8.16
# author: koumm

相關閱讀:配置Oracle 11g的Dataguard測試,建立物理備庫(Physical Standby Database)

Oracle 11g DataGuard 物理備庫配置及Active DataGuard測試

有關DG的相關概念,可參考:Oracle Data Guard Concepts and Administration
有關配置DG的參數描述,可參考:Oracle Data Guard 重要配置參數
基於同一主機配置 Oracle 11g Data Guard  
說明:
本文安裝配置了Oracle 11g Dataguard通過duplicate方式建立物理備庫。
比起上次配置有以下不同點:
1. 主備庫目錄結構不同。
2. 採用duplicate方式建立物理備庫。

一、環境介紹
1. 主要資料庫環境
作業系統版本  : OEL5.8 x64
資料庫版本    : Oracle 11.2.0.3 x64
資料庫名      : orcl
資料庫SID    : orcl
db_unique_name: orcl
instance_name : orcl
DGMGRL        : orcl_DGMGRL

2. 備庫環境
作業系統版本  : OEL5.8 x64
資料庫版本    : Oracle 11.2.0.3 x64 (只安裝oracle資料庫軟體,no netca dbca)
資料庫名      : slave
資料庫SID    : slave
db_unique_name: slave
instance_name : slave
DGMGRL        : slave_DGMGRL

3. DataGuard啟動順序
啟動順序:先啟備庫,後啟主庫
關閉順序:先關主庫,後關備庫
 
二、主要資料庫環境準備

1. 主庫環境對比
充分利用主要資料庫原來環境,僅量不對主庫參數配置做過多的修改。
重新建立口令檔案
# su - oracle
$ orapwd file='/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl' password=oracle entries=10 force=y

2. 修改配置lisener監聽檔案
說明:添加dgmgrl靜態監聽配置,為後面的dg broker配置打基礎。
$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora 
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.233.200)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = orcl)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = orcl)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = orcl_DGMGRL)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = orcl)
    )
  )
ADR_BASE_LISTENER = /u01/app/oracle
#其中的GLOBAL_DBNAME具有固定的格式:<db_unique_name>_DGMGRL.<db_domain>。

4. 修改配置tnsname.ora檔案
說明:ORCL是主庫的服務名,DG是備庫的服務名。
$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.233.200)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )
SLAVE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.233.150)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = slave)
    )
  )

5. 修改配置成規檔模式
1)、檢查資料庫是否處于歸檔狀態
SQL> archive log list;
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database flashback on;
SQL> alter database open;

2)、將主庫設定為 FORCE LOGGING 模式
SQL> alter database force logging;
SQL> select force_logging,flashback_on from v$database;
FOR FLASHBACK_ON
--- ------------------
YES YES

6. 修改主庫參數檔案
SQL>
alter system set instance_name='orcl' scope=spfile; 
alter system set db_unique_name='orcl' scope=spfile; 
alter system set local_listener='orcl' scope=spfile;
alter system set log_archive_config='DG_CONFIG=(orcl,slave)'; 
alter system set log_archive_dest_1='LOCATION=/u01/archivelog/ valid_for=(all_logfiles,all_roles) db_unique_name=orcl' scope=spfile;
alter system set log_archive_dest_2='SERVICE=slave lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=slave' scope=spfile; 
alter system set log_archive_format='arch_%r_%t_%s.arc' scope=spfile;
alter system set fal_client='orcl' scope=spfile;
alter system set fal_server='slave' scope=spfile; 
alter system set standby_file_management=AUTO; 
alter database add standby logfile group 4 '/u01/app/oracle/oradata/orcl/standby_redo04.log' size 50M; 
alter database add standby logfile group 5 '/u01/app/oracle/oradata/orcl/standby_redo05.log' size 50M; 
alter database add standby logfile group 6 '/u01/app/oracle/oradata/orcl/standby_redo06.log' size 50M; 
alter database add standby logfile group 7 '/u01/app/oracle/oradata/orcl/standby_redo07.log' size 50M; 
SQL> shutdown immediate;
SQL> startup;
 
三、備庫配置

1. 備庫環境
作業系統版本  : OEL5.8 x64
資料庫版本    : Oracle 11.2.0.3 x64 (只安裝oracle資料庫軟體,no netca dbca)
資料庫名      : slave
資料庫SID    : slave
db_unique_name: slave
instance_name : slave
DGMGRL        : slave_DGMGRL

2. 修改配置lisener監聽檔案
$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora 
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.233.150)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = slave)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = slave)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = slave_DGMGRL)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = slave)
    )
  )
ADR_BASE_LISTENER = /u01/app/oracle

其中的GLOBAL_DBNAME具有固定的格式:<db_unique_name>_DGMGRL.<db_domain>。

3. 修改配置tnsname.ora檔案
說明:ORCL是主庫的服務名,DG是備庫的服務名。
$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.233.200)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )
SLAVE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.233.150)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = slave)
    )
  )

測試服務名連通性:
tnsping orcl
tnsping slave

3. 建立11g資料庫基本目錄
# su - oracle
mkdir -p /u01/app/oracle/admin/slave/{adump,dpdump,pfile,scripts} 
mkdir -p /u01/app/oracle/oradata/slave 
mkdir -p /u01/app/oracle/fast_recovery_area/slave
mkdir -p /u01/archivelog

4. 拷貝主庫口令檔案並改名
註:10g DG環境只要求密碼相同,11g DG則要求與主庫完全一致。
否則報無許可權錯誤。
$ cd /u01/app/oracle/product/11.2.0/db_1/dbs/
$ scp oracle@192.168.233.150:/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl  $ORACLE_HOME/dbs/
$ mv orapworcl orapwslave

測試遠程登入
$ sqlplus sys/oracle@orcl as sysdba;
$ sqlplus sys/oracle@slave as sysdba;

5. 啟動到nomount狀態
$ echo 'db_name=slave' > $ORACLE_HOME/dbs/initslave.ora 
$ sqlplus /nolog
SQL> conn / as sysdba;
SQL> startup nomount;


四、 開始在RMAN duplicate資料庫

1. RMAN同進串連主庫與備庫
$ rman target sys/oracle@orcl auxiliary sys/oracle@slave
復原管理員: Release 11.2.0.3.0 - Production on 星期五 8月 16 21:14:10 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
已串連到目標資料庫: ORCL (DBID=1351417842)
已串連到次要資料庫: SLAVE (未裝載)

2. 開始duplicate資料庫
RMAN>
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate auxiliary channel stby type disk;
duplicate target database for standby nofilenamecheck from active database
dorecover
spfile
parameter_value_convert 'orcl','slave'
set instance_name='slave'
set db_unique_name='slave'
set local_listener='slave'
set db_file_name_convert='/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/slave/'
set log_file_name_convert='/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/slave/'
set control_files='/u01/app/oracle/oradata/slave/control01.ctl','/u01/app/oracle/oradata/slave/control02.ctl','/u01/app/oracle/oradata/slave/control03.ctl'
set log_archive_dest_1='LOCATION=/u01/archivelog/ valid_for=(all_logfiles,all_roles) db_unique_name=slave'
set log_archive_dest_2='SERVICE=orcl lgwr async valid_for=(online_logfile,primary_role) db_unique_name=orcl'
set log_archive_max_processes='5'
set standby_file_management='AUTO'
set fal_client='slave'
set fal_server='orcl';
release channel c1;
release channel c2;
release channel stby;
}
RMAN> quit
復原管理員完成。

3. 查看備庫狀態
說明:duplicate資料庫之後,備庫只是處於mount狀態,查看備庫狀態。
$ sqlplus / as sysdba
# 查看備庫狀態
SQL> select open_mode,database_role,db_unique_name from v$database;
OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME
-------------------- ---------------- ------------------------------
MOUNTED              PHYSICAL STANDBY slave

4. 將備庫置與應用記錄模式狀態
SQL> alter database recover managed standby database using current logfile disconnect from session; 
Database altered. 

5. 驗證物理備庫日誌應用
1)主庫上操作
SQL> conn / as sysdba;
SQL> create user abc identified by abc ;
SQL> grant dba to abc;
SQL> conn abc/abc
SQL> create table abc ( id integer , name char(10));
SQL> insert into abc values ( 0 , 'aaa' );
SQL> commit;
SQL> conn / as sysdba;
SQL> archive log list;
資料庫記錄模式          存檔模式
自動封存                啟用
存檔終點                /u01/archivelog/
最早的聯機日誌序列      8
下一個存檔日誌序列      10
當前日誌序列            10
 
2)備庫上驗證
SQL> archive log list
資料庫記錄模式        存檔模式
自動封存              啟用
存檔終點              /u01/archivelog/
最早的聯機日誌序列    9
下一個存檔日誌序列    0
當前日誌序列          10

SQL> select sequence#,first_time,next_time,applied from v$archived_log order by sequence#;
 SEQUENCE# FIRST_TIME    NEXT_TIME      APPLIED
---------- -------------- -------------- ---------
        7 16-8月 -13    16-8月 -13    YES
        8 16-8月 -13    16-8月 -13    YES
        9 16-8月 -13    16-8月 -13    IN-MEMORY

經過測試,Oracle 11g dataguard物理備庫建立成功。

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.