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.


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

评论:

写的太好了 呵呵呵

发表于 guest 在 2013年01月30日, 03:31 下午 CST #

发表一条评论:
  • HTML语法: 禁用
About

本博客由Oracle全球技术支持中国区的工程师维护。为中文用户提供数据库相关的技术支持信息,包括常用的诊断工具、诊断方法、产品新特性、案例分析等。此外,MOS也陆续推出各类中文内容:技术通讯统一发布在Note 1529795.1 中,中文文档列表更新在Note 1533057.1 中,网上讲座请查看MOS文档 1456176.1,在"Archived"中可以下载历史的录音和文档。

Search

Archives
« 四月 2014
星期日星期一星期二星期三星期四星期五星期六
  
1
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
今天