天天看点

Oracle传输表空间迁移数据库

本文是通过exp/imp方式实现,需要将数据库表空间处于只读模式,对于实时应用的生产数据库,可以采用rman方式进行传输表空间,本文源与目标数据库均为oralce 10.2.0.5 for linux版本。

执行表空间传输有以下限制条件:    

(1)源数据库和目标数据库必须处于相同的平台,10g以后可以用RMAN命令修改数据文件实现跨平台移动表空间。    

(2)对于源数据库和目标数据库版本不同时,源数据库的版本必须低于目标数据库。    

(3)两边数据库字符集和国家字符集必须一致。    

(4)目标数据库不能存在同名的表空间。

SQL> col PLATFORM_NAME for a40;   

SQL> select * from v$transportable_platform order by 3;

PLATFORM_ID PLATFORM_NAME                            ENDIAN_FORMAT   

----------- ---------------------------------------- --------------    

          6 AIX-Based Systems (64-bit)               Big    

         18 IBM Power Based Linux                    Big    

          2 Solaris[tm] OE (64-bit)                  Big    

          4 HP-UX IA (64-bit)                        Big    

         16 Apple Mac OS                             Big    

          1 Solaris[tm] OE (32-bit)                  Big    

          9 IBM zSeries Based Linux                  Big    

          3 HP-UX (64-bit)                           Big    

         17 Solaris Operating System (x86)           Little    

         20 Solaris Operating System (x86-64)        Little    

         12 Microsoft Windows x86 64-bit             Little    

         13 Linux x86 64-bit                         Little    

          8 Microsoft Windows IA (64-bit)            Little    

         19 HP IA Open VMS                           Little    

         11 Linux IA (64-bit)                        Little    

          5 HP Tru64 UNIX                            Little    

         10 Linux IA (32-bit)                        Little    

          7 Microsoft Windows IA (32-bit)            Little    

         15 HP Open VMS                              Little

SQL> create tablespace tjoa datafile '/u01/app/oracle/oradata/orcl/tjoa.dbf' size 10m autoextend on next 10m;   

SQL> create user abc identified by abc default tablespace TJOA;    

SQL> grant connect,resource to abc;    

SQL> conn abc/abc    

SQL> create table t as select * from all_objects;

SQL> conn / as sysdba   

SQL> execute dbms_tts.transport_set_check(ts_list=>'TJOA',incl_constraints=>TRUE);    

SQL> select * from transport_set_violations;

SQL> alter tablespace TJOA read only;   

SQL> select tablespace_name, status from dba_tablespaces where tablespace_name = 'TJOA';

TABLESPACE_NAME                STATUS   

------------------------------ ---------    

TJOA                           READ ONLY

SQL>

exp \'/ as sysdba \' file=tjoa.dmp transport_tablespace=y tablespaces=TJOA buffer=10240000

通过expdp方式:   

expdp \'/ as sysdba \' dumpfile=tjoa.dmp directory=dump_dir transport_tablespaces=TJOA

SQL> alter tablespace TJOA read write;

windows/linux平台字节序同为Little都不需要转换,10g及以上版本的数据文件可以直接拷贝。

使用rman的convert命令转换文件示例如下:   

$ rman target /    

RMAN> convert tablespace TJOA to platform 'Linux IA (32-bit)' format '/u01/%U';

scp tjoa.dmp 192.168.233.160:/home/oracle    

scp tjoa.dbf 192.168.233.160:/u01/app/oracle/oradata/orcl/

SQL> create user abc identified by abc;   

SQL> grant connect,resource to abc;

imp \'/ as sysdba \' file=tjoa.dmp transport_tablespace=y tablespaces=TJOA datafiles=/u01/app/oracle/oradata/orcl/tjoa.dbf

通过impdp方式:   

impdp \'/ as sysdba \' dumpfile=tjoa.dmp directory=dump_dir transport_datafiles=/u01/app/oracle/oradata/orcl/tjoa.dbf remap_schema=tjoa:tjoa

SQL> alter user abc default tablespace TJOA;   

SQL> select tablespace_name, status from dba_tablespaces where tablespace_name = 'TJOA';    

SQL> conn / as sysdba;   

Connected.    

SQL> alter user abc default tablespace TJOA;

User altered.

SQL>    

SQL>     

Tablespace altered.

TJOA                           ONLINE

本文转自 koumm 51CTO博客,原文链接:http://blog.51cto.com/koumm/1574822,如需转载请自行联系原作者