Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7887
  • 博文数量: 2
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2014-10-08 09:14
文章分类
文章存档

2017年(2)

我的朋友
最近访客

分类: Oracle

2017-08-14 09:54:52


最近在给客户做一个项目的数据库迁移,虽然是一个比较简单的操作,但由于考虑到停机时间和数据库安全以及其他因素,项目部搞了很多方案比如导入导出方案,客户都觉得不是很满意。所以考虑使用直接把原数据库进行复制,但现象是两数据库版本不同,不知道有没有影响,以下是在同版本数据库的操作,供参考学习!

11gRMAN duplicate 个人感觉比10g的先进了很多,10G需要在rman备份的基础上进行复制,使用 RMAN duplicate 创建一个数据完全相同但DBID不同的数据库。而11gRMAN duplicate 可以通过Active database duplicateBackup-based duplicate两种方法实现。这里的测试使用的是Active database duplicate,因为Active database duplicate 功能强大,不需要先把目标数据库进行rman备份,只要目标数据库处于归档模式下即可直接通过网络对数据库进行copy,且copy完成后自动open数据库。这对于大数据特别是T级别的数据库来说优点非常明显,复制前不需要进行备份,减少了备份和传送备份的时间,同时节省备份空间。下面来进行具体的duplicate操作。

 

1、环境信息。由于是测试,且个人硬件限制,以下测试在同一机器不同数据库实例操作,和在异机操作没什么区别。

target DB

ip192.168.1.1

hostnameoracledba

oraclesidorcl

 

auxiliary DB

ip192.168.1.1

hostnameoracledba

oraclesidoradu

2、创建auxiliary DB参数文件,启动实例到nomount状态,我们可以使用target DBpfile进行修改使用,内容不需要太多,有相关目录能把实例启动到nomount即可,创建完成后pfile如下:

[root@oracledba dbs]# cat initoradu.ora

.audit_file_dest='/u01/app/oracle/admin/oradu/adump'

*.audit_trail='db'

*.compatible='11.2.0.0.0'

*.control_files='/u01/app/oracle/oradata/oradu/control01.ctl','/u01/app/oracle/fast_recovery_area/oradu/control02.ctl'

*.db_block_size=8192

*.db_name='oradu'

db_file_name_convert=('/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/oradu/')

log_file_name_convert=('/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/oradu/')

 

由于这里使用的是同一机器上的不同实例,所以必须添加db_file_name_convert和log_file_name_convert,否则在复制的时候会报错无法创建数据文件,如果是异机复制,且两数据目录完全一样的情况下,这两个参数可省略,由于测试在同一环境,所以db_name不能一样,如果是异机复制,db_name完全可以一样。

 

 

 

创建参数文件中的相关目录并修改所属:

[root@oracledba dbs]# mkdir /u01/app/oracle/oradata/oradu/ -pv

mkdir: created directory `/u01/app/oracle/oradata/oradu/'

[root@oracledba dbs]# mkdir /u01/app/oracle/fast_recovery_area/oradu/ -pv

mkdir: created directory `/u01/app/oracle/fast_recovery_area/oradu/'

chown oracle:oinstall /u01 -R

 

启动实例到nomount状态

SQL> startup nomount pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initoradu.ora';

ORACLE instance started.

 

Total System Global Area  238034944 bytes

Fixed Size                       2227136 bytes

Variable Size               180356160 bytes

Database Buffers       50331648 bytes

Redo Buffers                5120000 bytes

 

 

3、创建密码文件,必须保持target DBauxiliary DB的密码一致。这里我直接对target DB密码文件重命名使用

[root@oracledba dbs]# cp orapworcl orapworadu

 

4、配置网络,原因不解释,配置完成后如下

[root@oracledba dbs]# cat ../network/admin/listener.ora

SID_LIST_LISTENER =

  (SID_LIST =

         (SID_DESC =

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

                   (SID_NAME =orcl)

         )

         (SID_DESC =

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

                   (SID_NAME =oradu)

         )

  )

 

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

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

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

    )

  )

 

ADR_BASE_LISTENER = /u01/app/oracle

 

[root@oracledba dbs]# cat ../network/admin/tnsnames.ora

orcl =

  (DESCRIPTION =

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

  (CONNECT_DATA =

  (SERVER = DEDICATED)

  (SERVICE_NAME = orcl)

  ))

 

oradu =                 

  (DESCRIPTION =

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

  (CONNECT_DATA =

  (SERVER = DEDICATED)

  (SERVICE_NAME = oradu)

  ))

 

5、开始复制,复制时需要注意是否使用nofilenamecheck参数,如果两个实例相关数据目录结构完全相同,则需要指定,否则会报错。这里不需要使用。复制日志太多,有兴趣的可以看看,或者跳过直接看结果!

[oracle@oracledba ~]$ export ORACLE_SID=oradu    --------异机操作可省略此步操作

[oracle@oracledba ~]$rman target sys/oracle@orcl auxiliary sys/oracle@oradu

