通过这个文章演示一下Oracle的表空间迁移流程以及需要注意的诸多事项。

实验目标:将ora10g数据库实例上的表空间TBS_SEC_D迁移到secooler数据库实例上
操作系统:Redhat 5.3
数据库:Oracle 10.2.0.3

【实验BEGIN】
【注意事项一】:导入之前,目标数据库中用户必须已经存在存在。
【注意事项二】:导入之前,目标数据库中不能存在同名的表空间,如迁移同名的表空间,需要对迁移之前的源数据库或待迁入数据库中的表空间改名。

1.检查源数据库的表空间是否是“自包含”的
1)以sys用户登录数据库
sec@ora10g> conn / as sysdba
Connected.

2)使用dbms_tts.transport_set_check对待迁移表空间进行检查,这里待表空间的名字是TBS_SEC_D
sys@ora10g> exec dbms_tts.transport_set_check('TBS_SEC_D',true);

PL/SQL procedure successfully completed.

3)通过transport_set_violations视图查看是否有违反“自包含”的内容,这里显示结果是没有,所以可以对完成TBS_SEC_D表空间的迁移
sys@ora10g> select * from transport_set_violations;

no rows selected

简单列一下“非自包含”的四种可能情况以及应对方法:
--假设待迁移的表空间名字只是:TBS_SEC_D
(1)【索引】表空间TBS_SEC_D上存在索引,但是这个索引的基表在另外一个表空间上(后面的实验将会演示违反这种约束的情况);
(2)【LOB】表存储在表空间TBS_SEC_D上,但是表上的LOB字段存储在其他表空间上;
(3)【约束】表的约束有的在表空间TBS_SEC_D上,但是其他的约束在另外的表空间上;
(4)【分区表】分区表的一些分区在表空间TBS_SEC_D上,但是其他的其他的分区在另外的表空间上。

如果违反上述的条件,单独想要导出表空间TBS_SEC_D是不行的,处理方法:
第一种处理方法:连带相关的表空间一起导出
第二种处理方法:预处理那些不在一起的表空间数据到TBS_SEC_D上,然后就可以导出表空间TBS_SEC_D了

2.将待导出的表空间TBS_SEC_D修改为“只读”——————这一步很关键
sys@ora10g> alter tablespace TBS_SEC_D read only;

Tablespace altered.

3.以SYSDBA权限导出表空间
ora10g@testdb183 /exp$ exp "'"/ as sysdba"'" file=exp_TBS.dmp log=exp_TBS.log transport_tablespace=y tablespaces=TBS_SEC_D triggers=y constraints=n grants=n

Export: Release 10.2.0.3.0 - Production on Tue Aug 25 19:54:22 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Export done in AL32UTF8 character set and UTF8 NCHAR character set
Note: table data (rows) will not be exported
Note: grants on tables/views/sequences/roles will not be exported
Note: constraints on tables will not be exported
About to export transportable tablespace metadata...
For tablespace TBS_SEC_D ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                           TEST
. exporting triggers
. end transportable tablespace metadata export
Export terminated successfully without warnings.

OK,导出成功。
表空间导出主要是transport_tablespace=y这个参数在起作用,看提示信息,这里导出的exp_TBS.dmp文件中是不包含对象数据的,仅包含表空间的“元数据”,真正的数据还在表空间对应的物理数据文件上,因此使用表空间传输技术完成导入时需要的不仅仅是这个exp_TBS.dmp导出文件,还需要表空间对应的数据文件。

4.不要着急将表空间TBS_SEC_D恢复为“读写”状态,需要先将导出的exp_TBS.dmp文件和组成表空间的物理数据文件发送到需要导入的secooler数据库服务器上
这里需要注意的是:要以二进制(bin)的模式传输数据。
我习惯于使用scp命令完成数据文件的传输。
最好将数据文件放置到目标数据库数据文件存放的目录,以便统一进行管理。

5.OK,传输完成后,现在可以将表空间TBS_SEC_D恢复为“读写”状态了
sys@ora10g> alter tablespace TBS_SEC_D read write;

Tablespace altered.

6.在目标数据库(secooler数据库实例)中导入表空间
secooler@dbserver /imp$ imp "'"/ as sysdba"'" file='/imp/exp_TBS.dmp' transport_tablespace=y datafiles='/imp/tbs_sec_d01.dbf' tablespaces=TBS_SEC_D tts_owners=sec fromuser=sec touser=sec

