辅助数据库是为了某种测试目的,来创建的和某一个时刻的目标数据库完全一样的数据库;

1.目标数据库和辅助数据库的环境描述

 一般来说,目标数据库和辅助数据库应该分别存放在不同的服务器上;

 要求,存放辅助数据库的服务器上,安装有和目标库完全一样版本的数据库软件即可;

 目标库和辅助数据库要有网络连接

 目标数据库:
  ORACLE_SID=orcl11g
  IP_ADDRESS:192.168.3.253

 辅助数据库:
  ORACLE_SID=aux
  IP_ADDRESS:192.168.3.253

2.为辅助数据库创建密码文件

 [oracle@db253 dbs]$ cd $ORACLE_HOME/dbs
 [oracle@db253 dbs]$ orapwd file=orapwaux password=oracle

3.为辅助数据库创建参数文件

SYS@orcl11g> create pfile='?/dbs/initaux.ora' from spfile;
 --这条语句中“?”表示$ORACLE_HOME

 File created.

 [oracle@db253 dbs]$ ll -h initaux.ora
 -rw-r--r-- 1 oracle oinstall 1.4K Jun 26 14:13 initaux.ora

 [oracle@db253 dbs]$ vi initaux.ora 
[oracle@db253 dbs]$ cat initaux.ora 
orcl11g.__db_cache_size=50331648
orcl11g.__java_pool_size=4194304
orcl11g.__large_pool_size=4194304
orcl11g.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl11g.__pga_aggregate_target=171966464
orcl11g.__sga_target=251658240
orcl11g.__shared_io_pool_size=0
orcl11g.__shared_pool_size=159383552
orcl11g.__streams_pool_size=4194304
*._allow_resetlogs_corruption=TRUE
*.audit_file_dest='/u01/app/oracle/admin/aux/adump'
*.audit_trail='OS'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/aux/control01.ctl'
*.db_16k_cache_size=20971520
*.db_block_size=8192
*.db_domain='neves.com'
*.db_name='aux'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4322230272
*.diagnostic_dest='/u01/app/oracle'
*.log_archive_dest_1='location=/u01/app/oracle/aux'
*.memory_target=422576128
*.nls_date_format='yyyy-mm-dd hh24:mi:ss'
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.remote_os_authent=FALSE
*.resource_limit=TRUE
*.sessions=170
*.undo_tablespace='UNDOTBS2'
db_file_name_convert='/u01/app/oracle/oradata/orcl11g/','/u01/app/oracle/oradata/aux/'
log_file_name_convert='/u01/app/oracle/oradata/orcl11g/','/u01/app/oracle/oradata/aux/'

4.创建辅助数据库需要的路径
 [oracle@db253 dbs]$ mkdir /u01/app/oracle/oradata/aux
 [oracle@db253 dbs]$ mkdir /u01/app/oracle/admin/aux/adump -pv
mkdir: created directory `/u01/app/oracle/admin/aux'
mkdir: created directory `/u01/app/oracle/admin/aux/adump'

5.启动aux实例
 [oracle@db253 trace]$ export ORACLE_SID=aux
 [oracle@db253 trace]$ sqlplus / as sysdba
SYS@aux> create spfile from pfile;
SYS@aux> startup nomount;
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORACLE instance started.

Total System Global Area  422670336 bytes
Fixed Size                  1345380 bytes
Variable Size             255854748 bytes
Database Buffers          159383552 bytes
Redo Buffers                6086656 bytes

6.为目标数据库和辅助数据库配置静态监听
 [oracle@db253 admin]$ cd $ORACLE_HOME/network/admin
 [oracle@db253 admin]$ cat listener.ora
LISTENER=
  (DESCRIPTION=
    (ADDRESS_LIST=
      (ADDRESS=(PROTOCOL=tcp)(HOST=db253.neves.com)(PORT=1521))
    )
  )
SID_LIST_LISTENER=
  (SID_LIST=
    (SID_DESC=
      (GLOBAL_DBNAME=orcl11g.neves.com)
      (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db)
      (SID_NAME=orcl11g)
    )
    (SID_DESC=
      (GLOBAL_DBNAME=aux.neves.com)
      (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db)
      (SID_NAME=aux)
    )
  )

 [oracle@db253 admin]$ lsnrctl status
 。。。。。。
 Services Summary...
Service "aux.neves.com" has 2 instance(s).
  Instance "aux", status UNKNOWN, has 1 handler(s) for this service...
  Instance "aux", status BLOCKED, has 1 handler(s) for this service...
Service "orcl11g.neves.com" has 2 instance(s).
  Instance "orcl11g", status UNKNOWN, has 1 handler(s) for this service...
  Instance "orcl11g", status READY, has 1 handler(s) for this service...

7.配置本地服务名
 [oracle@db253 admin]$ vi tnsnames.ora
ORCL11G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = db253.neves.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl11g.neves.com)
    )
  )

AUX =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = db253.neves.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = aux.neves.com)
    )
  )

 可以通过tnsping命令检验:
  [oracle@db253 admin]$ tnsping aux
  [oracle@db253 admin]$ tnsping orcl11g

 在通过sqlplus连接校验一下:
  [oracle@db253 admin]$ sqlplus sys/oracle@orcl11g as sysdba
  [oracle@db253 admin]$ sqlplus sys/oracle@aux as sysdba

8.目标数据库备份

 [oracle@db253 admin]$ rman target sys/oracle@orcl11g

 RMAN> sql 'alter system archive log current';
 RMAN> backup as compressed backupset database plus archivelog;

9.使用duplicate命令来复制辅助数据库

 [oracle@db253 admin]$ rman target sys/oracle@orcl11g auxiliary sys/oracle@aux

Recovery Manager: Release 11.2.0.3.0 - Production on Wed Jun 26 14:48:55 2013

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

connected to target database: ORCL11G (DBID=923506654)
connected to auxiliary database: AUX (not mounted)

 --一定要把备份文件,拷贝到aux所在的服务器上的对应目录

 RMAN> run{
 2> allocate auxiliary channel aux1 device type disk;
 3> duplicate target database to aux;
 4> }

10.校验auxiliary database
 [oracle@db253 admin]$ sqlplus sys/oracle@aux as sysdba

SYS@aux> select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
aux              OPEN