oracle数据迁移
通过这个文章演示一下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数据迁移的更多相关文章
- Oracle数据迁移至HBase操作记录
Oracle数据迁移至HBase操作记录 @(HBase) 近期需要把Oracle数据库中的十几张表T级别的数据迁移至HBase中,过程中遇到了许多苦难和疑惑,在此记录一下希望能帮到一些有同样需求的兄 ...
- Oracle数据迁移expdp/impdp
Oracle数据迁移expdp/impdp目的:指导项目侧自行进行简单的数据泵迁移工作. 本文实验环境:Oracle 11.2.0.4,利用数据库自带的scott示例用户进行试验测试. 1.首先需要创 ...
- Oracle数据迁移至MySQL
ORACLE DB: 11.2.0.3.0 MYSQL DB: 5.5.14 因项目需求,需要将ORACLE生产中数据迁移至MYSQL数据库中作为初始数据,方法有如下几种: 1.ORACLE OGG ...
- Oracle数据迁移笔记-Rownum与序列的自增长的组合用法技巧
Rownum与序列的自增长的组合用法技巧 根据序列自增长的步长规律,结合表行记录Rownum值的规则批量生成表的行记录主键的用法技巧 案例如下: CREATE OR REPLACE PROCEDURE ...
- 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 ...
- Oracle数据迁移后由列的直方图统计信息引起的执行计划异常
(一)问题背景 在使用impdp进行数据导入的时候,往往在导入表和索引的统计信息的时候,速度非常慢,因此我在使用impdp进行导入时,会使用exclude=table_statistics排除表的统计 ...
- 【Oracle 数据迁移】环境oracle 11gR2,exp无法导出空表的表结构【转载】
今天做数据迁移,但是发现有些空表无法exp,后来找到问题所在. [原文]:http://www.cnblogs.com/wenlong/p/3684230.html 11GR2中有个新特性,当表无数据 ...
- Oracle数据迁移-系统数据合并笔记
创建临时表:execute immediate 'sql'; 通过临时表和关联查询解决循环处理效率低下,大数据操作移植时时间太长的问题. 结构相同的系统数据库表移植,案例如下: create or r ...
- oracle 数据迁移之数据泵的基本使用
oracle相同数据库下跨schema的表迁移—expdp/impdp 需求:将GUIDO用户下的表迁移到SCOTT用户下 select * from dba_role_privs where GRA ...
随机推荐
- JAVA分析html算法(JAVA网页蜘蛛算法)
近来有些朋友在做蜘蛛算法,或者在网页上面做深度的数据挖掘.但是遇到复杂而繁琐的html页面大家都望而却步.因为很难获取到相应的数据. 最古老的办法的是尝试用正则表达式,估计那么繁琐的东西得不偿失,浪费 ...
- select多个字段赋值给多个变量
在存储过程中定义了变量v1 int;v2 int;v3 int;从表tab1选择3个字段f1,f2,f3赋值给这三个变量,要如何写 如果单个变量可以 select f1 into v1 from t ...
- 为网页设计师准备的30个使用的HTML5框架
原文地址:http://www.goodfav.com/zh/html5-framework-8189.html 网页设计师在开始使用一些应用程序之前需要考虑几个事实,以确保在应用Web程序框架时,这 ...
- SQL Server数学函数
数学函数 1.计算绝对值ABS ABS函数对一个数值表达式结果计算绝对值(bit数据类型除外),返回整数. 语法结构: ABS(数值表达式) 返回值:与数值表达式类型一致的数据 示例: ) --输出 ...
- 第三百零八至三百二十天 how can I 坚持
十三天..2月4号至2月16号,好快,假期还没开始就结束了.一一回忆下. 2月4号,腊月二十六,最后一天上班,没多大事,好像是玩了一天,东月回家,貌似路上好折腾,晚上D401,和她聊了一路,也聊了好多 ...
- C++ 之关联容器 map
标准库定义了四种关联容器:map是其中之一(另外还有set.multimap.multiset).map的元素以键-值(key-value),在学了顺序容器之后,再学习关联容器,就比较比较好理解了. ...
- tomcat的host配置
本机 etc\hosts 首先了解C:\WINDOWS\system32\drivers\etc\hosts文件配置 127.0.0.1 static1.ezsins.com #adoble ps c ...
- NHibernate的简单例子
NHibernate的简单例子 @(编程) [TOC] 因为项目需求,搭了一个NHibernate的例子,中间遇到了一些问题,通过各种方法解决了,在这里记录一下最后的结果. 1. 需要的dll Com ...
- JQuery与GridView控件结合示例
JQuery是一种非常强大的客户端JS编程技术,这里不想过多阐述它的相关背景知识,只想简单演示一下如何与asp.net的控件结合开发. 比如,我们要做一个下面如图所示的功能,效果是状态.编号.数字1. ...
- poj1584
题意:已知一个多边形的n个顶点坐标,然后再给一个钉子,给定钉子的半径和圆心坐标,首先判断多边形是否为凸多边形,若为凸多边形,再判断钉子是否可以放到凸多边形内部. 思路: 1.由于顶点给出的顺序可能为逆 ...