天天看點

使用RMAN Convert Database指令實作跨平台的資料庫遷移

  下面是一段使用RMAN Convert Database指令将Oracle 11.2.0.3 Database for Windows 64bit環境下的資料庫遷移到Oracle 11.2.0.3 Database for Linux 64bit的實驗。

1.以隻讀方式打開資料庫。

SQL> shutdown immediate

資料庫已經關閉。

已經解除安裝資料庫。

ORACLE 例程已經關閉。

SQL> startup mount

ORACLE 例程已經啟動。

Total System Global Area  304807936 bytes

Fixed Size                  2254704 bytes

Variable Size             104859792 bytes

Database Buffers          192937984 bytes

Redo Buffers                4755456 bytes

資料庫裝載完畢。

SQL> alter database open read only;

資料庫已更改。

2.檢查可轉換性和标示外部對象。

使用DBMS_TDB.CHECK_DB檢查資料庫狀态。

使用DBMS_TDB包的CHECK_DB函數檢查資料庫是否準備好了。

set serveroutput on

declare

    db_ready boolean;

  begin

    /* db_ready is ignored, but with SERVEROUTPUT set to ON any 

     * conditions preventing transport will be output to console */

    db_ready := dbms_tdb.check_db('Microsoft Windows IA (32-bit)',

        dbms_tdb.skip_none);

  end;

使用DBMS_TDB.CHECK_EXTERNAL辨別外部對象。

SQL> set serveroutput on

SQL> declare

     external boolean;

  begin

    /* value of external is ignored, but with SERVEROUTPUT set to ON

     * dbms_tdb.check_external displays report of external objects

     * on console */

    external := dbms_tdb.check_external;

  end;

3.執行CONVERT DATABASE指令。

C:\Documents and Settings\Administrator>rman target /

恢複管理器: Release 11.2.0.3.0 - Production on 星期二 3月 26 01:11:16 2013

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

已連接配接到目标資料庫: ORCL (DBID=1338818727)

RMAN> CONVERT DATABASE NEW DATABASE 'orcl'

transport script 'c:\convertdb\transportscript.sql'

to platform 'Linux x86 64-bit'PARALLELISM 4

db_file_name_convert 'C:\APP\ORADATA\ORCL\','c:\convertdb\';

