Duplicating an Active Database

0    320    1

Tags:

👉 本文共约11229个字,系统预计阅读时间或需43分钟。

    1. duplicate体系结构

搞点英语出来吧,英语不好的哥们就好好翻译翻译吧,这段英语是必须看懂的。。。。

You can duplicate a source database to a destination database, which can be on the same or different computers. The database instance associated with the duplicate database is called the auxiliary instance. All duplication techniques require a connection to the auxiliary instance. The diagram shows you the following techniques for database duplication:

  • From an active database, connected to the target and auxiliary instances
  • From backup, connected to the target and auxiliary instances
  • From backup, connected to the auxiliary instance, not connected to the target, but with recovery catalog connection
  • From backup, connected to the auxiliary instance, not connected to the target and the recovery catalog

Choosing a technique to duplicate your database—always with connection to the auxiliary instance:

img

简单点就是 ①基于备份 ,而基于备份又分为3种情况 ②基于活动数据库

  1. 本次实验简介

本次实验就是基于active database的duplicate技术。

Active database duplication 通过网络,直接copy target 库到auxiliary 库,然后创建复制库。 这种方法就不需要先用RMAN 备份数据库,然后将备份文件发送到auxiliary端。这个功能的作用是非常大的。 尤其是对T级别的库。 因为对这样的库进行备份,然后将备份集发送到备库,在进行duplicate 的代价是非常大的。 一备份要占用时间,二要占用备份空间,三在网络传送的时候,还需要占用带宽和时间。所以Active database duplicate 很好的解决了以上的问题。 它对大库的迁移非常有用。

  1. 本次实验原理

img

  1. 环境及搭建要求

环境:

  • 源数据库和目标数据库服务器:RHEL6.5
  • RMAN客户端:windows 7 系统下的rman client
  • source host : 192.168.59.129 sid:orcl database:11gR2
  • Destination host :192.168.59.133 sid:orcl database:11gR2

注意事项说明:

  • 这里的duplicate database 和 source database 的目录结构完全一样
  • 源数据库和辅助数据库的几种不同名称:source/target database ---->>>>>----- (destination host)/duplicate database (auxiliary instance)
  • 这里我利用了windows下的rman client来连接目标和辅助数据库,当然也可以利用目标库或者辅助库的rman client来操作
  • 目标数据库应该处于归档模式

source database环境:

SQL> select * from v$version;

BANNER

--------------------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

PL/SQL Release 11.2.0.1.0 - Production

CORE 11.2.0.1.0 Production

TNS for Linux: Version 11.2.0.1.0 - Production

NLSRTL Version 11.2.0.1.0 - Production

  1. 对辅助数据库的要求

辅助数据库应该提前安装好数据库,配置好环境变量。。。。。你懂的。。。。

辅助数据库的环境变量配置:

[root@rhel6 ~]# su - oracle

[oracle@rhel6 ~]$ more .bash_profile

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

# User specific environment and startup programs

export PATH=$PATH:/sbin/:$HOME/bin

# for oracle user

unset USERNAME

export GLOBAL_DB_UNIQUE_NAME=orcl

export ORACLE_HOSTNAME=192.168.59.133

export ORACLE_UNQNAME=orcl

export EDITOR=vi

export ORACLE_SID=orcl

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib

export PATH=$ORACLE_HOME/bin:$PATH

umask 022

#export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"

export SQLPATH=$ORACLE_HOME/sqlplus/admin

alias sqlplus='rlwrap sqlplus'

alias rman='rlwrap rman'

alias asmcmd='rlwrap asmcmd'

alias alert_log='tail -200f $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLESID/trace/alert$ORACLE_SID.log'

alias alert_xml='tail -200f $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/alert/log.xml'

alias alert_listener='tail -200f $ORACLE_BASE/diag/tnslsnr/rhel6/listener/trace/listener.log'

[oracle@rhel6 ~]$

  1. 正式开始

    1. duplicate database 设置

首先在duplicate database上进行设置:

  1. 创建pfile 参数文件

[oracle@rhel6 ~]$ cd $ORACLE_HOME/dbs

[oracle@rhel6 dbs]$ pwd

/u01/app/oracle/product/11.2.0/dbhome_1/dbs

[oracle@rhel6 dbs]$ ll -h

total 4.0K

-rw-r--r--. 1 oracle oinstall 2.8K May 15 2009 init.ora

[oracle@rhel6 dbs]$ vi initorcl.ora

[oracle@rhel6 dbs]$ more initorcl.ora

DB_NAME=orcl

[oracle@rhel6 dbs]$

截图:

img

  1. 创建密码文件

[oracle@rhel6 dbs]$ orapwd file=?/dbs/orapworcl password=lhr

[oracle@rhel6 dbs]$ ll -h

total 12K

-rw-r--r--. 1 oracle oinstall 2.8K May 15 2009 init.ora

-rw-r--r--. 1 oracle oinstall 13 Jul 20 16:03 initorcl.ora

-rw-r-----. 1 oracle oinstall 1.5K Jul 20 16:09 orapworcl

[oracle@rhel6 dbs]$

img

  1. 创建和source database的数据文件相关的目录结构

[oracle@rhel6 oracle]$ pwd

/u01/app/oracle

[oracle@rhel6 oracle]$ ll

total 8

drwxr-xr-x. 2 oracle oinstall 4096 May 18 17:14 checkpoints

drwxr-xr-x. 3 oracle oinstall 4096 May 18 16:04 product

[oracle@rhel6 oracle]$ mkdir -p /u01/app/oracle/oradata/orcl

[oracle@rhel6 oracle]$

img

