ITPub博客

首页 > 数据库 > 数据库开发技术 > 数据泵用法笔记

数据泵用法笔记

原创 数据库开发技术 作者:imlihj2007 时间:2009-04-17 07:35:25 0 删除 编辑

数据泵用法笔记:

*** 2009-4-2

有个别库可能缺少对象

,数据泵操作会失败!

:数据泵主要做数据的应用操作比较方便,也就是做数据导入导出!

测试环境hp oracle 11g

Data Pump 导出:

导出前提:

1. 首先必须创建文件夹!

#mkdir –p /backup/test1

#chmod –R 777 /backup/test1

2. 设置数据泵数据库环境变量:

$export ORACLE_SID=test

$sqlplus /nolog

sql>conn / as sysdbasql>create directory dptest1 as '/backup/test1';

3. 赋予用户读写权限:

sql>grant read, write on directory dptest1 to impcms

导出操作:

1. 导出一用户下的表

$expdp impcms/impcms tables=t_cms_mtv directory= dptest1 dumpfile=expcases.dmp job_name=cases_export

说明:这样把用户下的一个表可以导出来,并导出用户表的索引,约束,数据和注释信息,但是涉及到的过程不导出来!

2. 并行操作

$expdp impcms/impcms directory=dptest1 dumpfile=expcases_%u.dmp parallel=3 job_name=cases_export include=table:"like 'T_UMS_%'"

说明:您可以通过 PARALLEL 参数为导出使用一个以上的线程来显著地加速作业。每个线程创建一个单独的转储文件,因此参数 dumpfile 应当拥有和并行度一样多的项目。您可以指定通配符作为文件名,而不是显式地输入各个文件名, 可以导出三个表,并且生成N文件!导出来的东西就是比导一个用户下的表多了几张表而已!

3. 导出表,并导出函数和过程

$expdp impcms/impcms directory=dptest1 dumpfile=expcases1_%u.dmp parallel=3 job_name=cases_export1 include=table:"like 'T_UMS_%'",procedure,function

说明:这样可以把过程和函数给导出来,在前一个的基础上把其他的数据对象过程和函数给导出来!

4. 用户级别,导出所有对象

$expdp impcms/impcms directory= dptest1 dumpfile=expcases1_%u.dmp parallel=3 job_name=cases_export1

说明:导出用户所有对象:

5. 只导出数据,不导其他对象

expdp impcms/impcms directory= dptest1 dumpfile=expcases1_%u.dmp parallel=3 job_name=cases_export1 content=data_only

说明:这个在数据移植的时候应该很实用,仅仅可以把数据导出来,加上其他条件还可以快速移动数据对象!

6. 导元数据,不导出数据

$expdp impcms/impcms directory= dptest1 dumpfile=expcases1_%u.dmp parallel=3 job_name=cases_export1 content=metadata_only

说明:可以导出用户的所有对象信息,没有数据,结构移植很实用

7. 导出表空间

$expdp impcms/impcms directory=dptest1 dumpfile=expcase1s_%u.dmp parallel=3 job_name=cases_export TABLESPACES=imp

$expdp impcms/impcms directory=dptest1 dumpfile=expcase1s_%u.dmp parallel=3 job_name=cases_export TABLESPACES=impidx

说明:这个可以把表空间里的数据导出来,主要是表,其他暂时还不知道,依赖关系没有研究!

8. 导出几个用户的办法

$expdp system/sys directory= dptest1 dumpfile=expcases.dmp schemas=impcms,test

9. 导出全部数据库

$expdp system/sys directory= dptest1 dumpfile=expcases.dmp full=y

说明:暂时不知道怎样导进去

10. 过滤数据库对象

$expdp pe0402/pe0402 directory= dptest1 dumpfile=expcases.dmp job_name=cases_export exclude=procedure,function,package,index,comment

说明:可以不导出procedure,function,package,index,comment等对象信息

导出总结:

1, 可以导出任意对象

2, 可以过滤任意对象

Data Pump 导出:

数据导入会在很多地方出问题!

1. 用impcms导出一个表,导入到test用户下的情况

$expdp impcms/impcms tables= t_ums_rolepermission directory= dptest1 dumpfile=expcases.dmp job_name=cases_export

$impdp test/test directory= dptest1 dumpfile=expcases.dmp job_name=cases_export remap_schema=impcms:test

这个涉及到对象的移动到不同的用户方案下面

$impdp test/test directory= dptest1 tables=t_ums_rolepermission dumpfile=expcases.dmp job_name=cases_export remap_schema=impcms:test

这个语句可以涉及到用户的对象过滤

2. 导出用户的信息,然后做对象的限制导入

$expdp impcms/impcms directory= dptest1 dumpfile=expcases1.dmp job_name=cases_export1

1, 全导进去

$impdp test/test directory= dptest1 dumpfile=expcases1.dmp job_name=cases_export remap_schema=impcms:test

包的导入出了很多的问题,关键是type没有导进来,导致很多问题!

仅仅导入数据(先做对象导入)

$impdp test/test directory= dptest1 dumpfile=expcases1.dmp job_name=cases_export remap_schema=impcms:test content= metadata_only

仅仅导入数据(数据导入)

$impdp test/test directory= dptest1 dumpfile=expcases1.dmp job_name=cases_export remap_schema=impcms:test content= data_only exclude= CONSTRAINT,REF_CONSTRAINT

有主外键的时候会出问题(提前禁止使用)!

可以把数据给导进去,到数据要确保数据结构对象已经存在!

$impdp test/test directory= dptest1 dumpfile=expcases1.dmp job_name=cases_export remap_schema=impcms:test content= metadata_only

导入的时候不要把约束导进去!要提前禁止使用各种约束

$impdp test/test directory= dptest1 dumpfile=expcases1.dmp job_name=case1s_export remap_schema=impcms:test content=data_only exclude= CONSTRAINT,REF_CONSTRAINT skip_unusable_indexes=y,table_exists_action= replace

$impdp test/test directory= dptest1 dumpfile=expcases1.dmp job_name=case1s_export remap_schema=impcms:test exclude= CONSTRAINT,REF_CONSTRAINT sqlfile=procs.sql

生成对象创建的脚本!

导入总结:

1, 用户级别的导入的时候,要提前禁止约束的使用(如果有数据)!

2, 用户导入的时候,要提前把类型创建好,否则由于依赖关系,一般会创建type失败

3, 用户导入操作的时候可以不进行导入操作,仅仅生成创建的sql语句!

远程导出操作步骤:

远程必须有数据库,因为数据泵进程上服务器进程!

仅仅做数据的移植问题较小,涉及到对象就比较容易出问题

1创建用户

Sql> create user test identified by test

default tablespace users

quota unlimited on users;

2 授予权限

Sql> grant connect to test;

Sql> grant create table, create database link to test;

Sql> grant read, write on directory test1 to test;

3,创建连接

Sql> conn test/test

Sql> create database link test113 connect to impcms identified by impcms

using 'test';

select * from global_name@test113;

4,导出操作(问题多多,有很多东西暂时不清楚:版本,语言,平台)

$expdp test/test directory=test1 dumpfile=test.dp network_link=test113 logfile=jiangsu.log content= data_only

5,远程操作(会有很多容易失败和依赖的东西,需要再做验证)

$impdp test/test directory=test1 network_link=test113 logfile=jiangsu.log remap_schema=impcms:test content=data_only

如果有大对象操作,暂时还没有做验证!!!

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9879835/viewspace-1020732/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Oracle 11g笔记
请登录后发表评论 登录
全部评论

注册时间:2011-05-25

  • 博文量
    109
  • 访问量
    1577023