现在的位置: 首页 > 综合 > 正文

exp/imp 与 expdp/impdp 对比 及使用中的一些优化事项

2012年07月19日 ⁄ 综合 ⁄ 共 6683字 ⁄ 字号 评论关闭

 

关于exp/imp expdp/impdp 之前整理的2Blog如下:

 

ORACLE 数据库逻辑备份 简单 EXP/IMP

http://blog.csdn.net/tianlesoftware/archive/2009/10/23/4718366.aspx

 

Oracle 10g EXPDPIMPDP使用说明

http://blog.csdn.net/tianlesoftware/archive/2009/10/16/4674224.aspx

 

 

. exp/imp expdp/impdp 对比

 

1.1 expdp/impdp调用Server端的API在执行操作,是数据库内部的job任务。可以远程使用,但是生成的dump 文件存在于服务器上的directory里。

 

1.2  exp/imp expdp/impdp 的默认模式和原理不一样

 

1.2.1 exp/imp 不同模式原理

metalink的这边文章中,提到了exp/imp的不同模式下的工作原理:

Parameter DIRECT: Conventional Path Export Versus Direct Path Export [ID 155477.1]

http://blog.csdn.net/tianlesoftware/archive/2010/12/22/6090759.aspx

 

 

Starting with Oracle7 release 7.3, the Export utility provides two methods for exporting table data:

- Conventional Path Export

- Direct Path Export

 

1 Conventional path Export.

Conventional path Export uses the SQL SELECT statement to extract data from tables. Data is read from disk into the buffer cache, and rows are transferred to the evaluating buffer. The data, after passing expression evaluation, is transferred to the Export client, which then writes the data into the export file.

 

            exp/imp 默认会是传统路径, 这种模式下,是用SELECT 加数据查询出来, 然后写入buffer cache 在将这些记录写入evaluate buffer. 最后传到Export客户端,在写入dump文件。

 

 

 

2 Direct path Export.

            When using a Direct path Export, the data is read from disk directly into the export session's program global area (PGA): the rows are transferred directly to the Export session's private buffer. This also means that the SQL command-processing layer (evaluation buffer) can be bypassed, because the data is already in the format that Export expects. As a result, unnecessary data conversion is avoided. The data is transferred to the Export client, which then writes the data into the export file.

 

The default is DIRECT=N, which extracts the table data using the conventional path.

 

This parameter is only applicable to the original export client. Export DataPump (expdp) uses a Direct Path unload by default and switches to External Table mode if required

 

            直接路径模式下,数据直接从硬盘读取,然后写入PGA 格式就是export 的格式,不需要转换, 数据再直接传到export 客户端,写入dump 文件。 这种模式没有经过evaluation buffer 少了一个过程,导出速度提高也是很明显。

 

 

1.2.2 expdp/impdp 不同模式

            Export/Import DataPump Parameter ACCESS_METHOD - How to Enforce a Method of Loading and Unloading Data ? [ID 552424.1]

            http://blog.csdn.net/tianlesoftware/archive/2010/12/22/6090757.aspx

 

            The two most commonly used methods to move data in and out of databases with Data Pump are the "Direct Path" method and the "External Tables" method.

 

1Direct Path mode.

After data file copying, direct path is the fastest method of moving data. In this method, the SQL layer of the database is bypassed and rows are moved to and from the dump file with only minimal interpretation. Data Pump automatically uses the direct path method for loading and unloading data when the structure of a table allows it.

 

expdp/impdp 默认就是使用直接路径的,所以expdp要比exp块。

 

2External Tables mode.

            If data cannot be moved in direct path mode, or if there is a situation where parallel SQL can be used to speed up the data move even more, then the external tables mode is used. The external table mechanism creates an external table that maps the dump file data for the database table. The SQL engine is then used to move the data. If possible, the APPEND hint is used on import to speed the copying of the data into the database.

Note: When the Export NETWORK_LINK parameter is used to specify a network link for an export operation, a variant of the external tables method is used. In this case, data is selected from across the specified network link and inserted into the dump file using an external table.

 

3Data File Copying mode.

            This mode is used when a transport tablespace job is started, i.e.: the TRANSPORT_TABLESPACES parameter is specified for an Export Data Pump job. This is the fastest method of moving data because the data is not interpreted nor altered during the job, and Export Data Pump is used to unload only structural information (metadata) into the dump file.

 

4 Network Link Import mode.

            This mode is used when the NETWORK_LINK parameter is specified during an Import Data Pump job. This is the slowest of the four access methods because this method makes use of an INSERT SELECT statement to move the data over a database link, and reading over a network is generally slower than reading from a disk.

 

这种模式很方便,但是速度是最慢的,因为它是通过insertselect + dblink来实现的。 速度慢也由此可见了。

 

示例:

