11g 新特性—— Active Database Duplication

season0891發表於2014-05-09

https://blogs.oracle.com/Database4CN/entry/11g_%E6%96%B0%E7%89%B9%E6%80%A7_active_database_duplication

11g 新特性—— Active Database Duplication

簡介
---------
Active database duplication功能是從11g開始引入的一個新功能,它是對比以前版本中的基於備份集的複製資料庫功能。

下 面簡單的回顧一下關於ORACLE Duplicate Database功能,Duplicate database可以按照用途分為2種,一種是duplicate database,第二種是duplicate standby database,本文主要介紹duplicate database功能,會在以後介紹duplicate standby database。

Duplicate Database又可以按照複製資料的來源不同分為2種方式:Active Database Duplication(從正在執行的資料庫上覆制資料)和Backup-based duplication(基於備份集的資料複製)

1. Backup-based duplication 又分為下面3中形式:
o 複製的過程不連線到源資料庫,RMAN從Catalog 資料庫取得備份資訊。

o 複製的過程不連線到源資料庫,也不連線到Catalog資料庫,RMAN從已有的備份集取得備份資訊。

o 複製的過程連線到源資料庫,RMAN從源資料庫的控制檔案取得備份資訊。

2. Active Database 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對比
-------------------------------------------------------------
Active database 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。

下面以一個測試例子來具體說明
------------------------------
source database    :11gR2 standalone db, db_name=orcl,  ip=192.168.1.112
duplicate database :11gR2 standalone db, db_name=dupdb, ip=192.168.1.113
source 和 duplicate database 使用相同的目錄結構。
source 資料庫必須是配置為歸檔模式。

1. 將密碼檔案從source伺服器複製到duplicate伺服器,並且重新命名:
$ mv orapworcl orapwdupdb

2. 在duplicate伺服器,建立init引數檔案'initdupdb.ora',檔案中新增一行資訊:
DB_NAME=dupdb

3. 在duplicate伺服器, 建立 adump 目錄和資料檔案所在的目錄:
$ mkdir -p /home/oracle/app/admin/orcl/adump
$ mkdir -p /home/oracle/app/oradata

4. 在duplicate伺服器和source伺服器, 編輯新增下面資訊到$ORACLE_HOME/network/tnsnames.ora
dupdb =
 (DESCRIPTION =
   (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.113)(PORT = 1521))
   )
   (CONNECT_DATA =
     (SERVICE_NAME = dupdb)
   ))


orcl =
 (DESCRIPTION =
   (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.112)(PORT = 1521))
   )
   (CONNECT_DATA =
     (SERVICE_NAME = orcl)
   ))


5. 在duplicate伺服器, 編輯新增下面的資訊到 $GRID_HOME/network/listener.ora檔案(本測試是11.2資料庫,並且安裝了GRID,因此listener.ora檔案是在GRID_HOME下面)

LISTENER =
 (DESCRIPTION_LIST =
   (DESCRIPTION =
     (ADDRESS = (PROTOCOL = IPC)(KEY = ANYTHING))
     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.113)(PORT = 1521))
   ) )


SID_LIST_LISTENER =
 (SID_LIST =
   (SID_DESC =
     (GLOBAL_DBNAME = dupdb)
     (ORACLE_HOME = /home/oracle/app/product/11.2)
     (SID_NAME = dupdb)
   ) )

6. 在duplicate伺服器,啟動AUXILIARY例項到 nomount 狀態:
$ export ORACLE_SID=dupdb
$ sqlplus / as sysdba
SQL> startup nomount pfile='/home/oracle/app/product/11.2/dbs/initdupdb.ora'

7. 測試 connetion:
$ sqlplus sys/oracle@dupdb as sysdba
$ sqlplus sys/oracle@orcl as sysdba

8. duplicate database
% rman target sys/oracle@orcl AUXILIARY SYS/oracle@dupdb
RMAN> DUPLICATE TARGET DATABASE TO dupdb FROM ACTIVE DATABASE nofilenamecheck SPFILE;