Recovery Manager: Release 11.2.0.3.0 - Production on Sat May 11 23:40:39 2013

 

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

 

connected to target database: ORCL (DBID=1342927075)

connected to auxiliary database: ORADU (not mount)

 

RMAN>duplicate target database to oradu from active database nofilenamecheck;----------这里应该使用下面命令复制,可以进行对比一下差别。

RMAN> duplicate target database to oradu from active database;

 

Starting Duplicate Db at 11-MAY-13

using channel ORA_AUX_DISK_1

 

contents of Memory Script:

{

   sql clone "create spfile from memory";

}

executing Memory Script

 

sql statement: create spfile from memory

 

contents of Memory Script:

{

   shutdown clone immediate;

   startup clone nomount;

}

executing Memory Script

 

Oracle instance shut down

 

connected to auxiliary database (not started)

Oracle instance started

 

Total System Global Area     238034944 bytes

 

Fixed Size                     2227136 bytes

Variable Size                180356160 bytes

Database Buffers              50331648 bytes

Redo Buffers                   5120000 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 =

 ''ORADU'' comment=

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

   shutdown clone immediate;

   startup clone force nomount

   backup as copy current controlfile auxiliary format  '/u01/app/oracle/oradata/oradu/control01.ctl';

   restore clone controlfile to  '/u01/app/oracle/fast_recovery_area/oradu/control02.ctl' from

 '/u01/app/oracle/oradata/oradu/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 =  ''ORADU'' comment= ''Modified by RMAN duplicate'' scope=spfile

 

Oracle instance shut down

 

Oracle instance started

 

Total System Global Area     238034944 bytes

 

Fixed Size                     2227136 bytes

Variable Size                180356160 bytes

Database Buffers              50331648 bytes

Redo Buffers                   5120000 bytes

 

Starting backup at 11-MAY-13

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=40 device type=DISK

channel ORA_DISK_1: starting datafile copy

copying current control file

output file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_orcl.f tag=TAG20130511T224515 RECID=2 STAMP=815179515

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

Finished backup at 11-MAY-13

 

Starting restore at 11-MAY-13

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=18 device type=DISK

 

channel ORA_AUX_DISK_1: copied control file copy

Finished restore at 11-MAY-13

 

database mounted

 

contents of Memory Script:

