RMAN之CONVERT整库迁移

来源:这里教程网 时间:2026-03-03 16:02:46 作者:

参考链接: http://blog.itpub.net/29101923/viewspace-1431795/

rman 中的 convert 命令同样可以迁移数据文件,表空间和整个数据库,此处演示整库迁移的过程:

 

查看一下支持 convert 有哪些平台:

 

SQL> select PLATFORM_NAME,ENDIAN_FORMAT from v$DB_TRANSPORTABLE_PLATFORM;

 

PLATFORM_NAME                            ENDIAN_FORMAT

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

Microsoft Windows IA (32-bit)            Little

Linux IA (32-bit)                        Little

HP Tru64 UNIX                            Little

Linux IA (64-bit)                        Little

HP Open VMS                              Little

Microsoft Windows IA (64-bit)            Little

Linux 64-bit for AMD                     Little

Microsoft Windows 64-bit for AMD         Little

Solaris Operating System (x86)           Little

9 rows selected.

 

将源库置于 READ ONLY

 

SQL> startup open read only;

ORACLE instance started.

 

Total System Global Area  167772160 bytes

Fixed Size                  1218316 bytes

Variable Size             100665588 bytes

Database Buffers           62914560 bytes

Redo Buffers                2973696 bytes

Database mounted.

Database opened.

 

检查是否支持跨平台传输:

SQL> ed

 1  declare

  2  db_ready boolean;

  3  begin

  4  db_ready := dbms_tdb.check_db('Linux IA (32-bit)', 2);

  5  if(db_ready) then

  6  dbms_output.put_line('true');

  7  else

  8  dbms_output.put_line('false');

  9  end if;

 10* end;

 

SQL> set serverout on;

SQL> /

true

PL/SQL procedure successfully completed.

返回 true 视为正确

 

检查是否存在外部对象:

SQL> declare

  2  external boolean;

  3  begin

  4  external := dbms_tdb.check_external;

  5  end;

  6  /

 

The following external tables exist in the database:

SH.SALES_TRANSACTIONS_EXT

The following directories exist in the database:

SYS.EXPDP_DIR2, SYS.EXPDP_DIR, SYS.DATA_PUMP_DIR, SYS.SUBDIR, SYS.XMLDIR, SYS.MEDIA_DIR,

SYS.LOG_FILE_DIR, SYS.DATA_FILE_DIR, SYS.WORK_DIR, SYS.ADMIN_DIR

The following BFILEs exist in the database:

PM.PRINT_MEDIA

PL/SQL procedure successfully completed.

 

以上输出的对象将不会传输到新的数据库,如果有必要就需 DBA 手工的将这些对象创建到新的数据库中

 

执行整库转换:

 

RMAN> convert database new database 'orcl2'

2> transport script '/u01/rman_convert/whole_db_script.sql'

3> to platform 'Linux IA (32-bit)'

4> db_file_name_convert '/u01/app/oracle/oradata/orcl' '/u01/app/oracle/oradata/orcl2'

5> ;

 

.

.

.

channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:04

Run SQL script /u01/rman_convert/whole_db_script.sql on the target platform to create database

Edit init.ora file /u01/app/oracle/10.2.0/db_1/dbs/init_00p5armv_1_0.ora. This PFILE will be used to create the database on the target platform

To recompile all PL/SQL modules, run utlirp.sql and utlrp.sql on the target platform

To change the internal database identifier, use DBNEWID Utility

Finished backup at 09-APR-14

 

 

创建数据文件和 trace 文件的存储路径:

 

[oracle@localhost ~]$ mkdir -p /u01/app/oracle/oradata/orcl2

[oracle@localhost ~]$ mkdir -p /u01/app/oracle/admin/orcl2/{a,b,c,u}dump

 

 

将所以的转换文件和执行脚本复制到目标数据库:

 

