手机版
你好,游客 登录 注册
背景:
阅读新闻

Oracle传输表空间

[日期:2014-03-19] 来源:Linux社区  作者:dba_manganese [字体:大 中 小]

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;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款