使用Oracle 11g新特性 Active Database Duplication 搭建Dataguard環境


Duplication Database 介紹

Duplicate database可以按照用途分為2種:

    duplicate database(復制出一個數據庫)
    duplicate standby database(復制出一個dataguard standby數據庫)

Duplicate Database又可以按照復制數據的來源不同分為2種方式:

    Active Database Duplication(從正在運行的數據庫上復制數據)
    Backup-based duplication(基於備份集的數據復制)

 

Active Database Duplication 介紹

Active database duplication功能是從11g開始引入的一個新功能,它是對比以前版本中的基於備份集(Backup-based duplication)的復制數據庫功能。    這種復制數據庫要求源數據庫是open狀態或者mount狀態,復制的過程一定要連接到源數據庫,RMAN直接從源庫復制數據庫到Duplication服務器,這種方式不需要提前備份源庫。

 

Duplicate Database 特點

1. 復制的Database會自動分配一個新的DBID,與源數據庫的DBID不同,這樣Duplicate數據庫和源庫可以注冊到同一個catalog 數據庫。
如果使用操作系統的命令來做異機復制恢復的話,新創建的數據庫和源庫是相同的DBID。

2. 復制的數據庫可以是源庫的一個完全鏡像,也可以是源庫的一個子集。

3. 復制的數據庫和源庫必須是相同的操作系統平台,我們認為同平台下的32-bit 和 64-bit是同一個平台,例如Linux IA (32-bit) 和Linux IA (64-bit),認為是相同的平台,可以實施duplicate 功能,但是最后一定要運行下面的腳本來轉換PL/SQL:
ORACLE_HOME/rdbms/admin/utlirp.sql

 

Active Database Duplication 和 Backup-based duplication對比

Backup-based duplication :需要提前備份數據庫,磁盤空間大小能夠滿足備份的需要。
Active Database Duplication 不需要提前備份,節省了磁盤空間,減少了傳輸備份的時間,但在復制的過程中,對源庫有一定的壓力,需要一定的網絡帶寬

 

Active Database Duplication 原理

1. 手動創建一個臨時的pfile文件,pfile文件至少包括一個參數DB_NAME,然后啟動到nomount狀態。
2. RMAN從源庫拷貝spfile文件到復制數據庫上,並且修改spfile的名字。
3. RMAN從源庫拷貝最新的control file到復制數據庫,並且mount 復制數據庫。
4. RMAN從源庫拷貝datafile和必要的歸檔日志到復制數據庫。
5. RMAN執行不完全的恢復。
6. RMAN創建新的control file,並且設置新的DBID。
7. 以RESETLOGS方式打開復制的database。

以上理論知識參考自下列網址:

11g 新特性—— Active Database Duplication

 

使用Active Database Duplication搭建步驟

一、要點

--主庫        
主庫開啟歸檔
主庫開啟force logging
主庫修改dg需要的參數
主庫生成duplicate需要的控制文件
主庫tns中加入備庫服務名

--備庫
備庫生成一個包含db_name的pfile
拷貝主庫的密碼文件放置到備庫指定位置並改名
設置監聽為靜態監聽
拷貝主庫上的tns文件到備庫指定位置
使用tnsping測試主庫備庫之間的連通性
使用pfile啟動備庫到nomount狀態

 

二、具體操作、

系統說明:

主庫:

IP:172.25.21.111
Linux:RHEL6.4 DB:Oracle 11.2.0.4 SID:siebuat

備庫:

IP:172.25.21.222
Linux:RHEL6.4 DB:Oracle 11.2.0.4 SID:uatldg
-----------------------------------------------主庫配置-----------------------------------------------

1、查看主庫是否開啟歸檔

SYS@siebuat> archive log list;
Database log mode           Archive Mode
Automatic archival           Enabled
Archive destination           /oracle/archivelog
Oldest online log sequence     21
Next log sequence to archive   23
Current log sequence           23

2、查看主庫是否開啟FORCE_LOGGING

SYS@siebuat> r
  1* SELECT NAME,OPEN_MODE,DATABASE_ROLE,LOG_MODE,FORCE_LOGGING FROM V$DATABASE

NAME           OPEN_MODE  DATABASE_ROLE  LOG_MODE              FORCE_
------------------ ---------- -------------- ------------------------ ------
SIEBUAT        READ WRITE PRIMARY         ARCHIVELOG           YES

如果未開啟FORCE_LOGGING,則執行
SYS@siebuat> ALTER DATABASE FORCE LOGGING;

3、主庫修改dg需要的參數