以下???????試過程中螢幕上的輸出資訊 ================================================================================


[oracle@bakserver ~]$ rman target sys/oracle@orcl AUXILIARY SYS/oracle@dupdb

Recovery Manager: Release 11.2.0.1.0 - Production on Sun Mar 25 18:14:13 2012

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

connected to target database: ORCL (DBID=1306650359)
connected to auxiliary database: DUPDB (not mounted)

RMAN> DUPLICATE TARGET DATABASE TO dupdb FROM ACTIVE DATABASE nofilenamecheck SPFILE;

Starting Duplicate Db at 25-MAR-12
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 device type=DISK

contents of Memory Script:
{
   backup as copy reuse <=========================複製spfile
   targetfile  '/home/oracle/app/product/11.2/dbs/spfileorcl.ora' auxiliary format
 '/home/oracle/app/product/11.2/dbs/spfiledupdb.ora'   ;
   sql clone "alter system set spfile= ''/home/oracle/app/product/11.2/dbs/spfiledupdb.ora''";
}
executing Memory Script

Starting backup at 25-MAR-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=34 device type=DISK
Finished backup at 25-MAR-12

sql statement: alter system set spfile= ''/home/oracle/app/product/11.2/dbs/spfiledupdb.ora''

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''DUPDB'' comment=
 ''duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''DUPDB'' comment= ''duplicate'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     238530560 bytes

Fixed Size                     1335724 bytes
Variable Size                 83889748 bytes
Database Buffers             150994944 bytes
Redo Buffers                   2310144 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''ORCL'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''DUPDB'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   backup as copy current controlfile auxiliary format  '/home/oracle/app/oradata/orcl/control01.ctl'; <=========================複製控制檔案
   restore clone controlfile to  '/home/oracle/app/oradata/orcl/control02.ctl' from
 '/home/oracle/app/oradata/orcl/control01.ctl';
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''DUPDB'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area     238530560 bytes

Fixed Size                     1335724 bytes
Variable Size                 83889748 bytes
Database Buffers             150994944 bytes
Redo Buffers                   2310144 bytes

Starting backup at 25-MAR-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=/home/oracle/app/product/11.2/dbs/snapcf_orcl.f tag=TAG20120325T183209 RECID=3 STAMP=778876330
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 25-MAR-12

Starting restore at 25-MAR-12
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 device type=DISK

channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 25-MAR-12

database mounted
RMAN-05538: WARNING: implicitly using DB_FILE_NAME_CONVERT

