当前位置:操作系统 > Unix/Linux >>

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

exp/imp与expdp/impdp对比及使用中的一些优化事项
 
一. 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]
 
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]
 
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. 
 
(1)Direct 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. 
 
(2)External 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.
 
(3)Data 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. 
 
这种模式很方便,但是速度是最慢的,因为它是通过insert,select + dblink来实现的。 速度慢也由此可见了。
 
创建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 这样。
  
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 =foo 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 content(ALL:对象+导出数据行,DATA_ONLY:只导出对象,METADATA_ONLY:只导出数据的记录) 
 
二. 使用中的优化事项
2.1 EXP
通过上面的
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,