首页 > 代码库 > oracle 11g RMAN:Active Database Duplication for standby database 创建dg 命令解读

oracle 11g RMAN:Active Database Duplication for standby database 创建dg 命令解读

基于生产的duplicate 复制,如果事先没有手动配置pfile(设定内存,进程,dg相关配置参数,数据库相关路径参数)则会出现各种参数无法转换的问题;
因为duplicate 会从生产自动拷贝pfile,控制文件,密码文件过来,如果主库和备库环境不一样(数据库软件路径,数据文件存储路径)
如果没在duplicate的命令中完整指定新环境备库的各种参数涉及路径,及转换参数,就会默认使用从主库拷贝过来的spfile中的参数设置(会忽略oracle 自定义的的缺省配置:比如adr 缺省会放在ORACLE_BASE下,所有参数配置一切以主库拷贝过来的spfile 为准);

鉴于那些对原来主库环境,和oracle数据库参数不是特别了解的同学,就不建议使用这种配置了,折腾!

-------注意如果=备库和主库的$ORACLE_BASE/$ORACLE_HOME/数据存放路径 任意一个不同,则必须配置一下的参数 
run {
allocate channel prmy1 type disk;
allocate channel prmy2 type disk;
allocate channel prmy3 type disk;
allocate channel prmy4 type disk;
allocate auxiliary channel stby type disk;

duplicate target database for standby from active database
dorecover
spfile
  parameter_value_convert ‘ora11g‘,‘lixora‘
  set db_unique_name=‘orcl‘
  set standby_file_management=‘AUTO‘
  SET FAL_SERVER="ora11g" 
  SET LOG_ARCHIVE_DEST_1=‘LOCATION=/oracle/app/oracle/oradata/arch VALID_FOR=(ALL_LOGFILE,ALL_ROLE) DB_UNIQUE_NAME=lixora‘
  set log_archive_dest_2=‘service=ora11g ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=ora11g‘    
  SET CONTROL_FILES ‘/oracle/app/oracle/oradata/control01.ctl‘
  set diagnostic_dest=‘/oracle/app/oracle‘
  set audit_file_dest=‘/oracle/app/oracle‘
  set DB_FILE_NAME_CONVERT=‘/u01/app/ora11/oradata/ORA11G/datafile/‘,‘/oracle/app/oracle/oradata/‘
  SET LOG_FILE_NAME_CONVERT ‘/u01/app/ora11/oradata/ORA11G/onlinelog/‘, ‘/oracle/app/oracle/oradata/‘   
  set db_create_file_dest=‘/oracle/app/oracle/oradata/‘
  set db_recovery_file_dest=‘/oracle/app/oracle/oradata/‘
  #SET SGA_MAX_SIZE 200M               
  #SET SGA_TARGET 185M
NOFILENAMECHECK;
}


这些个存放目录:闪回区目录,adr目录,审计日志目录, Oracle-managed 数据文件目录 等等,一定要注意啊

------------这里解释使用类上述命令执行后的日子输出,来理解使用上述命令初始化备库的原理:

$rman target sys/sys@chicago auxiliary sys/sys@boston
connected to target database: CHICAGO (DBID=761464750)
connected to auxiliary database: CHICAGO (not mounted)
RMAN> run {
allocate channel prmy1 type disk;
allocate channel prmy2 type disk;
allocate channel prmy3 type disk;
allocate channel prmy4 type disk;
allocate auxiliary channel stby type disk;
duplicate target database for standby from active database
spfile
  parameter_value_convert ‘chicago‘,‘boston‘
  set db_unique_name=‘boston‘
  set db_file_name_convert=‘/chicago/‘,‘/boston/‘
  set log_file_name_convert=‘/chicago/‘,‘/boston/‘
  set control_files=‘/u01/app/oracle/oradata/control01.ctl‘
  set log_archive_max_processes=‘5‘
  set fal_client=‘boston‘
  set fal_server=‘chicago‘
  set standby_file_management=‘AUTO‘
  set log_archive_config=‘dg_config=(chicago,boston)‘
  set log_archive_dest_2=‘service=chicago ASYNCvalid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=chicago‘
;
}

using target database control file instead of recovery catalog
allocated channel: prmy1                    ---------这个就不多说了:分配通道
channel prmy1: SID=147 device type=DISK
allocated channel: prmy2
channel prmy2: SID=130 device type=DISK
allocated channel: prmy3
channel prmy3: SID=137 device type=DISK
allocated channel: prmy4
channel prmy4: SID=170 device type=DISK
allocated channel: stby
channel stby: SID=98 device type=DISK


Starting Duplicate Db at 19-MAY-08
contents of Memory Script:
{
backup as copy reuse      -------------拷贝主库密码文件,spfile参数文件
file ‘/u02/app/oracle/product/11.1.0/db_1/dbs/orapwcore‘ auxiliary format‘/u02/app/oracle/product/11.1.0/db_1/dbs/orapwcore1‘ 
file‘/u02/app/oracle/product/11.1.0/db_1/dbs/spfilecore.ora‘ auxiliary format‘/u02/app/oracle/product/11.1.0/db_1/dbs/spfilecore1.ora‘ ;
sql clone "alter system set spfile= ‘‘/u02/app/oracle/product/11.1.0/db_1/dbs/spfilecore1.ora‘‘";
}
executing Memory Script    ----

