加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

oracle数据迁移之跨平台迁移数据库

(2012-07-04 14:31:41)
标签:

杂谈

分类: oracle技术

    在Oracle10g中,不仅可以利用跨平台传输表空间的新特性在异构平台数据库之间迁移数据,在特定条件下,还可以利用Convert database特性进行整个数据库跨平台的迁移。
如果要在10G中进行全库跨平台的迁移,那么只能在endian的低位和低位或者高位和高位平台之间进行迁移,无法进行高位与低位平台的迁移。
大家可以参考V$TRANSPORTABLE_PLATFORM中的信息以决定是否能够迁移。

Convert database具体如下特性:
1、只传输数据表空间的数据文件。临时表空间将不会被传输,如果临时表空间是本地管理的话,那么传输数据库完成后将会自动在目标数据库创建临时表空间。
2、假如源数据库使用PFILE,那么PFILE也会被传输。如果源数据库使用的是SPFILE,将会自动产生一个PFILE进行传输,并在目标数据库生SPFILE。
3、 控制文件和联机日志文件将不会被传输。在目标数据库open resetlogs的过程中,将会自动创建控制文件和联机日志文件。
4、 BFILE、外部表和directory将不会被传输。RMAN检查的时候将会把这些对象列出,用户可以手工创建这些对象。
5、 密码文件将不会被传输,用户必须在目标数据库手工创建密码文件。

实验举例 linux系统to windows系统
SQL> col platform_name for a40
SQL> select * from v$transportable_platform order by 3;

PLATFORM_ID PLATFORM_NAME                            ENDIAN_FORMAT
----------- ---------------------------------------- --------------
          4 HP-UX IA (64-bit)                                   Big
          1 Solaris[tm] OE (32-bit)                            Big
         16 Apple Mac OS                                        Big
          3 HP-UX (64-bit)                                       Big
          9 IBM zSeries Based Linux                           Big
          6 AIX-Based Systems (64-bit)                       Big
          2 Solaris[tm] OE (64-bit)                            Big
         18 IBM Power Based Linux                           Big
         17 Solaris Operating System (x86)                 Little
         12 Microsoft Windows 64-bit for AMD             Little
         13 Linux 64-bit for AMD                              Little
          8 Microsoft Windows IA (64-bit)                  Little
         15 HP Open VMS                                        Little
          5 HP Tru64 UNIX                                      Little
         10 Linux IA (32-bit)                                   Little
          7 Microsoft Windows IA (32-bit)                   Little
         11 Linux IA (64-bit)                                   Little

17 rows selected.

检查数据库的操作系统平台,确认数据库文件和参数文件的位置
SQL> select platform_name from v$database;
PLATFORM_NAME
----------------------------------------
Linux IA (32-bit)

SQL> select name from v$datafile where rownum=1;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/db01/system01.dbf

SQL> show parameter spfile
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /u01/app/oracle/product/10.2.0/dbs/spfiledb01.ora

干净的关闭数据库,启动时使用read only 方式打开
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area  285212672 bytes
Fixed Size                  1218968 bytes
Variable Size             109053544 bytes
Database Buffers          167772160 bytes
Redo Buffers                7168000 bytes
Database mounted.
SQL> alter database open read only;
Database altered.

使用dbms_tdb包,提供正确的参数,检查数据库是否可以作为传输标的
SQL> DECLARE
           db_ready BOOLEAN;
         BEGIN
           db_ready := DBMS_TDB.CHECK_DB('Microsoft Windows IA (32-bit)');
         END;
         /

PL/SQL procedure successfully completed.

SQL>  DECLARE
            external BOOLEAN;
         BEGIN
           external := DBMS_TDB.CHECK_EXTERNAL;
         END;
         /
The following external tables exist in the database:
SH.SALES_TRANSACTIONS_EXT
The following directories exist in the database:
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.

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@buffer ~]$ ls
afiedt.buf  asmtool  backup  Desktop  install  workshop

