通过这个文章演示一下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. 使用MockMvc测试Spring mvc Controller

    概述   对模块进行集成测试时,希望能够通过输入URL对Controller进行测试,如果通过启动服务器,建立http client进行测试,这样会使得测试变得很麻烦,比如,启动速度慢,测试验证不方便 ...

  2. 谷歌眼镜--UI指南

    1>使用玻璃HTML模板 不是所有的内容都在几行文字来表达.有时候你需要结构化的内容发送到用户的时间轴,或者你需要控制对格式.为了适应这种情况,镜像API提供了一个 HTML 时间表的项目,接受 ...

  3. 轻松学习Linux系统安装篇之fdisk命令行工具的使用

    fdisk 的介绍:          fdisk 命令是磁盘分区表操作工具:和以前Dos和windows下的分区工具功能一样:fdsik 能划分磁盘成为若干个区,同时也能为每个分区指定分区的文件系统 ...

  4. ASP.NET的分页方法(三)

    第三讲是应用于MVC上面的分页,很多时候MVC要和EF表达式一起使用,但是我这个使用的最原始的ADO.NET,一样实现了这个效果.要实现这个效果首先要得到MvcPager.dll,引用之后,前台操作如 ...

  5. Oracle数据库编程:使用PL/SQL编写触发器

    8.使用PL/SQL编写触发器: 触发器存放在数据缓冲区中.        触发器加序列能够实现自动增长.        在触发器中不能使用connit和rollback.        DML触发器 ...

  6. 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证]

    二.使用Azure AD进行身份验证 之所以将Azure AD 作为开始,是应为基本上我们所有应用都需要进行安全管理.Azure Active Directory (Azure AD) 通过以下方式简 ...

  7. 自定义Template,向其中添加新的panel

    参考网站:https://www.devexpress.com/Support/Center/Example/Details/E2690 思路: 新建一个DefaultTemplate:       ...

  8. (剑指Offer)面试题27:二叉搜索树与双向链表

    题目: 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不能创建任何新的结点,只能调整树中结点指针的指向. 二叉树的定义如下: struct TreeNode{ int val; Tr ...

  9. HTTP(一) 连接管理

    ・HTTP是如何使用TCP连接的 HTTP传送一条报文时,以流的形式将报文数据内容通过一条打开的TCP连接按序传输. TCP收到数据流之后,由TCP/IP软件将数据流砍成被称作段的小数据块,并将段封装 ...

  10. Flex编程注意之直接获取某个组件的对象(this[]用法)通过id获取控件

    有这样一个需求:假如你new了一百次Button,同时这些button的id分别赋值如btn1.id = "button1"; btn2.id = "button2&qu ...