{

   set newname for datafile  1 to

 "/u01/app/oracle/oradata/oradu/system01.dbf";

   set newname for datafile  2 to

 "/u01/app/oracle/oradata/oradu/sysaux01.dbf";

   set newname for datafile  3 to

 "/u01/app/oracle/oradata/oradu/undotbs01.dbf";

   set newname for datafile  4 to

 "/u01/app/oracle/oradata/oradu/users01.dbf";

   backup as copy reuse

   datafile  1 auxiliary format

 "/u01/app/oracle/oradata/oradu/system01.dbf"   datafile

 2 auxiliary format

 "/u01/app/oracle/oradata/oradu/sysaux01.dbf"   datafile

 3 auxiliary format

 "/u01/app/oracle/oradata/oradu/undotbs01.dbf"   datafile

 4 auxiliary format

 "/u01/app/oracle/oradata/oradu/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 11-MAY-13

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf

output file name=/u01/app/oracle/oradata/oradu/system01.dbf tag=TAG20130511T224522

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:37

channel ORA_DISK_1: starting datafile copy

input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

output file name=/u01/app/oracle/oradata/oradu/sysaux01.dbf tag=TAG20130511T224522

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:37

channel ORA_DISK_1: starting datafile copy

input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

output file name=/u01/app/oracle/oradata/oradu/undotbs01.dbf tag=TAG20130511T224522

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:08

channel ORA_DISK_1: starting datafile copy

input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf

output file name=/u01/app/oracle/oradata/oradu/users01.dbf tag=TAG20130511T224522

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

Finished backup at 11-MAY-13

 

sql statement: alter system archive log current

 

contents of Memory Script:

{

   backup as copy reuse

   archivelog like  "/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2013_05_11/o1_mf_1_14_8rwpgonf_.arc" auxiliary format

 "/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_14_815146340.dbf"   ;

   catalog clone archivelog  "/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_14_815146340.dbf";

   switch clone datafile all;

}

executing Memory Script

 

Starting backup at 11-MAY-13

using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log copy

input archived log thread=1 sequence=14 RECID=10 STAMP=815179605

output file name=/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_14_815146340.dbf RECID=0 STAMP=0

channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01

Finished backup at 11-MAY-13

 

cataloged archived log

archived log file name=/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_14_815146340.dbf RECID=10 STAMP=815179607

 

datafile 1 switched to datafile copy

input datafile copy RECID=2 STAMP=815179607 file name=/u01/app/oracle/oradata/oradu/system01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=3 STAMP=815179607 file name=/u01/app/oracle/oradata/oradu/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=4 STAMP=815179607 file name=/u01/app/oracle/oradata/oradu/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=5 STAMP=815179607 file name=/u01/app/oracle/oradata/oradu/users01.dbf

 

contents of Memory Script:

{

   set until scn  1063454;

   recover

   clone database

    delete archivelog

   ;

}

executing Memory Script

 

executing command: SET until clause

 

Starting recover at 11-MAY-13

using channel ORA_AUX_DISK_1

 

starting media recovery

 

archived log for thread 1 with sequence 14 is already on disk as file /u01/app/oracle/product/11.2.0/db_1/dbs/arch1_14_815146340.dbf

archived log file name=/u01/app/oracle/product/11.2.0/db_1/dbs/arch1_14_815146340.dbf thread=1 sequence=14

media recovery complete, elapsed time: 00:00:00

Finished recover at 11-MAY-13

Oracle instance started

 

Total System Global Area     238034944 bytes

 

Fixed Size                     2227136 bytes

Variable Size                180356160 bytes

Database Buffers              50331648 bytes

Redo Buffers                   5120000 bytes

 

contents of Memory Script:

{

   sql clone "alter system set  db_name =

 ''ORADU'' 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

 

sql statement: alter system set  db_name =  ''ORADU'' 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     238034944 bytes

 

Fixed Size                     2227136 bytes

Variable Size                180356160 bytes

Database Buffers              50331648 bytes

Redo Buffers                   5120000 bytes

sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORADU" RESETLOGS ARCHIVELOG

  MAXLOGFILES     16

  MAXLOGMEMBERS      3

  MAXDATAFILES      100

  MAXINSTANCES     8

  MAXLOGHISTORY      292

 LOGFILE

  GROUP   1 ( '/u01/app/oracle/oradata/oradu/redo01.log' ) SIZE 50 M  REUSE,

  GROUP   2 ( '/u01/app/oracle/oradata/oradu/redo02.log' ) SIZE 50 M  REUSE,

  GROUP   3 ( '/u01/app/oracle/oradata/oradu/redo03.log' ) SIZE 50 M  REUSE

 DATAFILE

  '/u01/app/oracle/oradata/oradu/system01.dbf'

 CHARACTER SET AL32UTF8

 

 

contents of Memory Script:

{

   set newname for tempfile  1 to

 "/u01/app/oracle/oradata/oradu/temp01.dbf";

   switch clone tempfile all;

   catalog clone datafilecopy  "/u01/app/oracle/oradata/oradu/sysaux01.dbf",

 "/u01/app/oracle/oradata/oradu/undotbs01.dbf",

 "/u01/app/oracle/oradata/oradu/users01.dbf";

   switch clone datafile all;

}

executing Memory Script

 

executing command: SET NEWNAME

 

renamed tempfile 1 to /u01/app/oracle/oradata/oradu/temp01.dbf in control file

 

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/oradu/sysaux01.dbf RECID=1 STAMP=815179616

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/oradu/undotbs01.dbf RECID=2 STAMP=815179616

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/oradu/users01.dbf RECID=3 STAMP=815179616

 

datafile 2 switched to datafile copy

input datafile copy RECID=1 STAMP=815179616 file name=/u01/app/oracle/oradata/oradu/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=2 STAMP=815179616 file name=/u01/app/oracle/oradata/oradu/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=3 STAMP=815179616 file name=/u01/app/oracle/oradata/oradu/users01.dbf

 

contents of Memory Script:

{

   Alter clone database open resetlogs;

}

executing Memory Script

 

database opened

Finished Duplicate Db at 11-MAY-13

数据库复制完成。

 

6、检查结果

RMAN> exit

 

 

Recovery Manager complete.

[oracle@oracledba ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on Sat May 11 22:48:08 2013

 

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

 

 

Connected to:

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

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

 

SQL> select name from v$datafile;

 

NAME

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

/u01/app/oracle/oradata/oradu/system01.dbf

/u01/app/oracle/oradata/oradu/sysaux01.dbf

/u01/app/oracle/oradata/oradu/undotbs01.dbf

/u01/app/oracle/oradata/oradu/users01.dbf

 

SQL> select status from v$instance;

 

STATUS

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

OPEN

 

SQL> show parameter name

 

NAME                                       TYPE       VALUE

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

db_file_name_convert                 string     /u01/app/oracle/oradata/orcl/,

                                                          /u01/app/oracle/oradata/oradu/

                                                         

db_name                                string     ORADU

db_unique_name                          string     ORADU

global_names                        boolean         FALSE

instance_name                               string     oradu

lock_name_space                         string

log_file_name_convert                string     /u01/app/oracle/oradata/orcl/,

                                                          /u01/app/oracle/oradata/oradu/

                                              

 

NAME                                      TYPE       VALUE

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

processor_group_name                       string

service_names                                string     ORADU

SQL> show parameter pfile

 

NAME                                       TYPE       VALUE

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

spfile                                         string     /u01/app/oracle/product/11.2.0

                                                         /db_1/dbs/spfileoradu.ora

数据库已经open,各项参数正常,且已创建spfile并使用!整个复制过程完成!

阅读(997) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~