发表于: 2007.06.20 17:02
分类: ORACLE
出处: http://yangtingkun.itpub.net/post/468/296889
---------------------------------------------------------------
前一阵在执行EXP导出的时候,发现居然EXP常规路径导出比EXP的直接路径导出速度还快。
常规路径导出比直接路径导出快的问题(一):http://yangtingkun.itpub.net/post/468/295932
常规路径导出比直接路径导出快的问题(二):http://yangtingkun.itpub.net/post/468/296311
这篇文章继续分析导致问题的原因。
上面一篇文章已经提到了产生问题的主要原因是直接路径导出的缓冲问题,这里详细说明一下。
在导出的时候制定的BUFFER参数,用来设置导出时的数据缓冲区大小,但是这个参数只对常规路径导出生效,要设置直接路径导出的参数,需要使用RECORDLENGTH参数。
前面所有的对比,都没有站在同一个基准线上。在前面的测试中,常规路径导出的BUFFER大小设置为20M,而对于直接路径导出,其实采用的是默认值。即使是这样,在本地导出的时候,直接路径仍然要比常规路径速度快一下。
下面看看设置了RECORDLENGTH的情况,首先是本地导出的情况:
$ exp data_demo/data_demo file=direct_data.dmp direct=y recordlength=65535
Export: Release 9.2.0.4.0 - Production on Wed Jun 20 15:31:28 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user DATA_DEMO
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user DATA_DEMO
About to export DATA_DEMO's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export DATA_DEMO's tables via Direct Path ...
. . exporting table ACCESS_LOG 93888 rows exported
. . exporting table ASS_BBS_ARTICLE 0 rows exported
. . exporting table ASS_BBS_CATALOG 0 rows exported
. . exporting table ASS_BBS_USERINFO 0 rows exported
. . exporting table ASS_COMPLAIN_ORG_SCORE 0 rows exported
. . exporting table ASS_COMPLAIN_RECORD 0 rows exported
. . exporting table ASS_COMPLAIN_REPLY 0 rows exported
. . exporting table ASS_COMPLAIN_TYPE 0 rows exported
. . exporting table ASS_NEWS 2 rows exported
. . exporting table ASS_NEWS_TYPE 1 rows exported
. . exporting table A_CAT_BUYER 6283 rows exported
. . exporting table A_CAT_REGION_MERCHANDISE_BAK 12666 rows exported
.
.
.
. . exporting table Z_NEED_SEQS 55 rows exported
. . exporting table Z_REG_USER 0 rows exported
. . exporting table Z_USER_INFO 665 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.
$ ls -l direct_data.dmp
-rw-r--r-- 1 oracle dba 2411294790 Jun 20 15:34 direct_data.dmp
直接路径导出仅仅用了3分钟左右就完成了导出。下面看看在客户端导出的情况:
$ exp data_demo/data_demo@zjtrade file=direct_data.dmp direct=y recordlength=65535
Export: Release 9.2.0.4.0 - Production on 星期三 6月 20 14:56:24 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user DATA_DEMO
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user DATA_DEMO
About to export DATA_DEMO's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export DATA_DEMO's tables via Direct Path ...
. . exporting table ACCESS_LOG 93888 rows exported
. . exporting table ASS_BBS_ARTICLE 0 rows exported
. . exporting table ASS_BBS_CATALOG 0 rows exported
. . exporting table ASS_BBS_USERINFO 0 rows exported
. . exporting table ASS_COMPLAIN_ORG_SCORE 0 rows exported
. . exporting table ASS_COMPLAIN_RECORD 0 rows exported
. . exporting table ASS_COMPLAIN_REPLY 0 rows exported
. . exporting table ASS_COMPLAIN_TYPE 0 rows exported
. . exporting table ASS_NEWS 2 rows exported
. . exporting table ASS_NEWS_TYPE 1 rows exported
. . exporting table A_CAT_BUYER 6283 rows exported
. . exporting table A_CAT_REGION_MERCHANDISE_BAK 12666 rows exported
.
.
.
. . exporting table Z_NEED_SEQS 55 rows exported
. . exporting table Z_REG_USER 0 rows exported
. . exporting table Z_USER_INFO 665 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.
$ ls -l direct_data.dmp
-rw-r--r-- 1 oracle dba 2411294790 6月 20 15:06 direct_data.dmp
加上RECORDLENGTH参数后,通过客户端导出只用了10分钟,这个速度已经赶上常规路径在本地导出的速度了。
回过头再看不加RECORDLENGTH参数的情况,DIRECT路径导出居然用了1个多小时,判断问题主要是由于本地缓冲太小,每次数据写入数据量很小,造成网络请求频繁发生,怀疑大部分的时间是发生在网络传递上。
为了验证刚才的设想,通过客户端再次执行不带RECORDLENGTH参数的直接路径导出操作,等待导出操作进行了一段时间后,登陆到服务器,检查导出操作的会话状态:
SQL> select sid from v$session where program like 'exp%';
SID
----------
47
SQL> select event, total_waits, time_waited from v$session_event where sid = 47;
EVENT TOTAL_WAITS TIME_WAITED
------------------------------ ----------- -----------
direct path read 5311 102
SQL*Net message to client 620493 48
SQL*Net message from client 620492 118710
从等待进行上看,Oracle用于等待交互的次数要比真正的读操作多100次,而等待时间更是读操作的1000倍,看来大部分时间是花费在网络交互上了。
最后看看在客户端如果设置RECORDLENGTH参数的情况:
SQL> select sid from v$session where program like 'exp%';
SID
----------
47
SQL> select event, total_waits, time_waited from v$session_event where sid = 47;
EVENT TOTAL_WAITS TIME_WAITED
------------------------------ ----------- -----------
direct path read 4107 6
SQL*Net message to client 24572 2
SQL*Net more data to client 7252 3615
SQL*Net message from client 24572 7081
这个差别就很明显了,至此问题告一段落。
最后总结几句。
第一:根据Oracle文档对直接路径导出的描述,直接路径导出肯定要比常规路径导出快,这对于绝大部分的情况都是正确的,但是万事没有绝对,如果设置了不正确的参数,很可能会造成完全不一样的结果。
第二:任何奇怪的现象背后,都有造成这个问题的真正原因。如果不去探索、挖掘,除了觉得奇怪之外,不会有什么其他的收获了,最多不过在碰到类似的情况下,说这个问题我也碰到过。
第三:强调一下文档的重要性。很多人总是对文档不以为然,却不知道99%的Oracle问题的答案在文档中都可以找到。也有人认为,文档就是一个参考,有了问题才需要看,但是有些时候,如果你根本没有看过文档的话,很可能在你出现问题的时候,根本就不知道该查看哪篇文档,或者该搜索哪些内容。











