http://hi.baidu.com/hanbingxiaoshi/item/63724f51aad754968c12edae 1、连接oracle数据库 sql conn / as sysdba 已连接。 2、创建一个操作目录 sql create directory dump_dir as 'e:\dump'; 注意同时需要使用操作系统命令在硬盘上创建这个物理目录。 目录
http://hi.baidu.com/hanbingxiaoshi/item/63724f51aad754968c12edae
1、连接oracle数据库
sql> conn / as sysdba
已连接。
2、创建一个操作目录
sql> create directory dump_dir as 'e:\dump';
注意同时需要使用操作系统命令在硬盘上创建这个物理目录。
目录已创建。
3、使用以下命令创建一个导出文件目录
sql> grant read,write on directory dump_dir to scott;
授权成功。
4、使用命令expdp导出数据
c:\>expdp scott/tiger directory=dump_dir dumpfile=20080601.dmp tables=dept,emp
export: release 10.2.0.1.0 - production on 星期三, 18 6月, 2008 15:49:00
copyright (c) 2003, 2005, oracle. all rights reserved.
连接到: oracle database 10g enterprise edition release 10.2.0.1.0 - production
with the partitioning, olap and data mining options
启动 scott.sys_export_table_01: scott/******** directory=dump_dir dumpfile=20080601.dmp table
dept,emp
正在使用 blocks 方法进行估计...
处理对象类型 table_export/table/table_data
使用 blocks 方法的总估计: 128 kb
处理对象类型 table_export/table/table
处理对象类型 table_export/table/index/index
处理对象类型 table_export/table/constraint/constraint
处理对象类型 table_export/table/constraint/ref_constraint
. . 导出了 scott.dept 5.656 kb 4 行
. . 导出了 scott.emp 7.820 kb 14 行
已成功加载/卸载了主表 scott.sys_export_table_01
******************************************************************************
scott.sys_export_table_01 的转储文件集为:
e:\dump\20080601.dmp
作业 scott.sys_export_table_01 已于 15:49:22 成功完成
c:\>
**************************************************************************************************************
常见错误
如果没有在指定的硬盘上建立物理文件 ,则会出现如下错误提示信息:
解决的方法是现在硬盘上创建指定的物理文件目录,然后在执行expdp程序。
oracle 中的 create directory dump_dir as 'e:\dump';
命令只是在逻辑上创建了一个oracle能够识别的目录和硬盘上的一个物理目录之间的联系,
并不能真正的在硬盘上创建物理目录。
**************************************************************************************************************
c:\>expdp scott/tiger directory=dump_dir dumpfile=20080601.dmp tables=dept,emp
export: release 10.2.0.1.0 - production on 星期三, 18 6月, 2008 15:46:19
copyright (c) 2003, 2005, oracle. all rights reserved.
连接到: oracle database 10g enterprise edition release 10.2.0.1.0 - production
with the partitioning, olap and data mining options
ora-39002: 操作无效
ora-39070: 无法打开日志文件。
ora-29283: 文件操作无效
ora-06512: 在 sys.utl_file, line 475
ora-29283: 文件操作无效
导入命令:
impdp scott/tiger directory=dump_dir dumpfile=20080601.dmp tables=dept,emp
c:\>impdp scott/tiger directory=dump_dir dumpfile=20080601.dmp tables=dept,emp
import: release 10.2.0.1.0 - production on 星期三, 18 6月, 2008 15:56:11
copyright (c) 2003, 2005, oracle. all rights reserved.
连接到: oracle database 10g enterprise edition release 10.2.0.1.0 - production
with the partitioning, olap and data mining options
已成功加载/卸载了主表 scott.sys_import_table_01
启动 scott.sys_import_table_01: scott/******** directory=dump_dir dumpfile=20080601.dmp table
dept,emp
处理对象类型 table_export/table/table
处理对象类型 table_export/table/table_data
. . 导入了 scott.dept 5.656 kb 4 行
. . 导入了 scott.emp 7.820 kb 14 行
处理对象类型 table_export/table/index/index
处理对象类型 table_export/table/constraint/constraint
处理对象类型 table_export/table/constraint/ref_constraint
作业 scott.sys_import_table_01 已于 15:56:20 成功完成
c:\>
查看结果,发现删除的数据表又已经找回来了:
sql> set linesize 150;
sql> select * from scott.emp;
empno ename job mgr hiredate sal comm deptno
---------- ---------- --------- ---------- -------------- ---------- ---------- ----------
7369 smith clerk 7902 17-12月-80 800 20
7499 allen salesman 7698 20-2月 -81 1600 300 30
7521 ward salesman 7698 22-2月 -81 1250 500 30
7566 jones manager 7839 02-4月 -81 2975 20
7654 martin salesman 7698 28-9月 -81 1250 1400 30
7698 blake manager 7839 01-5月 -81 2850 30
7782 clark manager 7839 09-6月 -81 2450 10
7788 scott analyst 7566 19-4月 -87 3000 20
7839 king president 17-11月-81 5000 10
7844 turner salesman 7698 08-9月 -81 1500 0 30
7876 adams clerk 7788 23-5月 -87 1100 20
empno ename job mgr hiredate sal comm deptno
---------- ---------- --------- ---------- -------------- ---------- ---------- ----------
7900 james clerk 7698 03-12月-81 950 30
7902 ford analyst 7566 03-12月-81 3000 20
7934 miller clerk 7782 23-1月 -82 1300 10
已选择14行。
sql> select * from scott.dept;
deptno dname loc
---------- -------------- -------------
10 accounting new york
20 research dallas
30 sales chicago
40 operations boston
sql>
*******************************************************************************************************************************************
对oracle10g中的数据泵导出数据的分析
*******************************************************************************************************************************************
oracle10g中的数据泵只能用于服务器端,而不能用于客户端,它可以导出表、方案、表空间和整个数据库。
1、导出表
c:\>expdp scott/tiger directory=dump_dir dumpfile=20080601.dmp tables=dept,emp
2、导出方案
导出方案将方案的所有数据库对象和数据库表导出到一个文件中。
c:\>expdp hr/hr directory=dump_dir dumpfile=20080601schema.dmp schemas=hr
c:\>expdp hr/hr directory=dump_dir dumpfile=20080601schema.dmp schemas=hr
export: release 10.2.0.1.0 - production on 星期三, 18 6月, 2008 16:04:16
copyright (c) 2003, 2005, oracle. all rights reserved.
连接到: oracle database 10g enterprise edition release 10.2.0.1.0 - production
with the partitioning, olap and data mining options
启动 hr.sys_export_schema_01: hr/******** directory=dump_dir dumpfile=20080601schema.dmp sche
s=hr
正在使用 blocks 方法进行估计...
处理对象类型 schema_export/table/table_data
使用 blocks 方法的总估计: 448 kb
处理对象类型 schema_export/pre_schema/procact_schema
处理对象类型 schema_export/sequence/sequence
处理对象类型 schema_export/table/table
处理对象类型 schema_export/table/grant/owner_grant/object_grant
处理对象类型 schema_export/table/index/index
处理对象类型 schema_export/table/constraint/constraint
处理对象类型 schema_export/table/index/statistics/index_statistics
处理对象类型 schema_export/table/comment
处理对象类型 schema_export/procedure/procedure
处理对象类型 schema_export/procedure/alter_procedure
处理对象类型 schema_export/view/view
处理对象类型 schema_export/table/constraint/ref_constraint
处理对象类型 schema_export/table/trigger
处理对象类型 schema_export/table/statistics/table_statistics
. . 导出了 hr.countries 6.085 kb 25 行
. . 导出了 hr.departments 6.632 kb 27 行
. . 导出了 hr.employees 15.76 kb 107 行
. . 导出了 hr.jobs 6.609 kb 19 行
. . 导出了 hr.job_history 6.585 kb 10 行
. . 导出了 hr.locations 7.710 kb 23 行
. . 导出了 hr.regions 5.289 kb 4 行
已成功加载/卸载了主表 hr.sys_export_schema_01
******************************************************************************
hr.sys_export_schema_01 的转储文件集为:
e:\dump\20080601schema.dmp
作业 hr.sys_export_schema_01 已于 16:04:50 成功完成
c:\>
如果没有授予hr用户操作dump_dir目录的权限,则会出现如下错误提示信息:
c:\>expdp hr/hr directory=dump_dir dumpfile=20080601schema.dmp schemas=hr
export: release 10.2.0.1.0 - production on 星期三, 18 6月, 2008 16:02:55
copyright (c) 2003, 2005, oracle. all rights reserved.
连接到: oracle database 10g enterprise edition release 10.2.0.1.0 - production
with the partitioning, olap and data mining options
ora-39002: 操作无效
ora-39070: 无法打开日志文件。
ora-39087: 目录名 dump_dir 无效
3、导出表空间
expdp system/sysadmin directory=dump_dir dumpfile=tablespace.dmp tablespaces=users
c:\>expdp system/sysadmin directory=dump_dir dumpfile=tablespace.dmp tablespaces=users
export: release 10.2.0.1.0 - production on 星期三, 18 6月, 2008 16:09:19
copyright (c) 2003, 2005, oracle. all rights reserved.
连接到: oracle database 10g enterprise edition release 10.2.0.1.0 - production
with the partitioning, olap and data mining options
启动 system.sys_export_tablespace_01: system/******** directory=dump_dir dumpfile=tablespace.
p tablespaces=users
正在使用 blocks 方法进行估计...
处理对象类型 table_export/table/table_data
ora-39139: 数据泵不支持 xmlschema 对象。将跳过 table_data:oe.purchaseorder。
使用 blocks 方法的总估计: 1.187 mb
处理对象类型 table_export/table/table
处理对象类型 table_export/table/index/index
处理对象类型 table_export/table/constraint/constraint
处理对象类型 table_export/table/index/statistics/index_statistics
处理对象类型 table_export/table/rls_policy
处理对象类型 table_export/table/constraint/ref_constraint
处理对象类型 table_export/table/trigger
. . 导出了 oe.lineitem_table 283.5 kb 2232 行
. . 导出了 oe.action_table 14.87 kb 132 行
. . 导出了 oe.subcategory_ref_list_nestedtab 6.398 kb 21 行
. . 导出了 oe.product_ref_list_nestedtab 12.32 kb 288 行
. . 导出了 oe.categories_tab 13.12 kb 22 行
. . 导出了 scott.dept 5.656 kb 4 行
. . 导出了 scott.emp 7.820 kb 14 行
. . 导出了 scott.salgrade 5.585 kb 5 行
. . 导出了 scott.bonus 0 kb 0 行
已成功加载/卸载了主表 system.sys_export_tablespace_01
******************************************************************************
system.sys_export_tablespace_01 的转储文件集为:
e:\dump\tablespace.dmp
作业 system.sys_export_tablespace_01 已经完成, 但是有 1 个错误 (于 16:09:48 完成)
c:\>
4、导出整个数据库
expdp system/sysadmin directory=dump_dir dumpfile=full.dmp full=y
*******************************************************************************************************************************************
对oracle10g中的数据泵导入数据的分析
*******************************************************************************************************************************************
1、导入表
impdp scott/tiger directory=dump_dir dumpfile=dumptab.dmp tables=dept,emp
2、导入方案
一般只能导入自己的方案,如果想导入其他方案,必须具有exp_full_database或者dba权限。
impdp scott/tiger directory=dump_dir dumpfile=dumptab.dmp schemas=scott
3、导入表空间
impdp system/sysadmin directory=dump_dir dumpfile=tablespace.dmp tablespaces=users
4、导入整个数据库
impdp system/sysadmin directory=dump_dir dumpfile=full.dmp full=y
**************************************************************************************************************************************
使用oracle10g的数据泵可以移动表空间
**************************************************************************************************************************************
使用impdp和expdp可以实现在不同的数据库之间移动表空间。在oracle10g以前,只能在同一个操作系统平台
之间移动表空间。在oracle10g之后,不仅可以在同一个操作系统平台之间移动表空间,还可以在不同的操作系统
之间移动表空间。用户可以通过查看数据库视图v$transportable_platform查询到哪些操作系统平台之间可以移动
表空间,即:
sql> col platform_name format a60;
sql> select * from v$transportable_platform order by platform_id;
platform_id platform_name endian_format
----------- ------------------------------------------------------------ --------------
1 solaris[tm] oe (32-bit) big
2 solaris[tm] oe (64-bit) big
3 hp-ux (64-bit) big
4 hp-ux ia (64-bit) big
5 hp tru64 unix little
6 aix-based systems (64-bit) big
7 microsoft windows ia (32-bit) little
8 microsoft windows ia (64-bit) little
9 ibm zseries based linux big
10 linux ia (32-bit) little
11 linux ia (64-bit) little
platform_id platform_name endian_format
----------- ------------------------------------------------------------ --------------
12 microsoft windows 64-bit for amd little
13 linux 64-bit for amd little
15 hp open vms little
16 apple mac os big
17 solaris operating system (x86) little
18 ibm power based linux big
已选择17行。
要移动表空间必须满足如下条件:
1、原数据库和目标数据库必须有相同的数据库字符集和国家字符集
2、不能移动到具有同名表空间的目标数据库中。如果出现同名,只能使用alter tablespace rename
命令更改源数据库或者目标数据库的表空间名称。
3、不能移动system或者sys用户对象所在的表空间。
4、要将表空间在不同的操作系统之间移动,必须将初始化参数compatible参数设置为10.0以上。
因为oracle10g以前的版本不支持在不同操作系统之间移动表空间。
5、要移动的表空间集合必须满足自包含,可以使用dbms_tts的过程transport_set_check检查
是否自包含,然后在临时表transprot_set_violations内查询检查结果。
以下是移动表空间的步骤,以移动users表空间为例子:
第一步:设置表空间为只读表空间:
alter tablespace users read only;
第二步:使用expdp导出表空间
expdp 用户名/口令 directory=目录名称 dumpfile=导出文件名称 transport_tablespaces=表空间名称
例如:
expdp system/sysadmin directory=dump_dir dumpfile=tablespace.dmp tablespaces=users;
第三步:使用操作系统命令将导出文件和传输表空间的数据文件复制到目标数据库中。
第四步:在目标数据库上使用impdp将源数据库的导出内容导入到目标数据库中,impdp导入表空间的
命令格式如下:
imp 用户名称/口令 directory=目录名称 dumpfile=导出文件名称 transport_tablespaces=表空间名称
transport_datafiles=;数据文件名称'
例如:
impdp system/sysadmin directory=dump_dir dumpfile=tablespace.dmp tablespaces=users
transport_datafiles=d:\oracle\oradata\oramgr\user01.dbf;
第五步:使用一下命令将原数据库的传输表空间恢复为可读写
alter tablespace users read write;