--修改主庫spfile初始化參數
alter system set log_archive_config='dg_config=(siebuat,uatldg )';
--log_archive_dest_1已經設置在本地,不需要再設置,只需要設置log_archive_dest_2
alter system set log_archive_dest_2='service=uatldg LGWR SYNC AFFIRM valid_for=(online_logfiles,primary_role) db_unique_name=uatldg';
--延遲開啟dest_2,等備庫配置好后再enable
alter system set log_archive_dest_state_2='defer';
--設置standby文件自動管理
alter system set standby_file_management=auto;
alter system set fal_server='uatldg';
alter system set fal_client='siebuat';

 4、主庫生成duplicate控制文件需要的參數模板

SYS@siebuat> create pfile='/home/oracle/to_standby/duplicate.cmd' from spfile;

File created.

5、主庫TNSNAMES.ORA中加入備庫服務名

# Generated by Oracle configuration tools.

SIEBUAT =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.21.111)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = siebuat)
    )
  )

UATLDG =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.21.222)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = uatldg)
    )
  )

 6、主庫修改duplicate參數文件

[oracle@primary ~]$ cat duplicate.cmd
##在這里指定主庫與備庫存在不同的參數,可以直接通過主庫生成的pfile來修改
##標紅的參數行都需要存在,其他的如果主庫和備庫一樣,可以不添加(推薦添加上),
##如audit_trail、compatiable、db_block_size等通常都要保持一樣,不需要更改
##但如果備庫的服務器配置沒主庫高,如主庫內存100G,備庫只有60G,
##則必須添加sga_target,pga_aggregate_target等參數限制備庫共享內存的大小,否則會報內存不足
duplicate target database for standby from active database dorecover
spfile set audit_file_dest
='/oracle/admin/uatldg/adump' set audit_trail='db' set compatible='11.2.0.4.0' set control_files='/oracle/oradata/uatldg/control01.ctl','/oracle/oradata/uatldg/control02.ctl' set db_block_size='8192' set diagnostic_dest='/oracle' set dispatchers='(PROTOCOL=TCP) (SERVICE=siebuatXDB)' set fal_client='uatldg' set fal_server='siebuat' set log_archive_config='dg_config=(siebuat,uatldg )' set log_archive_dest_1='LOCATION=/oracle/archivelog' set log_archive_dest_2='service=siebuat LGWR valid_for=(online_logfiles,primary_role) db_unique_name=siebuat' set log_archive_dest_state_2='enable' set log_archive_format='%t_%s_%r.dbf' set open_cursors='300' set pga_aggregate_target='30M' set processes='200' set remote_login_passwordfile='EXCLUSIVE' set sga_target='300M' set standby_file_management='AUTO' set undo_tablespace='UNDOTBS1'
##下列參數為新增的在主庫中沒有的,對數據文件、日志文件的路徑進行轉換,
##尤其在主庫和備庫在同一台機器上時, ##如果不指定,容易造成duplicate時把主庫的在線日志文件沖掉,造成主庫crash。
 
         
set db_file_name_convert='/oracle/oradata/siebuat/','/oracle/oradata/uatldg/'
set log_file_name_convert='/oracle/oradata/siebuat/','/oracle/oradata/uatldg/'
set db_unique_name='uatldg';

 

 

-----------------------------------------------備庫配置-----------------------------------------------

1、拷貝主庫的密碼文件、tnsnames.ora文件

[oracle@primary to_standby]$ scp $ORACLE_HOME/dbs/orapwsiebuat oracle@172.25.21.222:$ORACLE_HOME/dbs/orapwuatldg 
oracle@172.25.21.222's password:
orapwsiebuat                                                     100% 1536 1.5KB/s 00:00 

  [oracle@primary to_standby]$ scp $ORACLE_HOME/network/admin/tnsnames.ora oracle@172.25.21.222:$ORACLE_HOME/network/admin/
  oracle@172.25.21.222's password:
  tnsnames.ora                                                     100% 511 0.5KB/s 00:00

 

2、設置備庫監聽為靜態監聽

# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = uatldg)
      (ORACLE_HOME = /oracle/software/11.2.0.4/db_1)
      (SID_NAME = uatldg)
    )
  )

LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.21.222)(PORT = 1521))
  )

ADR_BASE_LISTENER = /oracle
[oracle@standby admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 10-MAR-2016 13:24:32

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.25.21.222)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                09-MAR-2016 21:25:24
Uptime                    0 days 15 hr. 59 min. 8 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /oracle/software/11.2.0.4/db_1/network/admin/listener.ora
Listener Log File         /oracle/diag/tnslsnr/standby/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.25.21.222)(PORT=1521)))
Services Summary...
Service "uatldg" has 1 instance(s).
  Instance "uatldg", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

