X 传输表空间方法留待整理

这两天一直在看文档当中的传输表空间部分。说起来十分惭愧,经过不断的尝试,总算完成了一次不太完美的传输表空间的实验。

http://blog.itpub.net/29515435/viewspace-1123714/

一、传输表空间概述
首先来认识一下什么是传输表空间,传输表空间技术始于oracle9i,不论是数据字典管理的表空间还是本地管理的表空间,都可以使用传输表空间技术;传输表空间不需要在源数据库和目标数据库之间具有同样的DB_BLOCK_SIZE块大小;使用传输表空间迁移数据比使用数据导入导出工具迁移数据的速度要快,这是因为传输表空间只是复制包含实际数据的数据文件到目标数据库的指定位置,而使用数据导入导出工具则是传输表空间对象的元数据到目标数据库。

二、传输表空间的方法
1、使用SQL*PLUS,RMAN,Data Pump工具实现手动的传输表空间。
2、使用EM工具中的传输表空间向导实现传输表空间。

三、跨平台传输表空间
从oracle 10g开始,oracle实现了跨平台的表空间传输,跨平台的意味着数据库可以从一种类型的平台迁移到另一中类型的平台上,大多数(但不是全部)的平台都支持传输表空间。首先必须通过查看v$transportable_platform视图查看oracle支持的平台,并确定每种平台的字节存储次序,注意:这一点非常重要。以下查询为oracle支持的各种平台及字节存储次序(版本为10.2.0.4),在跨平台表空间传输时,需要通过查询该视图进行平台和字节存储次序的比对。
SQL> select * from v$transportable_platform order by platform_name;
PLATFORM_ID PLATFORM_NAME                        ENDIAN_FORMAT
----------- ------------------------------------ --------------
          6 AIX-Based Systems (64-bit)           Big
         16 Apple Mac OS                         Big
         19 HP IA Open VMS                       Little
         15 HP Open VMS                          Little
          5 HP Tru64 UNIX                        Little
          3 HP-UX (64-bit)                       Big
          4 HP-UX IA (64-bit)                    Big
         18 IBM Power Based Linux                Big
          9 IBM zSeries Based Linux              Big
         10 Linux IA (32-bit)                    Little
         11 Linux IA (64-bit)                    Little
         13 Linux x86 64-bit                     Little
          7 Microsoft Windows IA (32-bit)        Little
          8 Microsoft Windows IA (64-bit)        Little
         12 Microsoft Windows x86 64-bit         Little
         17 Solaris Operating System (x86)       Little
         20 Solaris Operating System (x86-64)    Little
          1 Solaris[tm] OE (32-bit)              Big
          2 Solaris[tm] OE (64-bit)              Big
19 rows selected.

四、两个数据库之间进行传输表空间的过程
1、如果是跨平台的表空间传输,需要检查两个平台支持的字节存储顺序,检查方法见如上文所述,如果可以确定源数据库和目标数据库属于同一平台,可以省略此步骤;
2、选择自包含的(self-contained)表空间,这里的限制相对于使用数据泵来说比较变态,实验中将会有一些粗略的介绍。
3、将源数据库上的选定表空间修改为read-only状态,使用expde工具生成传输表空间(集)。      //在这一步,如果两个平台间的字节存储次序不同,还需完成字节存储次序的转换
4、传输表空间及与表空间对应数据文件 (使用操作系统命令、ftp命令等方式)到目标数据库。    //字节存储次序的转换也可以在这一步完成
5、将源数据库的表空间恢复为read-write状态(可选)
6、在目标数据库,使用impdp工具导入表空间(集)

五、本次实验记录
本来设计的实验过程为:通过转换字节存储次序,实现跨平台的表空间传输。但是通过查询v$transportable_platform视图发现所拥有的平台(windows 64bit和Linux x86-64)的字节存储次序相同,并且在测试过程中出现了字符集不兼容的错误。由于条件不具备,无奈之下只好选择了两个Linux平台数据库(10.2.0.4和11.2.0.1)之间的表空间传输。

实验限制一:Windows 64bit和Linux x86-64的字节存储次序相同 
SQL> select * from v$transportable_platform where platform_name like 'Microsoft%64%' or platform_name like 'Linux%64%';
PLATFORM_ID PLATFORM_NAME                        ENDIAN_FORMAT
----------- ------------------------------------ --------------
         11 Linux IA (64-bit)                    Little
          8 Microsoft Windows IA (64-bit)        Little
         13 Linux x86 64-bit                     Little
         12 Microsoft Windows x86 64-bit         Little

实验限制二:表空间导入时,由于字符集不兼容出现的保存信息
C:\Users\Manganese>impdp system/oracle dumpfile=expdat.dmp directory=dump_dir transport_datafiles=D:\app\Manganese\oradata\orcl\test01.dbf logfile=tts_import.log
Import: Release 11.2.0.1.0 - Production on 星期一 3月 17 22:08:29 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功加载/卸载了主表 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01"
启动 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01":  system/******** dumpfile=expdat.dmp directory=dump_dir transport_datafiles=D:\app\Manganese\oradata\orcl\test01.dbf logfile=tts_import.log
处理对象类型 TRANSPORTABLE_EXPORT/PLUGTS_BLK
ORA-39123: 数据泵可传输的表空间作业中止
ORA-29345: 无法使用不兼容的字符集将表空间插入到数据库中
作业 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" 因致命错误于 22:08:30 停止