[oracle@localhost ~]$ scp 10.37.100.100:/u01/app/oracle/oradata/orcl2/* /u01/app/oracle/oradata/orcl2/

oracle@10.37.100.100's password: 

example01.dbf                                       100%  100MB  16.7MB/s   00:06    

sysaux01.dbf                                         100%  330MB  13.8MB/s   00:24    

system01.dbf                                         100%  500MB  11.4MB/s   00:44    

tts01.dbf                                              100%   20MB  20.0MB/s   00:01    

tts02.dbf                                              100%   20MB  20.0MB/s   00:00    

undotbs001.dbf                                     100%  100MB  14.3MB/s   00:07    

users01.dbf                                           100%  183MB  15.2MB/s   00:12  

 

[oracle@localhost ~]$ scp 10.37.100.100:/u01/rman_convert/* /u01/rman_convert/

oracle@10.37.100.100's password: 

whole_db_script.sql                              100%  2853     2.8KB/s   00:00  

 

[oracle@localhost ~]$ scp 10.37.100.100:/u01/app/oracle/10.2.0/db_1/dbs/init_00p5armv_1_0.ora /u01/rman_convert/

oracle@10.37.100.100's password: 

init_00p5armv_1_0.ora                         100%  1540     1.5KB/s   00:00    

 

修改 cupy 过来的参数文件:

[oracle@localhost ~]$ cp /u01/rman_convert/init_00p5armv_1_0.ora /u01/rman_convert/init_orcl2.ora

 

[oracle@localhost ~]$ vi /u01/rman_convert/init_orcl2.ora

将相关路径修改成自己的配置:

主要的有以下几个:

  control_files            = "/u01/app/oracle/oradata/orcl2/control01.ctl","/u01/app/oracle/oradata/orcl2/control02.ctl","/u01/app/oracle/oradata/orcl2/control03.ctl"

 

  db_recovery_file_dest    = "/u01/app/oracle/flash_recovery_area/orcl2"

  db_recovery_file_dest_size = 5368709120

  background_dump_dest     = "/u01/app/oracle/admin/orcl2/bdump"

  user_dump_dest           = "/u01/app/oracle/admin/orcl2/udump"

  core_dump_dest           = "/u01/app/oracle/admin/orcl2/cdump"

  audit_file_dest          = "/u01/app/oracle/admin/orcl2/adump"

  db_name                  = "ORCL2"

 

修改需要执行的脚本:(也可按照脚本一步一步去修改执行)

 

-- The following commands will create a new control file and use it

-- to open the database.

-- Data used by Recovery Manager will be lost.

-- The contents of online logs will be lost and all backups will

-- be invalidated. Use this only if online logs are damaged.

 

-- After mounting the created controlfile, the following SQL

-- statement will place the database in the appropriate

-- protection mode:

--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE

 

STARTUP NOMOUNT PFILE='/u01/rman_convert/init_orcl2.ora'

CREATE CONTROLFILE REUSE SET DATABASE "ORCL2" RESETLOGS FORCE LOGGING ARCHIVELOG

    MAXLOGFILES 16

    MAXLOGMEMBERS 3

    MAXDATAFILES 100

    MAXINSTANCES 8

    MAXLOGHISTORY 292

LOGFILE

  GROUP 1 '/u01/app/oracle/oradata/orcl2/redo01.log'  SIZE 50M,

  GROUP 2 '/u01/app/oracle/oradata/orcl2/redo02.log'  SIZE 50M,

  GROUP 3 '/u01/app/oracle/oradata/orcl2/redo03'  SIZE 50M

DATAFILE

  '/u01/app/oracle/oradata/orcl2/system01.dbf',

  '/u01/app/oracle/oradata/orcl2/sysaux01.dbf',

  '/u01/app/oracle/oradata/orcl2/users01.dbf',

  '/u01/app/oracle/oradata/orcl2/example01.dbf',

  '/u01/app/oracle/oradata/orcl2/tts01.dbf',

  '/u01/app/oracle/oradata/orcl2/tts02.dbf',

  '/u01/app/oracle/oradata/orcl2/undotbs001.dbf'

CHARACTER SET WE8ISO8859P1

;

 

-- Database can now be opened zeroing the online logs.

ALTER DATABASE OPEN RESETLOGS;

 

-- Commands to add tempfiles to temporary tablespaces.

-- Online tempfiles have complete space information.

-- Other tempfiles may require adjustment.

ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/10.2.0/db_1/dbs/temp01.dbf'

     SIZE 22020096  AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;

-- End of tempfile additions.

--

 

set echo off

prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

prompt * Your database has been created successfully!

prompt * There are many things to think about for the new database. Here

prompt * is a checklist to help you stay on track:

prompt * 1. You may want to redefine the location of the directory objects.

prompt * 2. You may want to change the internal database identifier (DBID) 

prompt *    or the global database name for this database. Use the 

prompt *    NEWDBID Utility (nid).

prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

SHUTDOWN IMMEDIATE 

STARTUP UPGRADE PFILE='/u01/rman_convert/init_orcl2.ora'

@@ ?/rdbms/admin/utlirp.sql 

SHUTDOWN IMMEDIATE 

STARTUP PFILE='/u01/rman_convert/init_orcl2.ora'

-- The following step will recompile all PL/SQL modules.

-- It may take serveral hours to complete.

@@ ?/rdbms/admin/utlrp.sql 

set feedback 6;

 

修改脚本相对操作简单,但要认真,不然很出错后差错就麻烦了

 

设置新的环境变量,进入 SQL*plus 命令行

[oracle@localhost ~]$ export ORACLE_SID=orcl2

[oracle@localhost ~]$ sqlplus / as sysdba

 

执行修改后的脚本:

SQL> @/u01/rman_convert/whole_db_script.sql

 

期间会重启几次数据库,等待时间较长,要有耐心,尤其是这个时间点:

DOC>   1. Query showing jobs created by UTL_RECOMP

DOC>         SELECT job_name FROM dba_scheduler_jobs

DOC>            WHERE job_name like 'UTL_RECOMP_SLAVE_%';

DOC>

DOC>   2. Query showing UTL_RECOMP jobs that are running

DOC>         SELECT job_name FROM dba_scheduler_running_jobs

DOC>            WHERE job_name like 'UTL_RECOMP_SLAVE_%';

DOC>#

SQL> 

SQL> DECLARE

  2     threads pls_integer := &&1;

  3  BEGIN

  4     utl_recomp.recomp_parallel(threads);

  5  END;

  6  /

 

 

执行完成后测试结果: SQL> conn scott/oracle Connected. SQL> select tname from tab; TNAME ------------------------------ DEPT EMP BONUS SALGRADE TEST

此时数据库复制已经完成,需要的话别忘了去创建前面检查时不能签约的外部对象,配置口令文件和监听等。 以下是自己实践修改好的TRANSPORT.SQL内容: -- The following commands will create a new control file and use it -- to open the database. -- Data used by Recovery Manager will be lost. -- The contents of online logs will be lost and all backups will -- be invalidated. Use this only if online logs are damaged. -- After mounting the created controlfile, the following SQL -- statement will place the database in the appropriate -- protection mode: --  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE STARTUP NOMOUNT PFILE='/u01/app/oracle/product/11.2.0.4/db_1/dbs/initKQZH.ora' CREATE CONTROLFILE REUSE SET DATABASE "KQZH" RESETLOGS FORCE LOGGING ARCHIVELOG     MAXLOGFILES 48     MAXLOGMEMBERS 3     MAXDATAFILES 100     MAXINSTANCES 8     MAXLOGHISTORY 37376 LOGFILE   GROUP 1 ('/oradata/KQZH/redo01.log','/oradata/KQZH/redo01b.log') SIZE 50M BLOCKSIZE 512,   GROUP 2 ('/oradata/KQZH/redo02.log','/oradata/KQZH/redo02b.log') SIZE 50M BLOCKSIZE 512,   GROUP 7 '/oradata/KQZH/redo07.log'  SIZE 50M BLOCKSIZE 512,   GROUP 12 '/oradata/KQZH/redo12.log'  SIZE 50M BLOCKSIZE 512 DATAFILE   '/oradata/KQZH/SYSTEM01.DBF',   '/oradata/KQZH/SYSAUX01.DBF',   '/oradata/KQZH/UNDOTBS01.DBF',   '/oradata/KQZH/USERS01.DBF',   '/oradata/TABLESPACE/KQZH01.DBF',   '/oradata/TABLESPACE/KQZH15.DBF' CHARACTER SET AL32UTF8 ; -- Database can now be opened zeroing the online logs. ALTER DATABASE OPEN RESETLOGS UPGRADE; -- Commands to add tempfiles to temporary tablespaces. -- Online tempfiles have complete space information. -- Other tempfiles may require adjustment. ALTER TABLESPACE TMPKQZH1 ADD TEMPFILE '/oradata/TABLESPACE/TMPKQZH101.DBF' SIZE 471859200  AUTOEXTEND ON NEXT 52428800  MAXSIZE 10240M; ALTER TABLESPACE TEMP ADD TEMPFILE '/oradata/TABLESPACE/TEMP01.DBF' SIZE 471859200  AUTOEXTEND ON NEXT 52428800  MAXSIZE 10240M; -- End of tempfile additions. -- set echo off prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ prompt * Your database has been created successfully! prompt * There are many things to think about for the new database. Here prompt * is a checklist to help you stay on track: prompt * 1. You may want to redefine the location of the directory objects. prompt * 2. You may want to change the internal database identifier (DBID) prompt *    or the global database name for this database. Use the prompt *    NEWDBID Utility (nid). prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SHUTDOWN IMMEDIATE STARTUP UPGRADE PFILE='/u01/app/oracle/product/11.2.0.4/db_1/dbs/initKQZH.ora' @@ ?/rdbms/admin/utlirp.sql SHUTDOWN IMMEDIATE STARTUP PFILE='/u01/app/oracle/product/11.2.0.4/db_1/dbs/initKQZH.ora' -- The following step will recompile all PL/SQL modules. -- It may take serveral hours to complete. @@ ?/rdbms/admin/utlrp.sql set feedback 6;

相关推荐