对于Oracle 数据库之间的导入导出,可以使用Oracle提供的导入导出工具EXP/IMP来实现。EXP/IMP是Oracle早期提供的数据导入导出工具。在Oracle 10g 中,提供了高速导入导出数据泵IMPDP,EXPDP,本文主要讲述EXPDP的用法。 关于IMPDP的用法,请参照:数据泵IMPDP 导入工具的使用 http://www.linuxidc.com/Linux/2012-01/51797.htm 一、数据泵的体系结构 数据泵是一个基于服务器端的高速导入导出工具,通过dbms_datapump包来调用 提供expdp,impdp,以及基于Web页面来实现导入导出 提供两种数据数据方式方式:直接路径、外部表 可以定制数据泵作业,以及从作业中分离和重新附加到作业 服务器端的数据泵是直接访问数据文件与SGA,不必通过会话进行访问 数据泵进程 对Unix系统而言,数据泵进程为expdp,impdp 对Windows系统而言,数据泵进程为expdp.exe,impdp.exe 启动一个DataPump作业,至少会启动下列两个进程,一个Data Pump Master(DMnn),一个或多个工作进程(DWnn),主进程控制工作进程 如果多个DataPump作业同时运行,那么每个作业都具有自己的DMnn进程以及自己的DWnn进程 如果设置了并行技术,则每个DWnn进程可以使用两个或多个并行执行服务器(名称为Pnnn) DataPump生成下列三种形式的文件 SQL文件:描述指定作业所包含对象的若干DDL语句 转储文件:即包含数据和元数据的文件 日志文件:用于记录导出时的相关信息 目录 用于设置导入导出文件所在或存放的位置 create directory dump_scott as /home/oracle/dump/scott"; 可以通过dba_directories来查看系统中已创建的目录 select * from dba_directories; 对于创建的目录必须授予用户读写目录的权限 grant read,write on directory dump_scott to scott; 二、数据泵的优点 在Oracel 10g 中提供的数据泵,较之i时代的导入导出工具(imp,exp),除了能实现imp/exp的功能之外,提供了更好的性能, 下面是数据泵的优点 为数据及数据对象提供更细微级别的选择性(使用exclude,include,content参数) 可以设定数据库版本号(主要是用于兼容老版本的数据库系统) 并行执行 预估导出作业所需要的磁盘空间(使用estimate_only参数) 支持分布式环境中通过数据库链接实现导入导出 支持导入时重新映射功能(即将对象导入到新的目标数据文件,架构,表空间等) 支持元数据压缩及数据采样 三、数据泵程序接口及模式 数据泵导入导出接口如下 命令行接口 参数文件 交互式命令行接口 数据库控制台 数据泵导入导出模式 整个数据库 架构 表 表空间 传输表空间 四、导出工具expdp 1. 它是操作系统下一个可执行的文件存放目录/ORACLE_HOME/bin [oracle@oradb bin]$ ls -lh expdp -rwxr-x--x 1 oracle oinstall 174K Sep 13 20:01 expdp expdp导出工具将数据库中数据备份压缩成一个二进制系统文件.可以在不同OS间迁移 expdb支持三种模式: a. 表模式: 导出用户所有表或者指定的表 b. 用户模式:导出用户所有对象以及对象中的数据 c. 导出表空间:导出数据库中特定的表空间 d. 整个数据库: 导出数据库中所有对象 使用expdp-? 可以查看expdp命令的用法并启动交互进程,也可使用expdp -help来查看更详细的帮助信息 [oracle@oradb bin]$ expdp -? abort_step Undocumented feature access_method Data Access Method - default is Automatic attach Attach to existing job - no default)"" compression Content to export: default is METADATA_ONLY content Content to export: default is ALL directory Default directory specification dumpfile dumpfile names: format is (file1,...) default is expdat.dmp encryption_password Encryption key to be used estimate Calculate size estimate: default is BLOCKS estimate_only Only estimate the length of the job: default is N exclude Export exclude option: no default filesize file size: the size of export dump files flashback_time database time to be used for flashback export: no default flashback_scn system change number to be used for flashback export: no default full indicates a full mode export include export include option: no default ip_address IP Address for PLSQL debugger help help: display description on export parameters, default is N job_name Job Name: no default)"" keep_master keep_master: Retain job table upon completion log_entry logentry logfile log export messages to specified file metrics Enable/disable object metrics reporting mp_enable Enable/disable multi-processing for current session network_link Network mode export nologfile No export log file created package_load Specify how to load PL/SQL objects parallel Degree of Parallelism: default is 1 parallel_threshold Degree of DML Parallelism parfile parameter file: name of file that contains parameter specifications query query used to select a subset of rows for a table sample Specify percentage of data to be sampled schemas schemas to export: format is "(schema1, .., schemaN)" silent silent: display information, default is NONE status Interval between status updates tables Tables to export: format is "(table1, table2, ..., tableN)" tablespaces tablespaces to transport/recover: format is "(ts1,..., tsN)" trace Trace option: enable sql_trace and timed_stat, default is 0 transport_full_check TTS perform test for objects in recovery set: default is N transport_tablespaces Transportable tablespace option: default is N tts_closure_check Enable/disable transportable containment check: def is Y userid user/password to connect to oracle: no default version Job version: Compatible is the default Export: Release 10.2.0.1.0 - Production on Monday, 20 September, 2010 14:22:56 Copyright (c) 2003, 2005, Oracle. All rights reserved. Username: 2. 导出工具expdp非交互式命令行方式的例子 a.基于表模式的导出 SQL> create directory dump_scott as "/home/oracle/dump/scott"; Directory created. SQL> select * from dba_directories; OWNER DIRECTORY_NAME DIRECTORY_PATH ------------------------------ ------------------------------ -------------------------------------------------- SYS DUMP_SCOTT /home/oracle/dump/scott SQL> grant read,write on directory dump_scott to scott; Grant succeeded. SQL> ! [oracle@oradb /]$ mkdir /home/oracle/dump [oracle@oradb /]$ mkdir /home/oracle/dump/scott [oracle@oradb ~]$ expdp scott/tiger directory=dump_scott dumpfile=dumptab.dmp / > logfile=scott.log tables=dept,emp Export: Release 10.2.0.1.0 - Production on Monday, 20 September, 2010 14:55:23 Copyright (c) 2003, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options Starting "SCOTT"."SYS_EXPORT_TABLE_01": scott/********/ directory=dump_scott dumpfile=dumptab.dmp logfile=scott.log tables=dept,emp Estimate in progress using BLOCKS method... Processing object type TABLE_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 128 KB Processing object type TABLE_EXPORT/TABLE/TABLE Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS . . exported "SCOTT"."DEPT" 5.656 KB 4 rows . . exported "SCOTT"."EMP" 7.820 KB 14 rows Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is: /home/oracle/dump/scott/dumptab.dmp Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 14:55:56 --后台中DMnn,DWnn进程为启动DataPump是产生的进程 [oracle@oradb /]$ ps -ef | grep ora_d oracle 3445 1 0 14:19 ? 00:00:00 ora_dbw0_orcl oracle 3461 1 0 14:19 ? 00:00:00 ora_d000_orcl [oracle@oradb ~]$ ls -lh /home/oracle/dump/scott total 132K -rw-r----- 1 oracle oinstall 124K Sep 20 14:55 dumptab.dmp -rw-r--r-- 1 oracle oinstall 1.4K Sep 20 14:55 scott.log b. 基于用户模式导出 [oracle@oradb /]$ expdp scott/tiger directory=dump_scott dumpfile=dumpscott.dmp schemas=scott Export: Release 10.2.0.1.0 - Production on Monday, 20 September, 2010 15:08:55 Copyright (c) 2003, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options Starting "SCOTT"."SYS_EXPORT_SCHEMA_01": scott/********/ directory=dump_scott dumpfile=dumpscott.dmp schemas=scott Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 192 KB Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA Processing object type SCHEMA_EXPORT/TABLE/TABLE Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS Processing object type SCHEMA_EXPORT/TABLE/COMMENT Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS . . exported "SCOTT"."DEPT" 5.656 KB 4 rows . . exported "SCOTT"."EMP" 7.820 KB 14 rows . . exported "SCOTT"."SALGRADE" 5.585 KB 5 rows . . exported "SCOTT"."BONUS" 0 KB 0 rows Master table "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SCOTT.SYS_EXPORT_SCHEMA_01 is: /home/oracle/dump/scott/dumpscott.dmp Job "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully completed at 15:09:23
使用Statspack进行Oracle性能分析数据泵IMPDP 导入工具的使用相关资讯 Oracle基础教程
- Oracle块编程返回结果集详解 (11/10/2013 10:45:58)
- Oracle基础教程之设置系统全局区 (08/22/2013 14:24:00)
- Oracle基础教程知识点总结 (06/18/2013 07:43:32)
| - Oracle基础教程之tkprof程序详解 (10/22/2013 11:49:50)
- Oracle基础教程之sqlplus汉字乱码 (07/18/2013 16:30:00)
- Oracle 管理之 Linux 网络基础 (02/16/2013 18:37:35)
|
本文评论 查看全部评论 (0)