Import: Release 10.2.0.3.0 - Production on Tue Aug 25 21:27:37 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options

Export file created by EXPORT:V10.02.01 via conventional path
About to import transportable tablespace(s) metadata...
import done in AL32UTF8 character set and UTF8 NCHAR character set
. importing SYS's objects into SYS
. importing SYS's objects into SYS
. importing SEC's objects into SEC
. . importing table                         "TEST"
. importing SYS's objects into SYS
Import terminated successfully without warnings.
secooler@dbserver /imp$

7.通过登陆到sec用户中查询数据库对象,验证数据已经成功导入。

8.将表空间置为可读写状态,完成整个表空间的迁移任务。
sec@secooler> select TABLESPACE_NAME,STATUS from dba_tablespaces where TABLESPACE_NAME='TBS_SEC_D';

TABLESPACE_NAME                STATUS
------------------------------ ---------
TBS_SEC_D                      READ ONLY

sec@secooler> alter tablespace SEC_D read write;

Tablespace altered.

sec@secooler> select TABLESPACE_NAME,STATUS from dba_tablespaces where TABLESPACE_NAME='TBS_SEC_D';

TABLESPACE_NAME                STATUS
------------------------------ ---------
TBS_SEC_D                      ONLINE

【实验补充ing】
【模拟违反“自包含”第一条原则过程】

sec@ora10g> create table t (x number) tablespace USERS;

Table created.

sec@ora10g> create index t_idx on t(x) tablespace TBS_SEC_D;

Index created.

sec@ora10g> conn / as sysdba
Connected.
sys@ora10g> exec dbms_tts.transport_set_check('USERS',true);

PL/SQL procedure successfully completed.

sys@ora10g> select * from transport_set_violations;

no rows selected

sys@ora10g> exec dbms_tts.transport_set_check('USERS',true);

PL/SQL procedure successfully completed.

sys@ora10g> select * from transport_set_violations;

no rows selected

sys@ora10g> exec dbms_tts.transport_set_check('TBS_SEC_D',true);

PL/SQL procedure successfully completed.

sys@ora10g> select * from transport_set_violations;

VIOLATIONS
------------------------------------------------
Index SEC.T_IDX in tablespace TBS_SEC_D points to table SEC.T in tablespace USERS

将TBS_SEC_D,USERS两个表空间同时导出不会有问题:
ora10g@testdb183 /exp$ exp "'"/ as sysdba"'" file=exp_TBS.dmp log=exp_TBS.log transport_tablespace=y tablespaces=TBS_SEC_D,USERS triggers=y constraints=n grants=n

Export: Release 10.2.0.3.0 - Production on Tue Aug 25 19:40:09 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Export done in AL32UTF8 character set and UTF8 NCHAR character set
Note: table data (rows) will not be exported
Note: grants on tables/views/sequences/roles will not be exported
Note: constraints on tables will not be exported
About to export transportable tablespace metadata...
For tablespace TBS_SEC_D ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                           TEST
For tablespace USERS ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                              T
. exporting triggers
. end transportable tablespace metadata export
Export terminated successfully without warnings.

单独将USERS表空间同时导出也不会有问题:
ora10g@testdb183 /exp$ exp "'"/ as sysdba"'" file=exp_TBS.dmp log=exp_TBS.log transport_tablespace=y tablespaces=USERS triggers=y constraints=n grants=n

Export: Release 10.2.0.3.0 - Production on Tue Aug 25 19:40:19 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Export done in AL32UTF8 character set and UTF8 NCHAR character set
Note: table data (rows) will not be exported
Note: grants on tables/views/sequences/roles will not be exported
Note: constraints on tables will not be exported
About to export transportable tablespace metadata...
For tablespace USERS ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                              T
. exporting triggers
. end transportable tablespace metadata export
Export terminated successfully without warnings.

但是,单独将TBS_SEC_D表空间同时就会报错,因为违反了一下原则:
【索引】表空间TBS_SEC_D上存在索引,但是这个索引的基表在另外一个表空间上(后面的实验将会演示违反这种约束的情况)
ora10g@testdb183 /exp$ exp "'"/ as sysdba"'" file=exp_TBS.dmp log=exp_TBS.log transport_tablespace=y tablespaces=TBS_SEC_D triggers=y constraints=n grants=n

