應用RMAN Transportable Database進行資料庫跨平臺遷移

lovestanford發表於2014-06-12
Purpose(目標)
在進行資料庫跨平臺遷移的時候,可能用到的辦法由expdp/impdp, exp/imp, rman  tts和本文介紹的 rman  transportable database,transportable database進行跨平臺資料遷移的時候,兩個平臺所使用的位元組排序方式必須一樣,要麼都是小端位元組,要麼就是大端位元組, 而TTS則可以在不同平臺和不同位元組之間進行資料遷移。

+ We can use RMAN "Transportable Database" conversion for performing cross platform database migration between two operating system platforms belonging to the same endian format.
Use V$TRANSPORTABLE_PLATFORM view to check the endianess of source and target database platforms.

+ If you need to migrate database across endian platforms i.e. from a little-endian platform to big-endian platform or vice-versa, we cannot use RMAN "Transportable Database" conversion. In this case, you would be using transportable tablespaces along with RMAN datafile conversion.

+ Also, note that for certain platform migration, we need not use RMAN convert (either using "Transportable Database" or "Transportable Tablespaces") at all. For these platforms, you can directly perform RMAN duplication (active or backup-based) or RMAN restore/recover without any conversion:

Details

本文演示所使用的資料庫是從小端位元組的Linux x86 64-bit遷移到 Solaris Operating System x86 32-bit,
For explaining RMAN "Transportable Database" methodology, we will migrate a 11.2.0.3 database running on Linux x86 64-bit (little-endian) platfrom to Solaris Operating System x86 32-bit (little-endian) platform。
下面描述具體Transportable Database的步驟。


step1. Execute 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來檢查外部表,目錄和 bfile物件,因為rman不能自動對這些物件進行transport轉換,必須手工fix。

SQL> set serveroutput on;
SQL> declare x boolean; begin x := dbms_tdb.check_external; end;
  2  /
The following directories exist in the database:
SYS.ORACLE_OCM_CONFIG_DIR, SYS.DATA_PUMP_DIR

PL/SQL procedure successfully completed.

As per output above, we have 2 directories defined in the database. Check the operating system path for these directories using below query. Ensure that the same path is available on the target system for these directories to be usable or rename the directory paths after conversion.
SQL> select DIRECTORY_NAME, DIRECTORY_PATH from DBA_DIRECTORIES;

DIRECTORY_NAME            DIRECTORY_PATH
------------------------- ----------------------------------------
DATA_PUMP_DIR             /orasoft/admin/ora11gR2/dpdump/
ORACLE_OCM_CONFIG_DIR     /orasoft/rdbms/11.2.0.3/ccr/state

2. Start the source database in READ ONLY mode:
將源資料庫置於只讀模式
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database open read only;

3. Execute 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. Any condition reported by CHECK_DB must be resolved before proceeding
執行DBMS_TDB.CHECK_DB檢查資料庫是否滿足遷移到目標平臺的條件,是否有其他影響遷移的因素
SQL> set serveroutput on
SQL>
SQL> DECLARE db_ready BOOLEAN;
  2  BEGIN
  3  db_ready := DBMS_TDB.CHECK_DB('Solaris Operating System (x86)', DBMS_TDB.SKIP_NONE);
  4  END;
  5  /

PL/SQL procedure successfully completed.

4. Transportable Database using RMAN COVERT DATABASE command can be performed on the source system or target system.

使用rman convert database命令對資料庫 資料檔案進行轉換,預設情況下對資料庫所以檔案進行轉換,
It's default behavior is to perform datafile conversion on all datafiles in the database.
However, only datafiles that contain undo data require conversion including all datafiles beloging to SYSTEM tablespace and all UNDO tablespaces.
然而,實際上只有包含undo資料的資料檔案需求進行轉換,(不知道為什麼是這樣,誰能解釋下)

To skip datafile conversion for datafiles that do not contain undo data, you must perform a target platform conversion as shown in this document.
Get a list of datafiles that require conversion and ones that don't
透過下屬的查詢得到兩個列表:一個列表中的資料檔案需要進行轉換,另一個列表中的資料檔案不需要進行轉換:

SQL> select FILE_NAME "Datafiles requiring Conversion" from DBA_DATA_FILES
  2  where TABLESPACE_NAME in (select distinct TABLESPACE_NAME from DBA_ROLLBACK_SEGS);

Datafiles requiring Conversion
--------------------------------------------------------------------------------
/oradata/ora11gR2/system01.dbf
/oradata/ora11gR2/undotbs01.dbf

