一.使用RMAN convert将Oracle 从Windows(windows server 2008 R2)迁移到Linux(OLE 6.5)
官方文档关于RMAN CONVERT 解释(http://docs.oracle.com/cd/E11882_01/backup.112/e10642/rcmxplat.htm#BRADV89986)
Database Conversion
To convert a whole database to a different platform, both platforms must use the same endian format.
The RMAN CONVERT DATABASE command automates the movement of an entire database from a source platform to a destination platform.
The transported database contains the same data as the source database and also has, with a few exceptions, the same settings as the source database.
在不同平台转换整个库,两个平台必须包含相同字节顺序,RMAN CONVERT 命令会自动转换整个库从源平台到目标平台
Files automatically transported to the destination platform include:
Data files that belong to permanent tablespaces
Unlike transporting tablespaces across platforms, transporting entire databases requires that certain types of blocks, such as blocks in undo segments,
be reformatted to ensure compatibility with the destination platform. Even though the endian formats for the source and destination platforms are the same,
the data files for a transportable database must undergo a conversion process. You cannot simply copy data files from one platform to another as you can
when transporting tablespaces.
不同于跨平台传输表空间,将整个数据库要求某些类型的块,如块在撤销段,而为了确保与目标平台的兼容性,尽管在源和目标平台的字节序的格式是相同的,
一个可移动的数据库的数据文件必须经过转换过程。当传输表空间,你不能简单的复制数据文件从一个平台到另一个平台。
Initialization parameter file or server parameter file
初始化参数文件或者是服务参数文件
If the database uses a text-based initialization parameter file, then RMAN transports it. If the database uses a server parameter file,
then RMAN generates an initialization parameter file based on the server parameter file, transports it and creates a new server parameter
file at the destination based on the settings in the initialization parameter file.
Usually, some parameters in the initialization parameter file require manual updating for the new database. For example, you may change
the DB_NAME and parameters such as CONTROL_FILES that indicate the locations of files on the destination host.
You can convert the format of the data files either on the source platform or on the destination platform. The CONVERT DATABASE ON DESTINATION PLATFORM command does not convert the format of data files. Rather, it generates scripts that you can run manually to perform the conversion. The CONVERT SCRIPT parameter creates a convert script that you can manually execute at the destination host to convert data file copies in batch mode. The TRANSPORT SCRIPT parameter generates a transport script that contains SQL statements to create the new database on the destination platform.
1.搭建单实例环境(请参照)
源库环境
OS平台:WINDOWS 2008 R2
DB: Oracle 11.2.0.4(X64)
1. 在源库添加事例数据
SQL> create tablespace king datafile 'C:\APP\ADMINISTRATOR\ORADATA\NETDATA\king01.dbf' size 50M
表空间已创建。
SQL> create user king identified by king default tablespace king temporary tablespace temp;
用户已创建。
SQL> grant connect,resource to king;
授权成功。
SQL> conn king/king
已连接。
SQL> create table test (id int,name varchar2(20));
表已创建。
SQL> insert into test values(1,'test');
已创建 1 行。
SQL> insert into test values(2,'test1');
已创建 1 行。
SQL> commit;
提交完成。
SQL>
SQL>
SQL>
SQL> insert into test values(3,'test3');
已创建 1 行。
SQL>
SQL>
SQL> commit;
提交完成。
SQL> select * from test;
ID NAME
---------- ----------------------------------------
1 test
2 test1
3 test3
SQL> show user;
USER 为 "KING"
C:\Users\Administrator>sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on 星期五 6月 19 21:06:47 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select file_name from dba_data_files;
FILE_NAME
-------------------------------------------------------------------------------
C:\APP\ADMINISTRATOR\ORADATA\NETDATA\USERS01.DBF
C:\APP\ADMINISTRATOR\ORADATA\NETDATA\UNDOTBS01.DBF
C:\APP\ADMINISTRATOR\ORADATA\NETDATA\SYSAUX01.DBF
C:\APP\ADMINISTRATOR\ORADATA\NETDATA\SYSTEM01.DBF
C:\APP\ADMINISTRATOR\ORADATA\NETDATA\EXAMPLE01.DBF
C:\APP\ADMINISTRATOR\ORADATA\NETDATA\KING01.DBF
2. 查询源平台
SQL> select PLATFORM_NAME from v$database;
PLATFORM_NAME
--------------------------------------------------------------------------------
Microsoft Windows x86 64-bit
SQL>
SQL> select PLATFORM_NAME,ENDIAN_FORMAT from v$transportable_platform order by 1,2;
PLATFORM_NAME ENDIAN_FORMAT
-------------------------------------------------- ----------------------------
AIX-Based Systems (64-bit) Big
Apple Mac OS Big
Apple Mac OS (x86-64) Little
HP IA Open VMS Little
HP Open VMS Little
HP Tru64 UNIX Little
HP-UX (64-bit) Big
HP-UX IA (64-bit) Big
IBM Power Based Linux Big
IBM zSeries Based Linux Big
Linux IA (32-bit) Little
PLATFORM_NAME ENDIAN_FORMAT
-------------------------------------------------- ----------------------------
Linux IA (64-bit) Little
Linux x86 64-bit Little
Microsoft Windows IA (32-bit) Little
Microsoft Windows IA (64-bit) Little
Microsoft Windows x86 64-bit Little
Solaris Operating System (x86) Little
Solaris Operating System (x86-64) Little
Solaris[tm] OE (32-bit) Big
Solaris[tm] OE (64-bit) Big
已选择20行。
SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> startup mount
ORACLE 例程已经启动。
Total System Global Area 855982080 bytes
Fixed Size 2286032 bytes
Variable Size 549457456 bytes
Database Buffers 297795584 bytes
Redo Buffers 6443008 bytes
数据库装载完毕。
SQL> alter database open read only;
数据库已更改。
SQL> select open_mode from v$database;
OPEN_MODE
----------------------------------------
READ ONLY
3.转换之前检查
Execute the DBMS_TDB.CHECK_DB function.
This check ensures that no conditions would prevent the transport of the database,
such as incorrect compatibility settings, in-doubt or active transactions, or
incompatible endian formats between the source platform and destination platform.
用DBMS_TDB.CHECK_DB这个检查确保无条件将使数据库传输,如不正确的兼容性设置,有in-doubt或活跃的事务,或不相容的Endian格式之间的源平台和目标平台。
SQL> set serveroutput on
SQL> declare
2 v_check boolean;
3 begin
4 v_check:=dbms_tdb.check_db('Linux x86 64-bit',dbms_tdb.skip_none);
5 end;
6 /
PL/SQL 过程已成功完成。
Execute the DBMS_TDB.CHECK_EXTERNAL function to identify any external tables, directories, or BFILEs. RMAN cannot automate the transport of
these files, so you must copy the files manually and re-create the database directories.
执行DBMS_TDB.CHECK_EXTERNAL函数标识任何外部表,目录或者是BFILEs.这些都是RMAN不能自动转换的文件,因此你必须手动复制或者是重新这些数据库目录
SQL> declare
2 v_ext boolean;
3 begin
4 v_ext:=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.MEDIA_DIR, SYS.LOG_FILE_DIR, SYS.DATA_FILE_DIR, SYS.SS_OE_XMLDIR, SYS.SUBDIR, SYS.XMLDIR, SYS.ORACLE_OCM_CONFIG_DIR2, SYS.ORACLE_OCM_CONFIG_DIR, SYS.DATA_PUMP_DIR
The following BFILEs exist in the database:
PM.PRINT_MEDIA
PL/SQL 过程已成功完成。
4.使用RMAN CONVERT进行转换源DB
源端使用RMAN convert将数据文件转换成"Linux x86 64-bit"
RMAN> convert database new database 'netdata'
2> transport script 'c:\backup\trans.sql' to platform 'Linux x86 64-bit'
3> db_file_name_convert 'C:\app\Administrator\oradata\netdata' 'c:\backup';
启动 conversion at source 于 19-6月 -15
使用通道 ORA_DISK_1
在数据库中找到外部表 SH.SALES_TRANSACTIONS_EXT
在数据库中找到目录 SYS.SUBDIR
在数据库中找到目录 SYS.SS_OE_XMLDIR
在数据库中找到目录 SYS.MEDIA_DIR
在数据库中找到目录 SYS.LOG_FILE_DIR
在数据库中找到目录 SYS.DATA_FILE_DIR
在数据库中找到目录 SYS.XMLDIR
在数据库中找到目录 SYS.ORACLE_OCM_CONFIG_DIR2
在数据库中找到目录 SYS.ORACLE_OCM_CONFIG_DIR
在数据库中找到目录 SYS.DATA_PUMP_DIR
在数据库中找到 BFILE PM.PRINT_MEDIA
在口令文件中找到用户 SYS (具有 SYSDBA and SYSOPER 权限)
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件: 文件号=00001 名称=C:\APP\ADMINISTRATOR\ORADATA\NETDATA\SYSTEM01.DBF
已转换的数据文件 = C:\BACKUP\SYSTEM01.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:55
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件: 文件号=00002 名称=C:\APP\ADMINISTRATOR\ORADATA\NETDATA\SYSAUX01.DBF
已转换的数据文件 = C:\BACKUP\SYSAUX01.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:35
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件: 文件号=00005 名称=C:\APP\ADMINISTRATOR\ORADATA\NETDATA\EXAMPLE01.DBF
已转换的数据文件 = C:\BACKUP\EXAMPLE01.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:35
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件: 文件号=00003 名称=C:\APP\ADMINISTRATOR\ORADATA\NETDATA\UNDOTBS01.DBF
已转换的数据文件 = C:\BACKUP\UNDOTBS01.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:08
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件: 文件号=00006 名称=C:\APP\ADMINISTRATOR\ORADATA\NETDATA\KING01.DBF
已转换的数据文件 = C:\BACKUP\KING01.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:07
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件: 文件号=00004 名称=C:\APP\ADMINISTRATOR\ORADATA\NETDATA\USERS01.DBF
已转换的数据文件 = C:\BACKUP\USERS01.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:01
编辑 init.ora 文件 C:\APP\ADMINISTRATOR\PRODUCT\11.2.0\DBHOME_2\DATABASE\INIT_00Q9TGBE_1_0.ORA。此 PFILE 将用于在目标平台上创建数据库据
在目标平台上运行 SQL 脚本 C:\BACKUP\TRANS.SQL 以创建数据库
要重新编译所有 PL/SQL 模块, 请在目标平台上运行 utlirp.sql 和 utlrp.sql
要更改内部数据库标识符, 请使用 DBNEWID 实用程序
完成 conversion at source 于 19-6月 -15
5.转化后文件传输至目标DB服务器并为目标DB服务器创建服务器参数文件
将c:\backup下面转换的文件复制到目标服务器(Oracle Linux X64)
为目标机器创建参数文件
直接修改此文件C:\APP\ADMINISTRATOR\PRODUCT\11.2.0\DBHOME_2\DATABASE\INIT_00Q9TGBE_1_0.ORA
修改为如下并保存文件为initnetdata.ora:
*.__db_cache_size=335544320
netdata.__db_cache_size=167772160
*.__java_pool_size=4194304
netdata.__java_pool_size=20971520
*.__large_pool_size=4194304
netdata.__large_pool_size=8388608
netdata.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
*.__pga_aggregate_target=318767104
netdata.__pga_aggregate_target=381681664
*.__sga_target=541065216
netdata.__sga_target=478150656
*.__shared_io_pool_size=0
netdata.__shared_io_pool_size=0
*.__shared_pool_size=184549376
netdata.__shared_pool_size=268435456
*.__streams_pool_size=0
netdata.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/netdata/adump'
*.audit_trail='OS'
*.compatible='11.2.0.4.0'
*.control_files='/data/netdata/control01.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='netdata'
*.db_recovery_file_dest='/data/netdata/flash_recovery_area'
*.db_recovery_file_dest_size=4102029312
*.dispatchers='(PROTOCOL=TCP) (SERVICE=netdataXDB)'
*.memory_target=859832320
*.open_cursors=500
*.processes=500
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
6. 目标DB服务器创建所需目录用oracle用户创建。
mkdir -p /u01/app/oracle/admin/netdata/adump
mkdir -p /data/netdata/
mkdir -p /data/netdata/flash_recovery_area
7.恢复操作
[oracle@OLEASM1 dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on 星期三 6月 17 23:29:35 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
已连接到空闲例程。
利用创建的参数文件启动到nomount
SQL> startup nomount pfile='initnetdata.ora';
ORACLE 例程已经启动。
Total System Global Area 855982080 bytes
Fixed Size 2258040 bytes
Variable Size 671091592 bytes
Database Buffers 176160768 bytes
Redo Buffers 6471680 bytes
创建控制文件
CREATE CONTROLFILE REUSE SET DATABASE "netdata" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/data/netdata/redo01.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/data/netdata/redo02.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/data/netdata/redo03.log' SIZE 50M BLOCKSIZE 512
DATAFILE
'/data/netdata/SYSTEM01.DBF',
'/data/netdata/SYSAUX01.DBF',
'/data/netdata/UNDOTBS01.DBF',
'/data/netdata/USERS01.DBF',
'/data/netdata/EXAMPLE01.DBF',
'/data/netdata/KING01.DBF'
CHARACTER SET ZHS16GBK
resetlogs方式启动数据库,创建临时表空间
SQL> ALTER DATABASE OPEN RESETLOGS;
ALTER TABLESPACE TEMP ADD TEMPFILE '/data/netdata/temp01.dbf' SIZE 200M AUTOEXTEND ON next 20M maxsize 2G;
编译64位平台下的对象
SQL> SHUTDOWN IMMEDIATE
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> STARTUP UPGRADE
ORACLE instance started.
Total System Global Area 612368384 bytes
Fixed Size 2098208 bytes
Variable Size 167775200 bytes
Database Buffers 436207616 bytes
Redo Buffers 6287360 bytes
Database mounted.
Database opened.
SQL> @?/rdbms/admin/utlirp.sql
重新编译PL/SQL模块
SQL> SHUTDOWN IMMEDIATE
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> STARTUP
ORACLE instance started.
Total System Global Area 612368384 bytes
Fixed Size 2098208 bytes
Variable Size 167775200 bytes
Database Buffers 436207616 bytes
Redo Buffers 6287360 bytes
Database mounted.
Database opened.
SQL> @?/rdbms/admin/utlrp.sql
SQL> select name,platform_name,open_mode from v$database;
NAME
---------
PLATFORM_NAME
--------------------------------------------------------------------------------
OPEN_MODE
--------------------
NETDATA
Linux x86 64-bit
READ WRITE
转换完成!!!
其实这些操作步骤都传输脚本里面
c:\backup\trans.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='C:\APP\ADMINISTRATOR\PRODUCT\11.2.0\DBHOME_2\DATABASE\INIT_00Q9TGBE_1_0.ORA'
CREATE CONTROLFILE REUSE SET DATABASE "NETDATA" RESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 'C:\APP\ADMINISTRATOR\PRODUCT\11.2.0\DBHOME_2\DATABASE\ARCH_D-NETDATA_ID-376675875_S-4_T-1_A-882816102_03Q9TGBE' SIZE 50M BLOCKSIZE 512,
GROUP 2 'C:\APP\ADMINISTRATOR\PRODUCT\11.2.0\DBHOME_2\DATABASE\ARCH_D-NETDATA_ID-376675875_S-5_T-1_A-882816102_04Q9TGBE' SIZE 50M BLOCKSIZE 512,
GROUP 3 'C:\APP\ADMINISTRATOR\PRODUCT\11.2.0\DBHOME_2\DATABASE\ARCH_D-NETDATA_ID-376675875_S-6_T-1_A-882816102_05Q9TGBE' SIZE 50M BLOCKSIZE 512
DATAFILE
'C:\BACKUP\SYSTEM01.DBF',
'C:\BACKUP\SYSAUX01.DBF',
'C:\BACKUP\UNDOTBS01.DBF',
'C:\BACKUP\USERS01.DBF',
'C:\BACKUP\EXAMPLE01.DBF',
'C:\BACKUP\KING01.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 TEMP ADD TEMPFILE 'C:\APP\ADMINISTRATOR\PRODUCT\11.2.0\DBHOME_2\DATABASE\DATA_D-NETDATA_I-376675875_TS-TEMP_FNO-1_06Q9TGBE'
SIZE 30408704 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='C:\APP\ADMINISTRATOR\PRODUCT\11.2.0\DBHOME_2\DATABASE\INIT_00Q9TGBE_1_0.ORA'
@@ ?/rdbms/admin/utlirp.sql
SHUTDOWN IMMEDIATE
STARTUP PFILE='C:\APP\ADMINISTRATOR\PRODUCT\11.2.0\DBHOME_2\DATABASE\INIT_00Q9TGBE_1_0.ORA'
-- The following step will recompile all PL/SQL modules.
-- It may take serveral hours to complete.
@@ ?/rdbms/admin/utlrp.sql
set feedback 6;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24486203/viewspace-1705702/
,如需转载,请注明出处,否则将追究法律责任。