Starting backup at 19-MAY-08
Finished backup at 19-MAY-08

sql statement: alter system set spfile= ‘‘/u02/app/oracle/product/11.1.0/db_1/dbs/spfilecore1.ora‘‘   -----在修改

contents of Memory Script:  -----------------------这里根据设置我们在run 脚本中spfile 标注下的一些参数设置, RMAN会自动生成以下脚本
{
sql clone "alter system set audit_file_dest =‘‘/u02/app/oracle/admin/boston/adump‘‘ comment=‘‘‘‘ scope=spfile";
sql clone "alter system set dispatchers =‘‘(PROTOCOL=TCP) (SERVICE=core1XDB)‘‘ comment=‘‘‘‘ scope=spfile";
sql clone "alter system set log_archive_dest_2 =‘‘service=core11 arch async VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=boston‘‘ comment=‘‘‘‘ 

scope=spfile";
sql clone "alter system set db_unique_name =‘‘boston‘‘ comment=‘‘‘‘ scope=spfile";
sql clone "alter system set db_file_name_convert =‘‘/chicago/‘‘, ‘‘/boston/‘‘ comment=‘‘‘‘ scope=spfile";
sql clone "alter system set log_file_name_convert =‘‘/chicago/‘‘, ‘‘/boston/‘‘ comment=‘‘‘‘ scope=spfile";
sql clone "alter system set control_files =‘‘/u01/app/oracle/oradata/control01.ctl‘‘ comment=‘‘‘‘ scope=spfile";
sql clone "alter system set log_archive_max_processes =5 comment=‘‘‘‘ scope=spfile";
sql clone "alter system set fal_client =‘‘boston‘‘ comment=‘‘‘‘ scope=spfile";
sql clone "alter system set fal_server =‘‘chicago‘‘ comment=‘‘‘‘ scope=spfile";
sql clone "alter system set standby_file_management =‘‘AUTO‘‘ comment=‘‘‘‘ scope=spfile";
sql clone "alter system set log_archive_config =‘‘dg_config=(chicago,boston)‘‘ comment=‘‘‘‘ scope=spfile";
sql clone "alter system set log_archive_dest_2 =‘‘service=chicago ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=chicago‘‘ comment=‘‘‘‘ scope=spfile";
shutdown clone immediate;   ----------------因为在使用这种方式创建备库时,我们只需要配置一个包含db_name,db_unique_name,block_size 这个三个参数,并把备库启动到 nomount 状态下,主要的目的就是为了让rman拷贝主库的spfile 和密码文件
startup clone nomount ;
}
executing Memory Script


sql statement: alter system set audit_file_dest = ‘‘/u02/app/oracle/admin/boston/adump‘‘ comment= ‘‘‘‘ scope=spfile
sql statement: alter system set dispatchers = ‘‘(PROTOCOL=TCP) (SERVICE=core1XDB)‘‘ comment= ‘‘‘‘ scope=spfile
sql statement: alter system set log_archive_dest_2 = ‘‘service=core11 arch async VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=boston‘‘ comment= ‘‘‘‘ 


scope=spfile
sql statement: alter system set db_unique_name = ‘‘boston‘‘ comment= ‘‘‘‘ scope=spfile
sql statement: alter system set db_file_name_convert = ‘‘/chicago/‘‘, ‘‘/boston/‘‘ comment= ‘‘‘‘ scope=spfile
sql statement: alter system set log_file_name_convert = ‘‘/chicago/‘‘, ‘‘/boston/‘‘ comment= ‘‘‘‘ scope=spfile
sql statement: alter system set control_files = ‘‘/u01/app/oracle/oradata/control01.ctl‘‘ comment= ‘‘‘‘ scope=spfile
sql statement: alter system set log_archive_max_processes = 5 comment= ‘‘‘‘ scope=spfile
sql statement: alter system set fal_client = ‘‘boston‘‘ comment= ‘‘‘‘ scope=spfile
sql statement: alter system set fal_server = ‘‘chicago‘‘ comment= ‘‘‘‘ scope=spfile
sql statement: alter system set standby_file_management = ‘‘AUTO‘‘ comment= ‘‘‘‘ scope=spfile
sql statement: alter system set log_archive_config = ‘‘dg_config=(chicago,boston)‘‘ comment= ‘‘‘‘ scope=spfile
sql statement: alter system set log_archive_dest_2 = ‘‘service=chicago ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=chicago‘‘ comment= ‘‘‘‘ 

scope=spfile

Oracle instance shut down    --------------这里重启是为了使用更新过的spfile

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area 845348864 bytes

Fixed Size 1303188 bytes
Variable Size 482348396 bytes
Database Buffers 356515840 bytes
Redo Buffers 5181440 bytes
contents of Memory Script:  ---------------开始拷贝standby 控制文件,并传到备库的相应位置
{
backup as copy current controlfile for standby auxiliary format ‘/u01/app/oracle/oradata/control01.ctl‘;
sql clone ‘alter database mount standby database‘;
}
executing Memory Script