Export: Release 10.2.0.3.0 - Production on Tue Aug 25 19:40:25 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Export done in AL32UTF8 character set and UTF8 NCHAR character set
Note: table data (rows) will not be exported
Note: grants on tables/views/sequences/roles will not be exported
Note: constraints on tables will not be exported
About to export transportable tablespace metadata...
EXP-00008: ORACLE error 29341 encountered
ORA-29341: The transportable set is not self-contained
ORA-06512: at "SYS.DBMS_PLUGTS", line 1387
ORA-06512: at line 1
EXP-00000: Export terminated unsuccessfully

======================================================================
【注意】不相同的数据库字符集和国家字符集是不能完成表空间迁移的!报错如下,要多加注意。
bomsdb1@testdb183 /imp$ imp "'"/ as sysdba"'" file='/imp/exp_TBS.dmp' transport_tablespace=y datafiles='/imp/tbs_sec_d01.dbf' tablespaces=TBS_SEC_D tts_owners=sec fromuser=sec touser=sec

Import: Release 10.2.0.3.0 - Production on Tue Aug 25 20:18:10 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options

Export file created by EXPORT:V10.02.01 via conventional path
About to import transportable tablespace(s) metadata...
import done in AL32UTF8 character set and AL16UTF16 NCHAR character set
import server uses WE8ISO8859P1 character set (possible charset conversion)
export server uses UTF8 NCHAR character set (possible ncharset conversion)
IMP-00017: following statement failed with ORACLE error 29345:
 "BEGIN   sys.dbms_plugts.beginImport ('10.2.0.3.0',873,'871',13,'Linux 64-bi"
 "t for AMD',12006,39801,1,0,0,0); END;"
IMP-00003: ORACLE error 29345 encountered
ORA-29345: cannot plug a tablespace into a database using an incompatible character set
ORA-06512: at "SYS.DBMS_PLUGTS", line 2386
ORA-06512: at "SYS.DBMS_PLUGTS", line 1946
ORA-06512: at line 1
IMP-00000: Import terminated unsuccessfully

【最后小结】
表空间迁移技术可以非常高效的完成数据的迁移任务,所用时间基本等于物理拷贝数据文件的时间。不过有一些具体环境的限制,在真正使用之前,需要进行严格的测试。

将完成表空间迁移过程中需要注意的事项列一下,如果不全,请大家补充。
【注意事项一】:导入之前,目标数据库中用户必须已经存在存在。
【注意事项二】:导入之前,目标数据库中不能存在同名的表空间,如迁移同名的表空间,需要对迁移之前的源数据库或待迁入数据库中的表空间改名。
【注意事项三】:导出前需要将表空间置为“只读状态”
【注意事项四】:需要以SYSDBA权限完成表空间迁移
【注意事项五】:表空间需要“自包含”,不符合“自包含”的情况如下
(1)【索引】表空间TBS_SEC_D上存在索引,但是这个索引的基表在另外一个表空间上(后面的实验将会演示违反这种约束的情况);
(2)【LOB】表存储在表空间TBS_SEC_D上,但是表上的LOB字段存储在其他表空间上;
(3)【约束】表的约束有的在表空间TBS_SEC_D上,但是其他的约束在另外的表空间上;
(4)【分区表】分区表的一些分区在表空间TBS_SEC_D上,但是其他的其他的分区在另外的表空间上;

Goodluck.

-- The End --

来自《oracle数据库表空间的导出

