--环境:
--目标数据库: orcl 10.10.10.8
--辅助数据库: test 10.10.10.7
$ cat /etc/issue
CentOS release 6.8 (Final)
Kernel \r on an \m
SQL> select * from v$version where rownum<2;
BANNER
----------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
- 备份目标数据库并复制备份到新库相同目录
RMAN> backup database include current controlfile plus archivelog delete input;
复制上面的备份到新库的相同位置中(注必须复制到新库,且为相同目录才行!!)
$ cd /oracle/fast_recovery_area/
$ tar zcvf orcl.tar.gz ORCL
$ scp orcl.tar.gz oracle@10.10.10.7:/oracle/fast_recovery_area/
备库
$ tar zxvf orcl.tar.gz
- 创建相应的dump文件夹
$ cd /oracle
$ mkdir -p oradata/test
$ mkdir -p fast_recovery_area/test
$ mkdir -p admin/test/adump
$ mkdir -p admin/test/dpdump
$ mkdir -p admin/test/pfile
- 配置辅助实例参数文件
原库执行
SQL> create pfile='/oracle/inittest.ora' from spfile;
$ vim /oracle/inittest.ora
test.__db_cache_size=125829120
test.__java_pool_size=4194304
test.__large_pool_size=8388608
test.__oracle_base='/oracle'#ORACLE_BASE set from environment
test.__pga_aggregate_target=192937984
test.__sga_target=293601280
test.__shared_io_pool_size=0
test.__shared_pool_size=146800640
test.__streams_pool_size=0
*.audit_file_dest='/oracle/admin/test/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/oracle/oradata/test/control01.ctl','/oracle/fast_recovery_area/test/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='test'
*.db_recovery_file_dest='/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.db_unique_name='test'
*.diagnostic_dest='/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.local_listener='(ADDRESS = (PROTOCOL=TCP)(HOST=10.10.10.7)(PORT=1521)(SID=test))'
*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST
MANDATORY Valid_for=(all_logfiles, all_roles)'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=486539264
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*.db_file_name_convert=('/oracle/oradata/orcl','/oracle/oradata/test')
*.log_file_name_convert=('/oracle/oradata/orcl','/oracle/oradata/test')
$ scp inittest.ora oracle@10.10.10.7:/oracle/product/11.2.0/dbhome_1/dbs/
生成辅助实例密码文件
$ orapwd file=$ORACLE_HOME/dbs/orapwtest password=oracle
配置网络
- 原库监听
$ cat listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /oracle/product/11.2.0/dbhome_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /oracle/product/11.2.0/dbhome_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.8)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXPROC0))
)
)
$ cat tnsnames.ora
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.8)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ORCL)
)
)
TEST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.7)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = TEST)
)
)
- 配置新库监听
$ cat listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /oracle/product/11.2.0/dbhome_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = test)
(ORACLE_HOME = /oracle/product/11.2.0/dbhome_1)
(SID_NAME = test)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.7)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXPROC0))
)
)
分别重启监听:
$ lsnrctl reload
在主库测试下:
$ tnsping test
$ tnsping orcl
启动新库到nomount:
$ export ORACLE_SID=test
$ sqlplus / as sysdba
SQL> startup nomount
主库操作
$ rman target sys/oracle@orcl auxiliary sys/oracle@test
Recovery Manager: Release 11.2.0.4.0 - Production on Fri Oct 19 10:36:09 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1516310366)
connected to auxiliary database: TEST (not mounted)
RMAN> duplicate target database to "test";
验证克隆的结果
$ export ORACLE_SID=test
$ sqlplus / as sysdba
SQL> select name,dbid,open_mode from v$database; -->使用了与之前数据库不同的dbid
NAME DBID OPEN_MODE
--------- ---------- --------------------
TEST 2292457546 READ WRITE