NEW DATABASE=新資料庫名稱transport script=遷移過程需要執行的步驟及腳本to platform=遷移的目标平台db_file_name_convert='源資料庫資料檔案的存儲位置' '轉換後的檔案存儲位置' (注意:存儲位置最後一定加上'\'符号) 如果'源資料庫資料檔案的存儲位置'下存在子目錄,隻需要在'轉換後的檔案存儲位置'下建立相應的子目錄即可,不需要在db_file_name_convert進行子目錄的指定。 單程序的轉換通常較慢,可以适當增加并行度,提高轉換速度。 如果CONVERT DATABASE執行失敗以後,再次執行可能收到如下的報錯:在密碼檔案中找到使用者 SYS (具有 SYSDBA and SYSOPER 權限)RMAN-00571: ===========================================================RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============RMAN-00571: ===========================================================RMAN-03009: conversion at source 指令 (ORA_DISK_1 通道上, 在 08/20/2015 09:32:25 上) 失敗ORA-19926: 此時無法轉換資料庫 嘗試重新開機資料庫執行個體再次執行。 在目的地不能有重複的檔案存在,否則會報錯。CONVERT DATABASE指令還可以在目标端執行:CONVERT DATABASE on target platformconvert script 'E:\app\oradata\hello_linux\convertscript.sql'transport script 'E:\app\oradata\hello_linux\transportscript.sql'NEW DATABASE 'hello'PARALLELISM 4db_file_name_convert 'E:\app\oradata\hello\','E:\app\oradata\hello_linux\'; 詳情參考文章:《RMAN跨平台傳輸資料庫和表空間》:​http://blog.itpub.net/23135684/viewspace-776048/

啟動 conversion at source 于 26-3月 -13

使用目标資料庫控制檔案替代恢複目錄

配置設定的通道: ORA_DISK_1

通道 ORA_DISK_1: SID=21 裝置類型=DISK

在資料庫中找到目錄 SYS.ORACLE_OCM_CONFIG_DIR

在資料庫中找到目錄 SYS.DATA_PUMP_DIR

在資料庫中找到目錄 SYS.XMLDIR

在密碼檔案中找到使用者 SYS (具有 SYSDBA and SYSOPER 權限)

通道 ORA_DISK_1: 啟動資料檔案轉換

輸入資料檔案: 檔案号=00001 名稱=C:\APP\ORADATA\ORCL\SYSTEM01.DBF

已轉換的資料檔案 = C:\CONVERTDB\SYSTEM01.DBF

通道 ORA_DISK_1: 資料檔案轉換完畢, 經過時間: 00:00:07

通道 ORA_DISK_1: 啟動資料檔案轉換

輸入資料檔案: 檔案号=00002 名稱=C:\APP\ORADATA\ORCL\SYSAUX01.DBF

已轉換的資料檔案 = C:\CONVERTDB\SYSAUX01.DBF

通道 ORA_DISK_1: 資料檔案轉換完畢, 經過時間: 00:00:25

通道 ORA_DISK_1: 啟動資料檔案轉換

輸入資料檔案: 檔案号=00003 名稱=C:\APP\ORADATA\ORCL\UNDOTBS01.DBF

已轉換的資料檔案 = C:\CONVERTDB\UNDOTBS01.DBF

通道 ORA_DISK_1: 資料檔案轉換完畢, 經過時間: 00:00:01

通道 ORA_DISK_1: 啟動資料檔案轉換

輸入資料檔案: 檔案号=00004 名稱=C:\APP\ORADATA\ORCL\USERS01.DBF

已轉換的資料檔案 = C:\CONVERTDB\USERS01.DBF

通道 ORA_DISK_1: 資料檔案轉換完畢, 經過時間: 00:00:01

編輯 init.ora 檔案 C:\APP\PRODUCT\11.2.0\DB_1\DATABASE\INIT_00O5F09R_1_0.ORA。此

 PFILE 将用于在目标平台上建立資料庫據

在目标平台上運作 SQL 腳本 C:\CONVERTDB\TRANSPORTSCRIPT.SQL 以建立資料庫

要重新編譯所有 PL/SQL 子產品, 請在目标平台上運作 utlirp.sql 和 utlrp.sql

要更改内部資料庫辨別符, 請使用 DBNEWID 實用程式

完成 conversion at source 于 26-3月 -13

transportscript.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\PRODUCT\11.2.0\DB_1\DATABASE\INIT_00O5F09R_1_0.ORA'
 
 
CREATE CONTROLFILE REUSE SET DATABASE "ORCL" RESETLOGS  NOARCHIVELOG
 
 
    MAXLOGFILES 16
 
 
    MAXLOGMEMBERS 3
 
 
    MAXDATAFILES 100
 
 
    MAXINSTANCES 8
 
 
    MAXLOGHISTORY 292
 
 
LOGFILE
 
 
  GROUP 1 'C:\APP\PRODUCT\11.2.0\DB_1\DATABASE\ARCH_D-ORCL_ID-1338818727_S-4_T-1_A-811037993_03O5F09R'  SIZE 50M BLOCKSIZE 512,
 
 
  GROUP 2 'C:\APP\PRODUCT\11.2.0\DB_1\DATABASE\ARCH_D-ORCL_ID-1338818727_S-5_T-1_A-811037993_04O5F09R'  SIZE 50M BLOCKSIZE 512,
 
 
  GROUP 3 'C:\APP\PRODUCT\11.2.0\DB_1\DATABASE\ARCH_D-ORCL_ID-1338818727_S-6_T-1_A-811037993_05O5F09R'  SIZE 50M BLOCKSIZE 512
 
 
DATAFILE
 
 
  'C:\CONVERTDB\SYSTEM01.DBF',
 
 
  'C:\CONVERTDB\SYSAUX01.DBF',
 
 
  'C:\CONVERTDB\UNDOTBS01.DBF',
 
 
  'C:\CONVERTDB\USERS01.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 'C:\APP\PRODUCT\11.2.0\DB_1\DATABASE\DATA_D-ORCL_I-1338818727_TS-TEMP_FNO-1_06O5F09R'
 
 
     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\PRODUCT\11.2.0\DB_1\DATABASE\INIT_00O5F09R_1_0.ORA'
 
 
@@ ?/rdbms/admin/utlirp.sql 
 
 
SHUTDOWN IMMEDIATE 
 
 
STARTUP PFILE='C:\APP\PRODUCT\11.2.0\DB_1\DATABASE\INIT_00O5F09R_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;      

    嚴格按照transportscript.sql的描述,修改相應路徑按步驟執行即可完成遷移工作。

    相同ENDIAN平台之間的資料庫遷移也可以直接拷貝完整的資料檔案、控制檔案、日志檔案、參數檔案、密碼檔案,通過手動的方式同樣可以打開資料庫,但必須確定拷貝的資料庫是一緻的,否則在新環境的執行個體恢複将失敗:

SQL> alter database open;

alter database open

*

ERROR at line 1:

ORA-01113: file 1 needs media recovery

ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/SYSTEM01.DBF'

SQL> recover database;

ORA-00283: recovery session canceled due to errors

ORA-10562: Error occurred while applying redo to data block (file# 2, block#

6595)

ORA-10564: tablespace SYSAUX

ORA-01110: data file 2: '/u01/app/oracle/oradata/orcl/SYSAUX01.DBF'

ORA-10561: block type 'TRANSACTION MANAGED DATA BLOCK', data object# 6651

ORA-00600: internal error code, arguments: [4502], [0], [], [], [], [], [], [],

[], [], [], []

告警日志:

2013-03-25 16:42:39.551000 +08:00

ALTER DATABASE RECOVER  database

Media Recovery Start

Serial Media Recovery started

Recovery of Online Redo Log: Thread 1 Group 1 Seq 4 Reading mem 0

  Mem# 0: /u01/app/oracle/oradata/orcl/REDO01.LOG

2013-03-25 16:42:40.718000 +08:00

Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_2623.trc  (incident=2553):

ORA-00600: internal error code, arguments: [4502], [0], [], [], [], [], [], [], [], [], [], []

Incident details in: /u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_2553/orcl_ora_2623_i2553.trc

2013-03-25 16:42:41.882000 +08:00

Use ADRCI or Support Workbench to package the incident.

See Note 411.1 at My Oracle Support for error and packaging details.

Dumping diagnostic data in directory=[cdmp_20130325164242], requested by (instance=1, sid=2623), summary=[incident=2553].

2013-03-25 16:42:44.437000 +08:00

Media Recovery failed with error 10562

ORA-283 signalled during: ALTER DATABASE RECOVER  database  ...

Sweep [inc][2553]: completed

Sweep [inc2][2553]: completed

2013-03-25 16:43:15.731000 +08:00

Shutting down instance (abort)

License high water mark = 1

USER (ospid: 2623): terminating the instance

2013-03-25 16:43:16.744000 +08:00

Instance terminated by USER, pid = 2623

Instance shutdown complete