contents of Memory Script:
{
   set newname for datafile  1 to
 "/home/oracle/app/oradata/orcl/system01.dbf";
   set newname for datafile  2 to
 "/home/oracle/app/oradata/orcl/sysaux01.dbf";
   set newname for datafile  3 to
 "/home/oracle/app/oradata/orcl/undotbs01.dbf";
   set newname for datafile  4 to
 "/home/oracle/app/oradata/orcl/users01.dbf";
   backup as copy reuse <=========================複製資料檔案
   datafile  1 auxiliary format
 "/home/oracle/app/oradata/orcl/system01.dbf"   datafile
 2 auxiliary format
 "/home/oracle/app/oradata/orcl/sysaux01.dbf"   datafile
 3 auxiliary format
 "/home/oracle/app/oradata/orcl/undotbs01.dbf"   datafile
 4 auxiliary format
 "/home/oracle/app/oradata/orcl/users01.dbf"   ;
   sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 25-MAR-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/home/oracle/app/oradata/orcl/system01.dbf
output file name=/home/oracle/app/oradata/orcl/system01.dbf tag=TAG20120325T183219
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/home/oracle/app/oradata/orcl/undotbs01.dbf
output file name=/home/oracle/app/oradata/orcl/undotbs01.dbf tag=TAG20120325T183219
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:16
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/home/oracle/app/oradata/orcl/sysaux01.dbf
output file name=/home/oracle/app/oradata/orcl/sysaux01.dbf tag=TAG20120325T183219
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=/home/oracle/app/oradata/orcl/users01.dbf
output file name=/home/oracle/app/oradata/orcl/users01.dbf tag=TAG20120325T183219
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 25-MAR-12

sql statement: alter system archive log current

contents of Memory Script:
{
   backup as copy reuse <=========================複製歸檔日誌
   archivelog like  "/home/oracle/app/archdir/1_17_778869623.dbf" auxiliary format
 "/home/oracle/app/archdir1_17_778869623.dbf"   ;
   catalog clone archivelog  "/home/oracle/app/archdir1_17_778869623.dbf";
   switch clone datafile all;
}
executing Memory Script

Starting backup at 25-MAR-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=17 RECID=3 STAMP=778876388
output file name=/home/oracle/app/archdir1_17_778869623.dbf RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
Finished backup at 25-MAR-12

cataloged archived log
archived log file name=/home/oracle/app/archdir1_17_778869623.dbf RECID=3 STAMP=778875343

datafile 1 switched to datafile copy
input datafile copy RECID=3 STAMP=778875343 file name=/home/oracle/app/oradata/orcl/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=4 STAMP=778875343 file name=/home/oracle/app/oradata/orcl/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=778875343 file name=/home/oracle/app/oradata/orcl/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=6 STAMP=778875343 file name=/home/oracle/app/oradata/orcl/users01.dbf

contents of Memory Script:
{
   set until scn  229779;
   recover <=========================不完全恢復
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 25-MAR-12
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 17 is already on disk as file /home/oracle/app/archdir1_17_778869623.dbf
archived log file name=/home/oracle/app/archdir1_17_778869623.dbf thread=1 sequence=17
media recovery complete, elapsed time: 00:00:01
Finished recover at 25-MAR-12

contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
   sql clone "alter system set  db_name =
 ''DUPDB'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     238530560 bytes

Fixed Size                     1335724 bytes
Variable Size                 83889748 bytes
Database Buffers             150994944 bytes
Redo Buffers                   2310144 bytes

sql statement: alter system set  db_name =  ''DUPDB'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system reset  db_unique_name scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     238530560 bytes

Fixed Size                     1335724 bytes
Variable Size                 83889748 bytes
Database Buffers             150994944 bytes
Redo Buffers                   2310144 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUPDB" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16 <=========================重建控制檔案
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/home/oracle/app/oradata/orcl/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/home/oracle/app/oradata/orcl/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/home/oracle/app/oradata/orcl/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/home/oracle/app/oradata/orcl/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/home/oracle/app/oradata/orcl/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/home/oracle/app/oradata/orcl/sysaux01.dbf",
 "/home/oracle/app/oradata/orcl/undotbs01.dbf",
 "/home/oracle/app/oradata/orcl/users01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /home/oracle/app/oradata/orcl/temp01.dbf in control file

cataloged datafile copy
datafile copy file name=/home/oracle/app/oradata/orcl/sysaux01.dbf RECID=1 STAMP=778875365
cataloged datafile copy
datafile copy file name=/home/oracle/app/oradata/orcl/undotbs01.dbf RECID=2 STAMP=778875365
cataloged datafile copy
datafile copy file name=/home/oracle/app/oradata/orcl/users01.dbf RECID=3 STAMP=778875365

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=778875365 file name=/home/oracle/app/oradata/orcl/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=778875365 file name=/home/oracle/app/oradata/orcl/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=778875365 file name=/home/oracle/app/oradata/orcl/users01.dbf

contents of Memory Script:
{
   Alter clone database open resetlogs; <=========================open db
}
executing Memory Script

database opened
Finished Duplicate Db at 25-MAR-12

RMAN>

RMAN> exit


Recovery Manager complete.


================================================================================

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

相關文章