Starting backup at 19-MAY-08
channel prmy1: starting datafile copy
copying standby control file
output file name=/u02/app/oracle/product/11.1.0/db_1/dbs/snapcf_chicago.f tag=TAG20080519T173406 RECID=2 STAMP=655148053
channel prmy1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 19-MAY-08
sql statement: alter database mount standby database    ----------------------mount 备库,准备修改初始化的数据文件路径,并拷贝到备库

contents of Memory Script:
{
set newname for tempfile 1 to"/u02/app/oracle/oradata/boston/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to "/u02/app/oracle/oradata/boston/system01.dbf";
set newname for datafile 2 to "/u02/app/oracle/oradata/boston/sysaux01.dbf";
set newname for datafile 3 to "/u02/app/oracle/oradata/boston/undotbs01.dbf";
set newname for datafile 4 to "/u02/app/oracle/oradata/boston/users01.dbf";
backup as copy reuse
datafile 1 auxiliary format "/u02/app/oracle/oradata/boston/system01.dbf" 
datafile 2 auxiliary format "/u02/app/oracle/oradata/boston/sysaux01.dbf" 
datafile 3 auxiliary format "/u02/app/oracle/oradata/boston/undotbs01.dbf" 
datafile 4 auxiliary format "/u02/app/oracle/oradata/boston/users01.dbf" ;
sql ‘alter system archive log current‘;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u02/app/oracle/oradata/boston/temp01.dbf in control file

executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME

Starting backup at 19-MAY-08
channel prmy1: starting datafile copy
input datafile file number=00001 name=/u02/app/oracle/oradata/chicago/system01.dbf
channel prmy2: starting datafile copy
input datafile file number=00002 name=/u02/app/oracle/oradata/chicago/sysaux01.dbf
channel prmy3: starting datafile copy
input datafile file number=00003 name=/u02/app/oracle/oradata/chicago/undotbs01.dbf
channel prmy4: starting datafile copy
input datafile file number=00004 name=/u02/app/oracle/oradata/chicago/users01.dbf
output file name=/u02/app/oracle/oradata/boston/undotbs01.dbf tag=TAG20080519T173421 RECID=0 STAMP=0
channel prmy3: datafile copy complete, elapsed time: 00:00:24
output file name=/u02/app/oracle/oradata/boston/users01.dbf tag=TAG20080519T173421 RECID=0 STAMP=0
channel prmy4: datafile copy complete, elapsed time: 00:00:16
output file name=/u02/app/oracle/oradata/boston/system01.dbf tag=TAG20080519T173421 RECID=0 STAMP=0
channel prmy1: datafile copy complete, elapsed time: 00:02:32
output file name=/u02/app/oracle/oradata/boston/sysaux01.dbf tag=TAG20080519T173421 RECID=0 STAMP=0
channel prmy2: datafile copy complete, elapsed time: 00:02:32
Finished backup at 19-MAY-08

sql statement: alter system archive log current

contents of Memory Script:
{
switch clone datafile all;   ---------修改standby 控制文件,更新standby 控制文件中的新数据文件路径
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=2 STAMP=655148231 file name=/u02/app/oracle/oradata/boston/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=655148231 file name=/u02/app/oracle/oradata/boston/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=655148231 file name=/u02/app/oracle/oradata/boston/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=655148231 file name=/u02/app/oracle/oradata/boston/users01.dbf
Finished Duplicate Db at 19-MAY-08
released channel: prmy1
released channel: prmy2
released channel: prmy3
released channel: prmy4



到这里备库环境已经全部初始化完毕,免去了我们以前需要,手动在备库配置pfile参数文件,手动拷贝密码文件到备库,创建standby控制并拷贝到备库,拷贝数据文件备份到备库 等等步骤但是看到这里,还是有个疑惑的oracle 是怎么直接拷贝那些密码文件,参数文件,控制文件,数据文件到备库的?这里猜测应该是调用了rman 某些接口,说的直白点就是和nbu 那些第三方数据备份软件用的那一招,现在oracle自己觉得这些个接口也可以这么用,于是乎在11g(11.1.0.6 开始) 中推出了 active—database duplicate  关于这个feature oracle官方是这么讲的:
Active database duplication copies the live target database over the network to the auxiliary destination and then creates the duplicate database.
The duplication work is performed by an auxiliary channel.This channel corresponds to a server session on the auxiliary instance on the auxiliary host.


以下为 Basic Steps to  ACTIVE database duplication 过程中rman干的事情 :
As part of the duplicating operation, RMAN automates the following steps: 
1. Creates a control file for the duplicate database 
2. Restarts the auxiliary instance and mounts the duplicate control file 
3. Creates the duplicate datafiles and recovers them with incremental backups and archived redo logs. 
4. Opens the duplicate database with the RESETLOGS option 

oracle 11g RMAN:Active Database Duplication for standby database 创建dg 命令解读