SQL> select FILE_NAME "Files NOT requiring Conversion" from DBA_DATA_FILES
  2  where TABLESPACE_NAME NOT in (select distinct TABLESPACE_NAME from DBA_ROLLBACK_SEGS);

Files NOT requiring Conversion
--------------------------------------------------------------------------------
/oradata/ora11gR2/sysaux01.dbf
/oradata/ora11gR2/users01.dbf

5. Now we need to move all the above files (the ones which need conversion and ones which do not) to the target system. For datafiles which do not require conversion, they can directly be moved to their final destination on the target system. For datafiles which need conversion, need to be moved to a staging location on the target system where we will run CONVERT on them during which they will be placed in their final destination.
接下來可將所有資料檔案(需要轉換的和不需求轉換的)copy到目標系統上。
對於不需要轉換的資料檔案,可以將它們放在最終的目錄下,需要轉換的檔案可以先放在一個臨時目錄下,方便對其進行轉換。

為了減少遷移時間,可以將資料檔案複製和轉換一步完成,這裡需要用到NFS技術(跳過先)
To minimize time for migration, we need to evaluate how datafile copying (to the target system) and datafile conversion can be merged into a single step. One method would be to NFS mount the source system directory (containing the datafiles) on the target system. Thus, when datafile conversion is run on target system, the datafiles will be placed in their final location eliminating the extra step of transferring the datafiles to the target system.

This method will work if you are performing migration for below cases:

a) Source database uses file-system, Target database uses file-system
b) Source database uses file-system, Target database uses ASM

If source database uses ASM, we need to use BACKUP AS COPY command in RMAN (this needs to be run when the database in in MOUNT mode or OPEN read only) to move the datafiles from ASM to a file-system location on the source and then NFS mount that location on the target system.
Alternatively if source database uses SAN storage, check with your system administrator if it is possible to mount the source san diskgroups directly on the target server in read only mode.
In this example, our source Linux x86 64-bit uses file-system whereas our target Solaris x86 32-bit will use ASM. We will NFS mount the source system directory which contains the datafiles i.e. '/oradata' to the target Solaris system

NFS mounting is outside the scope of this article but here is how it is done
On source, put below line in /etc/exports:
/oradata        oraSolaris10(ro)

Re-start NFS:
# /etc/init.d/nfs stop
# /etc/init.d/nfs start
On target, perform the NFS mount:
# mount -o vers=3  -F nfs 192.168.114.10:/oradata /oradata

6. We now need to move the initialization parameter file from source to target system. If source database is using spfile, create pfile from it and move it to the target:
將源資料庫上的系統初始化引數檔案(pfile,如果沒有可以先建立)複製到目標系統的適當位置,然後針對目標系統進行相應的修改,然後 startup nomount pfile='pfile'

SQL> create pfile = '/oradata/ora11gR2/initSol11g.ora' from spfile;

On the target system, move this pfile to $ORACLE_HOME/dbs location and make suitable changes to reflect mount-points available on
the target system and any other changes you might want to make. you might want to specifically change these parameters:
audit_file_dest, control_files, db_name, db_recovery_file_dest, diagnostic_dest(幾個引數在pfile中需要修改)

STARTUP NOMOUNT the instance on the target system using the modified pfile:
使用經過修改過的spfile啟動例項到nomount狀態

SQL> startup nomount pfile='/orasoft/rdbms/11.2.0.3/dbs/initSol11g.ora'

7. Now, start the conversion process in RMAN on target system for the datafiles that we identified in Step 4 i.e. ones which contain UNDO data:
現在對需要進行轉換的資料檔案進行相應的rman convert
7.1a 如果目標資料庫使用ASM
RMAN> CONVERT FROM PLATFORM 'Linux x86 64-bit'
2> PARALLELISM 2
3> DATAFILE '/oradata/ora11gR2/system01.dbf' FORMAT '+DATA'
4> DATAFILE '/oradata/ora11gR2/undotbs01.dbf' FORMAT '+DATA';

Starting conversion at target at 08-NOV-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=62 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=12 device type=DISK
channel ORA_DISK_1: starting datafile conversion
input file name=/oradata/ora11gR2/system01.dbf
channel ORA_DISK_2: starting datafile conversion
input file name=/oradata/ora11gR2/undotbs01.dbf
converted datafile=+DATA/sol11g/datafile/undotbs1.256.766638629
channel ORA_DISK_2: datafile conversion complete, elapsed time: 00:02:53
converted datafile=+DATA/sol11g/datafile/system.257.766638629
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:04:23
Finished conversion at target at 08-NOV-11