使用rman的convert命令生成传输文件(包括数据文件、转换脚本和参数文件),并存放在目录backup下
[oracle@buffer ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Wed Apr 28 23:45:15 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: DB01 (DBID=1348011758)
RMAN> convert database new database 'orcl'
2>    transport script '/home/oracle/backup/transdb.sql'
3>    to platform 'Microsoft Windows IA (32-bit)'
4>    db_file_name_convert '/u01/app/oracle/oradata/db01' '/home/oracle/backup';

Starting convert at 28-APR-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=154 devtype=DISK
External table SH.SALES_TRANSACTIONS_EXT found in the database
Directory SYS.DATA_PUMP_DIR found in the database
Directory SYS.SUBDIR found in the database
Directory SYS.XMLDIR found in the database
Directory SYS.MEDIA_DIR found in the database
Directory SYS.LOG_FILE_DIR found in the database
Directory SYS.DATA_FILE_DIR found in the database
Directory SYS.WORK_DIR found in the database
Directory SYS.ADMIN_DIR found in the database

BFILE PM.PRINT_MEDIA found in the database

User SYS with SYSDBA and SYSOPER privilege found in password file
channel ORA_DISK_1: starting datafile conversion
input datafile fno=00001 name=/u01/app/oracle/oradata/db01/system01.dbf
converted datafile=/home/oracle/backup/system01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting datafile conversion
input datafile fno=00003 name=/u01/app/oracle/oradata/db01/sysaux01.dbf
converted datafile=/home/oracle/backup/sysaux01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:16
channel ORA_DISK_1: starting datafile conversion
input datafile fno=00002 name=/u01/app/oracle/oradata/db01/undotbs01.dbf
converted datafile=/home/oracle/backup/undotbs01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile conversion
input datafile fno=00005 name=/u01/app/oracle/oradata/db01/example01.dbf
converted datafile=/home/oracle/backup/example01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile conversion
input datafile fno=00004 name=/u01/app/oracle/oradata/db01/users01.dbf
converted datafile=/home/oracle/backup/users01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:01
Run SQL script /home/oracle/backup/transdb.sql on the target platform to create database
Edit init.ora file /u01/app/oracle/product/10.2.0/dbs/init_00lc9tkr_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 28-APR-10

RMAN> exit
Recovery Manager complete.
          new database表示目标数据库的名字
          transport script指定生成建库脚本的位置
          to platform表示目标数据库的平台,
          db_file_name_convert指定源数据库数据文件所在的位置以及转换后数据文件存放的目录。
          生成的PFILE为/u01/app/oracle/product/10.2.0/dbs/init_00lc9tkr_1_0.ora,需要格局目标数据库的具体目录进行编辑:

[oracle@buffer ~]$ cd backup
[oracle@buffer backup]$ ll
total 1004572
-rw-r-----  1 oracle oinstall 104865792 Apr 28 23:49 example01.dbf
-rw-r-----  1 oracle oinstall 272637952 Apr 28 23:48 sysaux01.dbf
-rw-r-----  1 oracle oinstall 513810432 Apr 28 23:48 system01.dbf
-rw-r--r--  1 oracle oinstall      2713 Apr 28 23:49 transdb.sql
-rw-r-----  1 oracle oinstall 131080192 Apr 28 23:48 undotbs01.dbf
-rw-r-----  1 oracle oinstall   5251072 Apr 28 23:49 users01.dbf
[oracle@buffer backup]$ cd /u01/app/oracle/product/10.2.0/dbs
[oracle@buffer dbs]$ ll
total 92
-rw-rw----  1 oracle oinstall  1271 Apr 26 16:39 ab_+ASM.dat
-rw-rw----  1 oracle oinstall  1544 Apr 19 15:52 hc_+ASM.dat
-rw-r-----  1 oracle oinstall  1544 Apr 19 15:26 hc_db01.dat
-rw-rw----  1 oracle oinstall  1544 Apr 19 15:57 hc_db02.dat
-rw-r--r--  1 oracle oinstall  1450 Apr 28 23:49 init_00lc9tkr_1_0.ora
-rw-r-----  1 oracle oinstall    34 Apr 19 16:25 initdb02.ora
-rw-r-----  1 oracle oinstall 12920 May  2001 initdw.ora
-rw-r-----  1 oracle oinstall  8385 Sep 11  1998 init.ora
-rw-rw----  1 oracle oinstall    24 Apr 19 15:52 lk+ASM
-rw-r-----  1 oracle oinstall    24 Apr 19 15:27 lkDB01
-rw-rw----  1 oracle oinstall    24 Apr 19 15:57 lkDB02
-rw-r-----  1 oracle oinstall  1536 Apr 19 15:52 orapw+ASM
-rw-r-----  1 oracle oinstall  1536 Apr 27 22:20 orapwdb01
-rw-r-----  1 oracle oinstall  1536 Apr 19 16:27 orapwdb02
-rw-r-----  1 oracle oinstall  7725 Apr 26 15:54 reorg1.sql
-rw-r-----  1 oracle oinstall  1536 Apr 19 15:54 spfile+ASM.ora
-rw-r-----  1 oracle oinstall  2560 Apr 28 23:44 spfiledb01.ora
传输backup目录下的所有文件到windows平台相应的目录(e:\oracle\oradata\orcl)
传输/u01/app/oracle/product/10.2.0/dbs/init_00lc9tkr_1_0.ora 到windows平台的相应的目录(E:\oracle\10.2.0\database),改名称为initorcl.ora
linux 平台部分工作完成。
####################################################################################

 

 

如果目标数据库是windows系统,使用oradim工具在目标数据库新创建一个ORACLE服务
使用orapwd工具创建口令文件
编辑参数文件和数据库创建文件,以满足windows系统的要求。

E:\>oradim -new -sid orcl -startmode manual
实例已创建。
E:\>set oracle_sid=orcl
E:\>orapwd file=E:\oracle\10.2.0\database\pwdorcl.ora password=oracle entries=5
E:\>sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 4月 29 00:35:52 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
已连接到空闲例程。
SQL> startup nomount
ORACLE 例程已经启动。
Total System Global Area  285212672 bytes
Fixed Size                  1248576 bytes
Variable Size              92275392 bytes
Database Buffers          188743680 bytes
Redo Buffers                2945024 bytes
SQL>
SQL> @E:\oracle\oradata\orcl\transdb
控制文件已创建。
数据库已更改。
表空间已更改。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Your database has been created successfully!
* There are many things to think about for the new database. Here
* is a checklist to help you stay on track:
* 1. You may want to redefine the location of the directory objects.
* 2. You may want to change the internal database identifier (DBID)
   or the global database name for this database. Use the
   NEWDBID Utility (nid).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

..........执行剩余的脚本然后退出,数据库迁移完成!

附:编辑的参数文件的内容如下
# Please change the values of the following parameters:

  control_files            = "e:\oracle\oradata\orcl\control01.dbf"
  db_recovery_file_dest    = "E:\oracle\flash_recovery_area"
  db_recovery_file_dest_size= 2147483648
  background_dump_dest     = "E:\oracle\admin\orcl/bdump"
  user_dump_dest           = "E:\oracle\admin\orcl/udump"
  core_dump_dest           = "E:\oracle\admin\orcl/cdump"
  audit_file_dest          = "E:\oracle\admin\orcl/adump"
  db_name                  = "ORCL"


# Please review the values of the following parameters:

  __shared_pool_size       = 96468992
  __large_pool_size        = 4194304
  __java_pool_size         = 4194304
  __streams_pool_size      = 4194304
  __db_cache_size          = 167772160
  remote_login_passwordfile= "EXCLUSIVE"
  db_domain                = ""
  dispatchers              = "(PROTOCOL=TCP) (SERVICE=db01XDB)"


# The values of the following parameters are from source database:

  processes                = 150
  sga_target               = 285212672
  db_block_size            = 8192
  compatible               = "10.2.0.1.0"
  db_file_multiblock_read_count= 16
  undo_management          = "AUTO"
  undo_tablespace          = "UNDOTBS1"
  job_queue_processes      = 10
  open_cursors             = 300
  pga_aggregate_target     = 94371840


编辑的transdb.sql文件如下

CREATE CONTROLFILE REUSE SET DATABASE "ORCL" RESETLOGS  NOARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 'e:\oracle\oradata\orcl\redo01.log'  SIZE 50M,
  GROUP 2 'e:\oracle\oradata\orcl\redo02.log'  SIZE 50M,
  GROUP 3 'e:\oracle\oradata\orcl\redo03.log'  SIZE 50M
DATAFILE
  'e:\oracle\oradata\orcl\system01.dbf',
  'e:\oracle\oradata\orcl\undotbs01.dbf',
  'e:\oracle\oradata\orcl\sysaux01.dbf',
  'e:\oracle\oradata\orcl\users01.dbf',
  'e:\oracle\oradata\orcl\example01.dbf'
CHARACTER SET ZHS16GBK
;

-- 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 'e:\oracle\oradata\orcl\temp01.dbf'
     SIZE 20971520  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
@@ ?/rdbms/admin/utlirp.sql
SHUTDOWN IMMEDIATE
STARTUP
-- The following step will recompile all PL/SQL modules.
-- It may take serveral hours to complete.
@@ ?/rdbms/admin/utlrp.sql
set feedback 6;

 

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有