3、使用tnsping測試主庫備庫之間的連通性

####備庫#########################################################################
[oracle@standby admin]$ hostname standby [oracle@standby admin]$ tnsping siebuat TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 10-MAR-2016 13:29:07 Copyright (c) 1997, 2013, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.21.111)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = siebuat))) OK (10 msec)
[oracle@standby admin]$ tnsping uatldg TNS Ping Utility
for Linux: Version 11.2.0.4.0 - Production on 10-MAR-2016 13:29:16 Copyright (c) 1997, 2013, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.21.222)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = uatldg))) OK (0 msec)
[oracle@standby admin]$
####主庫#######################################################################################

[oracle@primary ~]$ hostname
primary
[oracle@primary ~]$ tnsping siebuat

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 10-MAR-2016 13:30:48
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.21.111)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = siebuat)))
OK (0 msec)
[oracle@primary ~]$ tnsping uatldg

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 10-MAR-2016 13:30:57
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.21.222)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = uatldg)))
OK (0 msec)
 

4、備庫創建一個pfile,加入db_name即可,並啟動到nomount

db_name='uatldg'

5、啟動備庫到nomount模式

[oracle@standby dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Thu Mar 10 13:38:54 2016

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

Connected to an idle instance.

SYS@uatldg> startup nomount
ORACLE instance started.

Total System Global Area  521936896 bytes
Fixed Size            2254824 bytes
Variable Size          209717272 bytes
Database Buffers      306184192 bytes
Redo Buffers            3780608 bytes
SYS@uatldg> 

 

duplicate操作(在主庫上執行)

[oracle@primary ~]$ rman target / auxiliary sys/passoword@uatldg cmdfile=duplicate.cmd log=standby_create.log
 Recovery Manager: Release 11.2.0.4.0 - Production on Thu Mar 10 13:41:38 2016 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights 
reserved. connected
to target database: SIEBUAT (DBID=443676106)
connected to auxiliary database: UATLDG (not mounted)

RMAN>
Starting Duplicate Db at 10-MAR-16
using target database control file instead of recovery catalog allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=1 device type=DISK
--復制主庫密碼文件
contents of Memory Script: { backup as copy reuse targetfile '/oracle/software/11.2.0.4/db_1/dbs/orapwsiebuat' auxiliary format '/oracle/software/11.2.0.4/db_1/dbs/orapwuatldg' ; } executing Memory Script Starting backup at 10-MAR-16 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=53 device type=DISK Finished backup at 10-MAR-16
--復制主庫的控制文件
contents of Memory Script: { backup as copy current controlfile for standby auxiliary format '/oracle/oradata/uatldg/control01.ctl'; restore clone controlfile to '/oracle/oradata/uatldg/control02.ctl' from '/oracle/oradata/uatldg/control01.ctl'; } executing Memory Script Starting backup at 10-MAR-16 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy copying standby control file output file name=/oracle/software/11.2.0.4/db_1/dbs/snapcf_siebuat.f tag=TAG20160310T134417 RECID=3 STAMP=906126258 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 10-MAR-16
--還原控制文件到備庫 Starting restore at 10-MAR-16 using channel ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: copied control file copy Finished restore at 10-MAR-16

--使用還原的控制文件啟動備庫到mount狀態
contents of Memory Script: { sql clone 'alter database mount standby database'; } executing Memory Script sql statement: alter database mount standby database
--轉換主庫的數據文件、臨時文件、undo文件等到備庫路徑 contents
of Memory Script: { set newname for tempfile 1 to "/oracle/oradata/uatldg/temp01.dbf"; switch clone tempfile all; set newname for datafile 1 to "/oracle/oradata/uatldg/system01.dbf"; set newname for datafile 2 to "/oracle/oradata/uatldg/sysaux01.dbf"; set newname for datafile 3 to "/oracle/oradata/uatldg/undotbs01.dbf"; set newname for datafile 4 to "/oracle/oradata/uatldg/users01.dbf"; set newname for datafile 5 to "/oracle/oradata/uatldg/example01.dbf"; backup as copy reuse datafile 1 auxiliary format "/oracle/oradata/uatldg/system01.dbf" datafile 2 auxiliary format "/oracle/oradata/uatldg/sysaux01.dbf" datafile 3 auxiliary format "/oracle/oradata/uatldg/undotbs01.dbf" datafile 4 auxiliary format "/oracle/oradata/uatldg/users01.dbf" datafile 5 auxiliary format "/oracle/oradata/uatldg/example01.dbf" ; sql 'alter system archive log current';--切換歸檔 } executing Memory Script executing command: SET NEWNAME renamed tempfile 1 to /oracle/oradata/uatldg/temp01.dbf in control file executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME
--進行數據文件備份並拷貝到備庫 Starting
backup at 10-MAR-16 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy input datafile file number=00001 name=/oracle/oradata/siebuat/system01.dbf output file name=/oracle/oradata/uatldg/system01.dbf tag=TAG20160310T134428 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35 channel ORA_DISK_1: starting datafile copy input datafile file number=00002 name=/oracle/oradata/siebuat/sysaux01.dbf output file name=/oracle/oradata/uatldg/sysaux01.dbf tag=TAG20160310T134428 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15 channel ORA_DISK_1: starting datafile copy input datafile file number=00005 name=/oracle/oradata/siebuat/example01.dbf output file name=/oracle/oradata/uatldg/example01.dbf tag=TAG20160310T134428 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15 channel ORA_DISK_1: starting datafile copy input datafile file number=00003 name=/oracle/oradata/siebuat/undotbs01.dbf output file name=/oracle/oradata/uatldg/undotbs01.dbf tag=TAG20160310T134428 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07 channel ORA_DISK_1: starting datafile copy input datafile file number=00004 name=/oracle/oradata/siebuat/users01.dbf output file name=/oracle/oradata/uatldg/users01.dbf tag=TAG20160310T134428 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 10-MAR-16 sql statement: alter system archive log current contents of Memory Script: { switch clone datafile all; } executing Memory Script datafile 1 switched to datafile copy input datafile copy RECID=3 STAMP=906126342 file name=/oracle/oradata/uatldg/system01.dbf datafile 2 switched to datafile copy input datafile copy RECID=4 STAMP=906126342 file name=/oracle/oradata/uatldg/sysaux01.dbf datafile 3 switched to datafile copy input datafile copy RECID=5 STAMP=906126342 file name=/oracle/oradata/uatldg/undotbs01.dbf datafile 4 switched to datafile copy input datafile copy RECID=6 STAMP=906126342 file name=/oracle/oradata/uatldg/users01.dbf datafile 5 switched to datafile copy input datafile copy RECID=7 STAMP=906126342 file name=/oracle/oradata/uatldg/example01.dbf Finished Duplicate Db at 10-MAR-16 --duplicate standby database完成 RMAN>

 Dataguard操作

查看主備庫信息

--主庫
SYS@siebuat> l 1* select switchover_status,DATABASE_ROLE,open_mode,PROTECTION_MODE,PROTECTION_LEVEL from v$database SYS@siebuat> / SWITCHOVER_STATUS DATABASE_ROLE OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL -------------------- --------------- ---------- ------------------------- ------------------------- TO STANDBY PRIMARY READ WRITE MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
--備庫
SYS@uatldg> l 1* select switchover_status,DATABASE_ROLE,open_mode,PROTECTION_MODE,PROTECTION_LEVEL from v$database SYS@uatldg> / SWITCHOVER_STATUS DATABASE_ROLE OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL -------------------- -------------------- ---------- ------------------------- ------------------------- RECOVERY NEEDED PHYSICAL STANDBY MOUNTED MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
--開啟備庫日志應用
SYS@uatldg> alter database recover managed standby database disconnect from session; Database altered. SYS@uatldg> select switchover_status,DATABASE_ROLE,open_mode,PROTECTION_MODE,PROTECTION_LEVEL from v$database; SWITCHOVER_STATUS DATABASE_ROLE OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL -------------------- -------------------- ---------- ------------------------- ------------------------- NOT ALLOWED PHYSICAL STANDBY MOUNTED MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE

 --查看是否存在gap

  SYS@uatldg> select thread#,low_sequence#,high_sequence# from v$archive_gap;

  no rows selected

--開啟備庫到ADG模式

SYS@uatldg> alter database recover managed standby database cancel;

Database altered.

SYS@uatldg> alter database open read only;

Database altered.

SYS@uatldg> alter database recover managed standby database disconnect from session;

Database altered.

SYS@uatldg> select switchover_status,DATABASE_ROLE,open_mode,PROTECTION_MODE,PROTECTION_LEVEL from v$database;

SWITCHOVER_STATUS DATABASE_ROLE OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL
-------------------- -------------------- ---------- ------------------------- -------------------------
NOT ALLOWED PHYSICAL STANDBY READ ONLY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
                             WITH APPLY

SYS@uatldg>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM