使用rman跨平台传输数据库和表空间

oracle支持传输表空间,用来在不同数据库中移动表空间内容,也支持传输数据库功能,可以用来在不同平台重新创建一个完成的数据库,只要这2个平台的endian顺序一致。

传输表空间

当源与目的地平台的endian格式不同的时候,需要在源平台上使用convert tablespace或在目的地平台上使用convert datafile命令转换。

convert会产生出目的地平台上使用的正确的格式,不会改变源数据文件的内容。

下面是在源平台上使用convert tablespace ..to platform的例子

RMAN> CONVERT TABLESPACE ts_1, ts_2...
   TO PLATFORM 'platform_name';

支持的platform_names可以再v$transportable_platform中查到。在源平台上只能转换整个表空间,而不是单个数据文件。

下面是转换的一个例子

% rman TARGET /
RMAN> CONVERT TABLESPACE finance,hr
   TO PLATFORM 'Linux IA (32-bit)'
   FORMAT='/tmp/transport_linux/%U';

在目的地平台上使用convert datafile... from platform

这个命令在目的地平台上使用,将转换源平台上的表空间格式到目的地平台的格式。

RMAN> CONVERT DATAFILE datafile_1, datafile_2...
   FROM PLATFORM 'platform_name';

可以将文件转换到不同的位置

% rman TARGET /
RMAN> CONVERT DATAFILE
   '/tmp/transport_solaris/fin/fin01.dbf',
   '/tmp/transport_solaris/fin/fin02.dbf',
   '/tmp/transport_solaris/hr/hr01.dbf',
   '/tmp/transport_solaris/hr/hr02.dbf'
   DB_FILE_NAME_CONVERT
        '/tmp/transport_solaris/fin','/orahome/dbs/fin',
        '/tmp/transport_solaris/hr','/orahome/dbs/hr'

跨平台传输数据库:rman convert database

rman的convert database用来完成在不同平台移动整个数据库,要有相同的endian格式。

使用dbms_tdb包准备转换数据库

1使用dbms_tdb.check_db来检查数据库状态

这个方法来检查数据库是否能传输到一个目的地平台,当前的数据库状态是否允许传输。

将数据库以只读模式打开,调用dbms_tdb.check_db,要是serveroutpout设置成on,并且这个检查返回了false,那么输出包含了为什么数据库不能转换。可能的原因如下:

ConditionAction
Unrecognized target platform name.Check V$DB_TRANSPORTABLE_PLATFORM for recognized platform names.
Target platform has a different endian format.Conversion is not supported.
Database is not open read-only.Open database read-only and retry.
There are active or in-doubt transactions in the database.Open the database read-write. After the active transactions are rolled back and the in-doubt transactions are resolved, open the database read-only and retry.

This can happen if users flashback the database and open it read only. The active transactions will be rolled back when the database is opened read-write.

Deferred transaction rollback needs to be done.Open the database read-write and and bring online the necessary tablespaces. Once the deferred transaction rollback is complete, open the database read-only and retry.
Database compatibility version is below 10.Change the init.ora COMPATIBLE parameter to 10 or higher, open the database read-only and retry.
Some tablespaces have not been open read-write with compatibility version is 10 or higher.Change the init.ora COMPATIBLE parameter to 10 or higher. Then open the affected tablespaces read-write. Then shut down the database, open it read-only, and retry.


下面是一个检查的例子

SQL> set serveroutput on
SQL> declare
       db_ready boolean;
     begin
       db_ready := dbms_tdb.check_db('Microsoft Windows IA (32-bit)',dbms_tdb.skip_readonly);
     end;
     /
 
Database is not open READ ONLY. Please open database READ ONLY and retry.

PL/SQL procedure successfully completed.

使用dbms_tdb.check_external来标识外部对象

这个方法必须用来标识任意的外部表,目录和bfiles,rman不会自动传输这些文件。

下面是一个例子

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;

下面是在源平台上执行convert database;

1将数据库至于只读状态打开

2检查数据库

dbms_tdb.check_db

3检查外部表

dbms_tdb.check_external

4运行rman的convert database

RMAN> CONVERT DATABASE NEW DATABASE 'newdb'
        transport script '/tmp/convertdb/transportscript'
        to platform 'Microsoft Windows IA (32-bit)'
        db_file_name_convert '/disk1/oracle/dbs' '/tmp/convertdb'
        ;
5将阐述的文件放到目的地,要是数据文件的路径与源库的不一致,那么编辑脚本和pfile

6在目的地主机上运行脚本来创建新数据库

完成上面的步骤,一个新的数据库就创建完毕了。

在目的地机器上运行convert database

这个方式的前期检查与之前的检查方法是一样的。下面的步骤不太一样:

1在源平台上使用convert database命令例如

CONVERT DATABASE ON TARGET PLATFORM
     CONVERT SCRIPT '/tmp/convertdb/convertscript.rman'
        TRANSPORT SCRIPT '/tmp/convertdb/transportscript.sql'
        new database 'newdb'
        FORMAT '/tmp/convertdb/%U'

convert database on target platform产生阐述脚本和pfile及转换脚本,要将未转换的源数据文件放到目的地机器上的临时目录中,然后运行目的地上的转换脚本来完成数据格式的转变。

If the filesystem containing the datafiles of the source database is accessible from the destination system using the same path names, then you can use the convert script on the destination host without any changes. The CONVERT DATAFILE commands in the script produce datafile copies in the locations specified by FORMAT, converted for use with the new database. (Once the convert script has been run, the source database can be opened for read-write access again.)

Otherwise, while the datafiles are still read-only, copy them to a temporary location. (As soon as copies of the datafiles are made, the source database can be opened read-write again.) If necessary, move the copies of the datafiles to a temporary location on the destination host, and then update each CONVERT DATAFILE command in the convert script to use the temporary location of each datafile as input and the FORMAT parameter of each CONVERT command to specify the desired final location of the datafiles of the transported database.


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值