您的位置:首页 > 数据库 > Oracle

Oracel exp/imp 优化

2015-10-22 10:32 387 查看

Oracel exp/imp 优化

来源:整理至网络。

注意:exp/imp后面的账户需要有管理员权限

exp system/manager FILE=exp_full.dmp LOG=exp_full.log FULL=y DIRECT=y RECORDLENGTH=65535

imp system/manager FILE=exp_full.dmp LOG=imp_full.log FULL=y RECORDLENGTH=65535

exp 优化

1、导出指定表数据:

a)导出表数据和表结构


exp username/password@sid feedback=100000 buffer=65536 tables=() file=xxx


b)只导出表结构


exp username/password@sid feedback=100000 buffer=65536 tables=() rows=n file=xxx


2、导出指定用户数据:

exp uboss_etl/uboss_etl@orcl owner=etl_pbid feedback=100000 buffer
=65536 file=d:\java_temp\t2.dmp


3、导出全库

exp uboss_etl/uboss_etl@orcl fully=y feedback=100000 buffer
=65536 file=d:\java_temp\t2.dmp


上述导出方式也有另一种写法:

exp uboss_etl/uboss_etl@sid direct=y recordlength=65535 feedback=100000 tables=(xxx) file=xxx


这种写法比上面方式更快。
原因:

( 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。 少了一个过程,导出速度提高也是很明显。

一些限制如下: 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 只能在 conventional path 模式下使用。 In versions of Export prior to 8.1.5, you could not use direct path Export for tables containing objects and LOBs.
-如果 exp 版本小于 8.1.5,不能使用 exp 导入有 lob 字段的 biao。 不过现在很
少有有 8 版本的数据库了。 这点可以忽略掉了。 The BUFFER parameter applies ONLY to conventional path Export. It has no effect on a direct path Export. This BUFFER parameter specifies the size (in bytes) of the
buffer used to fetch rows. It determines the maximum number of rows in an array,
fetched by Export. For direct path Export, use the RECORDLENGTH parameter to specify the size of the buffer that Export uses for writing to the export file.
-- buffer 选项只对 conventional path exp 有效。 对于直接路径没有影响。 对于
直接路径, 应该设置 RECORDLENGTH 参数。
The RECORDLENGTH parameter specifies the length (in bytes) of the file record. You can use this parameter to specify the size of the Export I/O buffer (highest value is 64 kb). Changing the RECORDLENGTH parameter affects only the size of data that accumulates before writing to disk. It does not affect the operating system file block size. If you do not define this parameter, it defaults to your platform-dependent value for BUFSIZ (1024 bytes in most cases).
invoking a Direct path Export with a maximum I/O buffer of 64kb can improve the
performance of the Export with almost 50%. This can be achieved by specifying the additional Export parameters DIRECT and RECORDLENGTH
-- 对于直接路径下, RECORDLENGTH 参数建议设成 64k( 65535)。 这个值对性能提高比较大。 如:


> exp system/manager FILE=exp_full.dmp LOG=exp_full.log FULL=y DIRECT=y RECORDLENGTH=65535
> imp system/manager FILE=exp_full.dmp LOG=imp_full.log FULL=y RECORDLENGTH=65535


IMP 优化:

原则:减少IO竞争

imp user/pwd fromuser=user1 touser=user2 file=/tmp/imp_db_pipe1 commit=y feedback=10000 buffer=10240000 ignore=y rows=y indexes=n
imp user/pwd fromuser=user1 touser=user2 file=/tmp/imp_index_pipe1 commit=y feedback=10000 buffer=10240000 ignore=y rows=n indexes=y


2.3.2.2 IMP Oracle Import 进程需要花比 Export 进程数倍的时间将数据导入数据库。某些关键时刻,导入是为了应对数据库的紧急故障恢复。为了减少宕机时间,加快导入速度显得至关重要。没有特效办法加速一个大数据量的导入,但我们可以做一些适当的设定以减少整个导入时间。

( 1)避免 I/O 竞争 Import 是一个 I/O 密集的操作,避免 I/O 竞争可以加快导入速度。如果可能,不要在系统高峰的时间导入数据,不要在导入数据时运行 job 等可能竞争系统资源的操作。

( 2)增加排序区 Oracle Import 进程先导入数据再创建索引,不论 INDEXES 值设为 YES 或者 NO,主键的索引是一定会创建的。创建索引的时候需要用到排序区,在内存大小不足的时候,使用临时表空间进行磁盘排序,由于磁盘排序效率和内存排序效率相差好几个数量级。增加排序区可以大大提高创建索引的效率,从而加快导入速度。
( 3)调整 BUFFER 选项 Imp 参数 BUFFER 定义了每一次读取导出文件的数据量,设的越大,就越减少 Import 进程读取数据的次数,从而提高导入效率。 BUFFER 的大小取决于系统应用、数据库规模,通常来说,设为百兆就足够了。其用法如下: imp user/pwd fromuser=user1 touser=user2 file=/tmp/imp_db_pipe1 commit=y feedback=10000 buffer=10240000

( 4)使用 COMMIT=Y 选项 COMMIT=Y 表示每个数据缓冲满了之后提交一次,而不是导完一张表提交一次。这样会大大减少对系统回滚段等资源的消耗,对顺利完成导入是有益的。

( 5)使用 INDEXES=N 选项
前面谈到增加排序区时,说明 Imp 进程会先导入数据再创建索引。导入过程中建立用户定义的索引,特别是表上有多个索引或者数据表特别庞大时,需要耗费大量时间。某些情况下,需要以最快的时间导入数据,而索引允许后建,我们就可以使用 INDEXES=N 只导入数据不创建索引,从而加快导入速度。

我们可以用 INDEXFILE 选项生成创建索引的 DLL 脚本,再手工创建索引。我们也可以用如下的方法导入两次,第一次导入数据,第二次导入索引。其用法如下:


imp user/pwd fromuser=user1 touser=user2 file=/tmp/imp_db_pipe1 commit=y feedback=10000 buffer=10240000 ignore=y rows=y indexes=n
imp user/pwd fromuser=user1 touser=user2 file=/tmp/imp_index_pipe1 commit=y feedback=10000 buffer=10240000 ignore=y rows=n indexes=y


( 6)增加 LARGE_POOL_SIZE
如果在 init.ora 中配置了 MTS_SERVICE, MTS_DISPATCHERS 等参数, tnsnames.ora 中又没有(SERVER=DEDICATED)的配置,那么数据库就使用了共享
服务器模式。在 MTS 模式下, Exp/Imp 操作会用到 LARGE_POOL,建议调整 LARGE_POOL_SIZE 到 150M。
检查数据库是否在 MTS 模式下: SQL>select distinct server from v$session;
如果返回值出现 none 或 shared,说明启用了 MTS。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息