create directory dump1 as '/oradata/dumpfiles';
grant read,write on dump1 to xxx;

 

创建DBLINK:

/* Formatted on 2010/12/23 11:28:22 (QP5 v5.115.810.9015) */

CREATE DATABASE LINK TIANLESOFTWARE

 CONNECT TO BUSINESS

 IDENTIFIED BY <PWD>

 USING

      '(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = IP ADDRESS)(PORT = 1521))

)

(CONNECT_DATA =

(SID = ORCL)

(SERVER = DEDICATED)

)

)';

 

Dumpfile 参数 ,可以用%U 指定

expdp xxx/xxx schemas=xxx  directory=dump1  dumpfile=xxx_%U.dmp filesize=5g

这样每个文件5G xxx_01.dump,xxx_02.dump 这样。

 

关于%U参考:

http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/dp_overview.htm#sthref44

 

在下文也会讲到这点。

 

expdp xxx/xxx schemas=xxx  directory=dump1 network_link =dbl_65 dumpfile=xxx_01.dump ,xxx_02.dump

这样也可以,但不确定xxx_01.dump增到多大才开始写xxx_02.dump文件。

 

ESTIMATE_ONLY=y 可以估计文件大小。

NETWORK_LINK:这样就可以不必一定在本机expdp,也可以在目标机通过 NETWORK_LINK 把从文件抽到目标机上。

expdp xxx/xxx schemas=xxx  directory=dump1 network_link =tianlesoftware dumpfile=xxx_%U.dump filesize=10m
或者用impdp + network_link 实现无文件导入

 

需要注意,LOB字段可以使用NETWORK_LINK ,而long类型字段会报错,

ORA-31679: Table data object "xx"."SYS_USER" has long columns, and longs can not be loaded/unloaded using a network link

 

1.3  网络和磁盘影响

            expdp/impdp 是服务端程序,影响它速度的只有磁盘IO

            exp/imp 可以在服务端,也可以在客户端。所以,它受限于网络和磁盘。

 

1.4 exp/imp expdp/impdp 功能上的区别

1把用户usera的对象导到用户userb,用法区别在于fromuser=usera touser=userb ,remap_schema='usera':'userb' 。例如

            imp system/passwd fromuser=usera touser=userb file=/oracle/exp.dmp log=/oracle/exp.log;

            impdp system/passwd directory=expdp dumpfile=expdp.dmp remap_schema='usera':'userb' logfile=/oracle/exp.log;

2更换表空间,用exp/imp的时候,要想更改表所在的表空间,需要手工去处理一下,如alter table xxx move tablespace_new之类的操作。用impdp只要用remap_tablespace='tabspace_old':'tablespace_new'

3当指定一些表的时候,使用exp/imp tables的用法是 tables=('table1','table2','table3')expdp/impdp用法tables='table1','table2','table3'

 

4是否要导出数据行

            exp (ROWS=Y 导出数据行,ROWS=N 不导出数据行)

            expdp contentALL:对象+导出数据行,DATA_ONLY:只导出对象,METADATA_ONLY:只导出数据的记录)

 

 

. 使用中的优化事项

 

2.1  exp

            通过上面的分析,知道采用direct path可以提高导出速度。 所以,在使用exp时,就可以采用直接路径模式。 这种模式有2个相关的参数:DIRECT RECORDLENGTH参数。

 

  DIRECT参数定义了导出是使用直接路径方式(DIRECT=Y),还是常规路径方式(DIRECT=N)。常规路径导出使用SQL SELECT语句从表中抽取数据,直接路径导出则是将数据直接从磁盘读到PGA再原样写入导出文件,从而避免了SQL命令处理层的数据转换过程,大大提高了导出效率。在数据量大的情况下,直接路径导出的效率优势更为明显,可比常规方法速度提高三倍之多。

 

  和DIRECT=Y配合使用的是RECORDLENGTH参数,它定义了Export I/O缓冲的大小,作用类似于常规路径导出使用的BUFFER参数。建议设置RECORDLENGTH参数为最大I/O缓冲,即65535(64kb)。其用法如下:

            如:exp userid=system/manager full=y direct=y recordlength=65535 file=exp_full.dmp log=exp_full.log

 

 

一些限制如下:

            You cannot use the DIRECT=Y parameter when exporting in tablespace-mode  (i.e. when specifying the parameter TRANSPORT_TABLESPACES=Y).  You can use the DIRECT=Y parameter when exporting in full, user or table mode (i.e.: when specifying FULL=Y or OWNER=scott or TABLES=scott.emp).

--直接路径不能使用在tablespace-mode

 

The parameter QUERY applies ONLY to conventional path Export. It cannot be specified in a direct path export (DIRECT=Y).

-- 直接路径不支持query 参数。 query 只能

抱歉!评论已关闭.