You can increase PARALLELISM value if there are many files which need to be converted so that more channels are allocated.
If the target database will not use ASM, specify the file-system path in the FORMAT clause where the datafile will finally reside.
7.1b如果目標資料庫使用傳統FS:

RMAN> CONVERT FROM PLATFORM 'Linux x86 64-bit'
 PARALLELISM 2
 DATAFILE '/oradata/ora11gR2/system01.dbf' FORMAT '/u01/app/oracle/oradata/ORCL/system01.dbf'
 DATAFILE '/oradata/ora11gR2/undotbs01.dbf' FORMAT /u01/app/oracle/oradata/ORCL/undo01.dbf';

8. Now, copy rest of the datafiles (which do not contain undo and hence do not require conversion) to the ASM diskgroup using RMAN without conversion.
Note that to copy files into ASM we have again used CONVERT command (without FROM PLATFORM clause).
When CONVERT DATAFILE is used without specifying a source or destination platform, we do not perform any kind of conversion. This is specifically used to move files into ASM from file-sytem.

If the target database will not use ASM, this step is not needed. Instead use OS cp command to copy these datafile directly to the directory where you want them to reside.
8.1a如果目標資料庫使用ASM:
RMAN> CONVERT PARALLELISM 2
2> DATAFILE '/oradata/ora11gR2/sysaux01.dbf' FORMAT '+DATA'
3> DATAFILE '/oradata/ora11gR2/users01.dbf' FORMAT '+DATA';

Starting conversion at target at 08-NOV-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=63 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=13 device type=DISK
channel ORA_DISK_1: starting datafile conversion
input file name=/oradata/ora11gR2/sysaux01.dbf
channel ORA_DISK_2: starting datafile conversion
input file name=/oradata/ora11gR2/users01.dbf
converted datafile=+DATA/sol11g/datafile/users.259.766639567
channel ORA_DISK_2: datafile conversion complete, elapsed time: 00:00:17
converted datafile=+DATA/sol11g/datafile/sysaux.258.766639567
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:59
Finished conversion at target at 08-NOV-11

8.1b 如果目標資料庫使用傳統FS:直接使用OS的cp命令進行檔案複製,
參加步驟5.

9. Now, we need to create the controlfile for our target database. You can generate the controlfile creation script by running below on the source database:
為目標資料庫建立控制檔案,
在源系統上,使用alter database backup controlfile to trace resetlogs;

SQL> alter database backup controlfile to trace resetlogs;
然後根據目標系統的相關資訊,對控制檔案SQL指令碼進行修改:

Edit the controlfile creation script to reflect:

a) Datafile names for the target database where the datafiles finally reside (after running CONVERT DATAFILE)
b) Redo Log names as per target system path
c) database name as needed for the target database.

Here is the controlfile creation script for our example:

SQL> CREATE CONTROLFILE REUSE SET DATABASE "SOL11G" RESETLOGS ARCHIVELOG
  2      MAXLOGFILES 16
  3      MAXLOGMEMBERS 3
  4      MAXDATAFILES 100
  5      MAXINSTANCES 8
  6      MAXLOGHISTORY 292
  7  LOGFILE
  8    GROUP 1 '+DATA/sol11g/redo01.log'  SIZE 50M BLOCKSIZE 512,
  9    GROUP 2 '+DATA/sol11g/redo02.log'  SIZE 50M BLOCKSIZE 512,
 10    GROUP 3 '+DATA/sol11g/redo03.log'  SIZE 50M BLOCKSIZE 512
 11  DATAFILE
 12    '+DATA/sol11g/datafile/system.257.766638629',
 13    '+DATA/sol11g/datafile/sysaux.258.766639567',
 14    '+DATA/sol11g/datafile/undotbs1.256.766638629',
 15    '+DATA/sol11g/datafile/users.259.766639567'
 16  CHARACTER SET WE8MSWIN1252;
 
Control file created.

10. Now, open the database on the target system. Once, database opens, add tempfiles to the TEMP tablespace
開啟目標資料庫,新增臨時檔案

SQL> ALTER DATABASE OPEN RESETLOGS;

Database altered.

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '+DATA' SIZE 20971520  AUTOEXTEND OFF;


Tablespace altered.

11. Complete the database conversion by running UTLIRP and UTLRP as below:
重新編譯資料庫中的無效物件,至此,資料庫遷移完成
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP UPGRADE;(為啥要執行這一步驟,不解)
SQL> @ ?/rdbms/admin/utlirp
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP;
SQL> @ ?/rdbms/admin/utlrp


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/21754115/viewspace-1181665/,如需轉載,請註明出處,否則將追究法律責任。

相關文章