不然在duplicate时会报如下错误:

ORA-19505: failed to identify file "/u01/app/oracle/oradata/orcl/users01.dbf"

ORA-27040: file create error, unable to create file

  1. 启动Auxiliary 到nomout 状态

[oracle@rhel6 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sun Jul 20 16:48:04 2014

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup nomount;

ORACLE instance started.

Total System Global Area 217157632 bytes

Fixed Size 2211928 bytes

Variable Size 159387560 bytes

Database Buffers 50331648 bytes

Redo Buffers 5226496 bytes

SQL>

img

  1. 在Target 和Auxiliary 都配置Oracle Net(Listener.ora and tnsnames.ora)

注意:

  • 对于Listener.ora 的配置需要配置成静态监听,何谓静态监听???哈哈百度吧。。。。
  • target和auxiliary都需要配置listener.ora和tnsnames.ora
  • 如果rman client不在target和auxiliary库上,那么也应该配置tnsnames.ora的

target database配置:

[oracle@rhel6 admin]$ more listener.ora

# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora

# Generated by Oracle configuration tools.

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.59.129)(PORT = 1521))

)

)

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(GLOBAL_DBNAME = orcl.lhr.com)

(SID_NAME = orcl)

(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)

)

(SID_DESC =

(GLOBAL_DBNAME = rman.lhr.com)

(SID_NAME = rman)

(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)

)

)

[oracle@rhel6 admin]$ more tnsnames.ora

orcl =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.59.129)(PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = orcl.lhr.com)

)

)

lhr_dup =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.59.133)(PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = orcl)

)

)

img

img

auxiliary database 配置:

[oracle@rhel6 admin]$ more listener.ora

# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora

# Generated by Oracle configuration tools.

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.59.133)(PORT = 1521))

)

)

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(GLOBAL_DBNAME = orcl)

(SID_NAME = orcl)

(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)

)

)

ADR_BASE_LISTENER = /u01/app/oracle

[oracle@rhel6 admin]$ more tnsnames.ora

orcl =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.59.129)(PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = orcl.lhr.com)

)

)

lhr_dup =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.59.133)(PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = orcl)

)

)

img

img

  1. 测试网络是否配置好

配置好网络后,首先测试一下源数据库和duplicate数据库是否可以连接上,如果不能正常连接说明listener和tnsnames没有配置正确:

----------------源数据库

C:\Users\Administrator>sqlplus sys/lhr@orcl as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 星期日 7月 20 17:55:58 2014

Copyright (c) 1982, 2010, Oracle. All rights reserved.

连接到:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>exit

----------------duplicate数据库

C:\Users\Administrator>sqlplus sys/lhr@lhr_dup as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 星期日 7月 20 17:41:28 2014

Copyright (c) 1982, 2010, Oracle. All rights reserved.

连接到:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> exit

从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options 断开

如果没有配置好的话,可能在后边执行duplicate命令的时候报错:

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: Duplicate Db 命令 (在 07/20/2014 17:28:11 上) 失败

RMAN-03015: 在存储的脚本Memory Script中出现错误

RMAN-03009: backup 命令 (ORA_DISK_1 通道上, 在 07/20/2014 17:28:11 上) 失败

ORA-17629: 无法连接到远程数据库服务器

ORA-17627: ORA-12154: TNS: 无法解析指定的连接标识符

ORA-17629: 无法连接到远程数据库服务器

img

  1. 开始RMAN duplicate from active database

注意:如果target 和 Auxiliary库的目录结构相同,记得加上nofilenamecheck参数,不然会报如下错误:

RMAN-05001: auxiliary file name /u01/app/oracle/oradata/orcl/users01.dbf conflicts with a file used by the target database

这里我利用的是本机电脑,即windows 7 系统上的rman client 来演示的。。。。。

C:\Users\Administrator>rman target sys/lhr@orcl auxiliary sys/lhr@lhr_dup

恢复管理器: Release 11.2.0.1.0 - Production on 星期日 7月 20 17:46:11 2014

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

连接到目标数据库: ORCL (DBID=1379935487)

已连接到辅助数据库: ORCL (未装载)

RMAN> duplicate target database to orcl from active database nofilenamecheck;

启动 Duplicate Db 于 20-7月 -14

使用目标数据库控制文件替代恢复目录

分配的通道: ORA_AUX_DISK_1

通道 ORA_AUX_DISK_1: SID=19 设备类型=DISK

内存脚本的内容:

{

sql clone "alter system set db_name =

''ORCL'' comment=

''Modified by RMAN duplicate'' scope=spfile";

sql clone "alter system set db_unique_name =

''ORCL'' comment=

''Modified by RMAN duplicate'' scope=spfile";

shutdown clone immediate;

startup clone force nomount

backup as copy current controlfile auxiliary format '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/cntrlorcl.dbf';

alter clone database mount;

}

正在执行内存脚本

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

sql 语句: alter system set db_unique_name = ''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle 实例已关闭

本人提供Oracle(OCP、OCM)、MySQL(OCP)、PostgreSQL(PGCA、PGCE、PGCM)等数据库的培训和考证业务,私聊QQ646634621或微信dbaup66,谢谢!
AiDBA后续精彩内容已被站长无情隐藏,请输入验证码解锁本文!
验证码:
获取验证码: 请先关注本站微信公众号,然后回复“验证码”,获取验证码。在微信里搜索“AiDBA”或者“dbaup6”或者微信扫描右侧二维码都可以关注本站微信公众号。

标签:

Avatar photo

小麦苗

学习或考证,均可联系麦老师,请加微信db_bao或QQ646634621

您可能还喜欢...

发表回复