1、实验前准备。创建测试用表空间、用户、表、插入两条数据(用于最后验证表传输成功,数据都可以正常访问)
SQL> create tablespace test 
  2  datafile '/u01/app/oracle/oradata/stdb/test01.dbf' size 10m;                                                  //创建测试用表空间,表空间名为test
Tablespace created.
SQL> create user tester identified by tester default tablespace test account unlock;                      //创建测试用户,用户名为tester,默认表空间为test
User created.
SQL> grant connect,resource to tester;
Grant succeeded.
SQL> conn tester/tester;
Connected.
SQL> create table t1 (id number,name varchar(10),sex char(1),age int,class varchar(3));              //创建测试验证用表,表名为t1
Table created.
SQL> insert into t1 values (2001,'alex','M',18,'10');
1 row created.
SQL> insert into t1 values (2002,'bob','M',18,'20');
1 row created.
SQL> select * from t1;
        ID NAME       S        AGE CLA
---------- ---------- - ---------- ---
      2001 alex       M         18 10
      2002 bob        M         18 20
SQL> commit;
Commit complete.

 

2、表空间自包含(独立性)检查
根据文件介绍,传输表空间由诸多限制,如下:
An index inside the set of tablespaces is for a table outside of the set of tablespaces.
A partitioned table is partially contained in the set of tablespaces.
A referential integrity constraint points to a table across a set boundary.
A table inside the set of tablespaces contains a LOB column that points to LOBs outside the set of tablespaces. 
等等。 

SQL> conn /as sysdba
Connected.
SQL> execute dbms_tts.transport_set_check('test',true);
PL/SQL procedure successfully completed.
SQL> select * from transport_set_violations;
no rows selected                                                    //查询无返回结果说明检查通过,否则需要根据violation字段的说明解决各类参照完整性问题,比如说主键、外键约束、分区等问题

3、在源数据库将表空间设为只读状态
SQL> alter tablespace test read only;
Tablespace altered.

4、使用expdp工具生成表空间(集)
[oracle@stdb ~]$ expdp system/oracle dumpfile=expdat.dmp directory=dump_dir transport_tablespaces=test logfile=export.log
Export: Release 10.2.0.4.0 - 64bit Production on Monday, 17 March, 2014 19:29:02
Copyright (c) 2003, 2007, Oracle.  All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01":  system/******** dumpfile=expdat.dmp directory=dump_dir transport_tablespaces=test logfile=export.log 
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Master table "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_TRANSPORTABLE_01 is:
  /u01/app/oracle/dump_dir/expdat.dmp
Job "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 19:29:18

5、将源数据库表空间设为read-write状态。
6、使用ftp工具分别拷贝表空间(集)和与表空间对应数据文件到相应的目录。

7、在目标数据库使用impdp工具将表空间(集)导入目标数据库,根据需要决定是否需要创建与源数据库相同的用户,或者在使用impdp是可以使用remap_schema参数。
[oracle@dbserver2 ~]$ impdp system/oracle dumpfile=expdat.dmp directory=dump_dir transport_datafiles=/u01/app/oracle/oradata/prac/test01.dbf logfile=import.log
Import: Release 11.2.0.1.0 - Production on Mon Mar 17 14:32:29 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01":  system/******** dumpfile=expdat.dmp directory=dump_dir transport_datafiles=/u01/app/oracle/oradata/prac/test01.dbf logfile=import.log 
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at 14:32:31

8、验证结果
[oracle@dbserver2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Mon Mar 17 14:34:36 2014
Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select ts#,name from v$tablespace;
       TS# NAME
---------- ------------------------------
         0 SYSTEM
         1 SYSAUX
         2 UNDOTBS1
         4 USERS
         3 TEMP
         6 EXAMPLE
         7 TEST
7 rows selected.

SQL> conn tester/tester;
Connected.
SQL> select * from t1;
        ID NAME       S        AGE CLA
---------- ---------- - ---------- ---
      2001 alex       M         18 10
      2002 bob        M         18 20

六、附录
由于没能进行字节存储次序转换测试,特地从文档上拷贝两个示例,待有条件时再进行测试。
示例一:在源数据库端完成字节存储次序转换

RMAN> CONVERT TABLESPACE sales_1,sales_2 
2> TO PLATFORM 'Microsoft Windows IA (32-bit)'
3> FORMAT '/tmp/%U';

Starting conversion at source at 30-SEP-08
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile conversion
input datafile file number=00007 name=/u01/app/oracle/oradata/salesdb/sales_101.dbf converted datafile=/tmp/data_D-SALESDB_I-1192614013_TS-SALES_1_FNO-7_03jru08s channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile conversion
input datafile file number=00008 name=/u01/app/oracle/oradata/salesdb/sales_201.dbf converted datafile=/tmp/data_D-SALESDB_I-1192614013_TS-SALES_2_FNO-8_04jru0aa channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:25
Finished conversion at source at 30-SEP-08

示例二:在目标数据库端完成字节存储次序转换

C:\>RMAN TARGET /
Recovery Manager: Release 11.2.0.0.1 
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
connected to target database: ORAWIN (DBID=3462152886)

RMAN> CONVERT DATAFILE 
2>'C:\Temp\sales_101.dbf',
3>'C:\Temp\sales_201.dbf'
4>TO PLATFORM="Microsoft Windows IA (32-bit)"
5>FROM PLATFORM="Solaris[tm] OE (32-bit)"
6>DB_FILE_NAME_CONVERT=
7>'C:\Temp\', 'C:\app\orauser\oradata\orawin\'
8> PARALLELISM=4;
原文地址:https://www.cnblogs.com/chendian0/p/10211762.html