oracle数据迁移的更多相关文章

  1. Oracle数据迁移至HBase操作记录

    Oracle数据迁移至HBase操作记录 @(HBase) 近期需要把Oracle数据库中的十几张表T级别的数据迁移至HBase中,过程中遇到了许多苦难和疑惑,在此记录一下希望能帮到一些有同样需求的兄 ...

  2. Oracle数据迁移expdp/impdp

    Oracle数据迁移expdp/impdp目的:指导项目侧自行进行简单的数据泵迁移工作. 本文实验环境:Oracle 11.2.0.4,利用数据库自带的scott示例用户进行试验测试. 1.首先需要创 ...

  3. Oracle数据迁移至MySQL

    ORACLE DB: 11.2.0.3.0 MYSQL DB: 5.5.14 因项目需求,需要将ORACLE生产中数据迁移至MYSQL数据库中作为初始数据,方法有如下几种: 1.ORACLE OGG ...

  4. Oracle数据迁移笔记-Rownum与序列的自增长的组合用法技巧

    Rownum与序列的自增长的组合用法技巧 根据序列自增长的步长规律,结合表行记录Rownum值的规则批量生成表的行记录主键的用法技巧 案例如下: CREATE OR REPLACE PROCEDURE ...

  5. oracle数据迁移之Exp和Expdp导出数据的性能对比与优化

    https://wangbinbin0326.github.io/2017/03/31/oracle%E6%95%B0%E6%8D%AE%E8%BF%81%E7%A7%BB%E4%B9%8BExp%E ...

  6. Oracle数据迁移后由列的直方图统计信息引起的执行计划异常

    (一)问题背景 在使用impdp进行数据导入的时候,往往在导入表和索引的统计信息的时候,速度非常慢,因此我在使用impdp进行导入时,会使用exclude=table_statistics排除表的统计 ...

  7. 【Oracle 数据迁移】环境oracle 11gR2,exp无法导出空表的表结构【转载】

    今天做数据迁移,但是发现有些空表无法exp,后来找到问题所在. [原文]:http://www.cnblogs.com/wenlong/p/3684230.html 11GR2中有个新特性,当表无数据 ...

  8. Oracle数据迁移-系统数据合并笔记

    创建临时表:execute immediate 'sql'; 通过临时表和关联查询解决循环处理效率低下,大数据操作移植时时间太长的问题. 结构相同的系统数据库表移植,案例如下: create or r ...

  9. oracle 数据迁移之数据泵的基本使用

    oracle相同数据库下跨schema的表迁移—expdp/impdp 需求:将GUIDO用户下的表迁移到SCOTT用户下 select * from dba_role_privs where GRA ...

随机推荐

  1. int型长度

    Ø  基本数据类型 C语言中只有4中基本数据类型——整型.浮点型.指针和聚合类型(如数组和结构等):所有其他类型都是从这4种基本类型的某种变化或组合派生而来. 一.整型家族 整型家族包括char.sh ...

  2. ASP.NET MVC3 系列教程 - 部署你的WEB应用到IIS 6.0

    I:ASP.NET MVC3 部署的前期工作 1.确认部署的服务器操作系统环境 首先我们确认服务器的操作系统版本 可以从系统命令行工具里输入: systeminfo 获取相关操作系统信息例如 然后再确 ...

  3. Python学习第二天数组

    1:Python定义数组:a=[0,1,2,3,4] ;   打印数组list(a); 这时:a[0]=0, a[1]=1, a[[2]=2...... 1.1:如果想定义一个很长的数组可以用到pyt ...

  4. geeksforgeeks@ Find sum of different corresponding bits for all pairs (Bit manipulation)

    http://www.practice.geeksforgeeks.org/problem-page.php?pid=387 Find sum of different corresponding b ...

  5. 主机找不到vmnet1和vmnet8

    今天跑程序时,突然发现虚拟机ping不通主机了,返过来可行,防火墙什么的都设置好了,仍然不行,后来发现,在网络和共享中心已经看不到vmnet1和vmnet8了,更改适配器设置也只有本地连接和宽带连接, ...

  6. TCP包头

    每发一个包,不论大小协议头会占用一定的空间 TCP头20字节,IP头20字节,MAC头14字节,共54字节 //Mac头部,总长度14字节  typedef struct _eth_hdr  {    ...

  7. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  8. How Tomcat Works(十七)

    在前面的文章中,已经学会了如何通过实例化一个连接器和容器来获得一个servlet容器,并将连接器和容器相关联:但在前面的文章中只有一个连接器可用,该连接器服务8080端口上的HTTP请求,无法添加另一 ...

  9. 快速排序详解以及java实现

    快速排序作为一种高效的排序算法被广泛应用,SUN的JDK中的Arrays.sort 方法用的就是快排. 快排采用了经典的分治思想(divide and conquer): Divide:选取一个基元X ...

  10. NLog使用总结

    一.代码调用方式:    public static readonly Logger Logger = LogManager.GetCurrentClassLogger(); Logger .Trac ...