你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle 并行原理深入解析及案例精粹

[日期:2012-08-12] 来源:Linux社区  作者:Leonarding [字体:大 中 小]
(12)直接加载和sqlload
sqlload 是我们常用的文本加载工具,它可以把文本文件按照一定的格式批量加载到数据库中去,现在我们测试传统加载conventional、直接加载direct、并行parallel直接加载的性能对比和执行效率。
-rwxrwxrwx   1 Oracle oinstall       283 Aug  9 00:11 leo_test.ctl     控制文件
-rwxrwxrwx   1 oracle oinstall   8983596 Aug  8 20:57 leo_test.data    数据文件,10万行数据,9个字段
-rwxrwxrwx   1 oracle oinstall      2099 Aug  9 00:15 leo_test.log     日志文件
1.传统加载conventional   10万行记录->表LEO_TEST_SQLLOAD 
 
sqlldr userid=ls/ls control=leo_test.ctl     传统加载数据
LS@LEO>  select count(*) from leo_test_sqlload;
  COUNT(*)
----------
    100000
SQL*Loader: Release 10.2.0.1.0 - Production on Thu Aug 9 00:14:15 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Control File:   leo_test.ctl                   控制文件
Data File:      /home/oracle/leo_test.data     数据文件
  Bad File:     leo_test.bad                   坏文件
  Discard File:  none specified
 (Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array:     64 rows, maximum of 256000 bytes
Continuation:    none specified
Path used:      Conventional                     sqlload采用传统加载方式,数据要通过缓冲区加载到表中
Table LEO_TEST_SQLLOAD, loaded from every logical record.
Insert option in effect for this table: APPEND   采用追加的方式加载,新数据不覆盖旧数据,而是结尾累加
TRAILING NULLCOLS option in effect
   Column Name                  Position   Len  Term Encl Datatype             列信息
------------------------------ ---------- ----- ---- ---- ---------------------
START_TIME                          FIRST     *   |       DATE YYYY-MM-DD HH24:MI:SS
END_TIME                             NEXT     *   |       DATE YYYY-MM-DD HH24:MI:SS
PROTOCOL                             NEXT     *   |       CHARACTER
PRIVATE_IP                           NEXT     *   |       CHARACTER
PRIVATE_PORT                         NEXT     *   |       CHARACTER
SRC_IP                               NEXT     *   |       CHARACTER
SRC_PORT                             NEXT     *   |       CHARACTER
DEST_IP                              NEXT     *   |       CHARACTER
DEST_PORT                            NEXT     *   |       CHARACTER
Table LEO_TEST_SQLLOAD:
  100000 Rows successfully loaded.               10万行记录成功加载
  0 Rows not loaded due to data errors.
  0 Rows not loaded because all WHEN clauses were failed.
  0 Rows not loaded because all fields were null.
Space allocated for bind array:                 148608 bytes(64 rows)
Read   buffer bytes: 1048576
Total logical records skipped:          0
Total logical records read:        100000
Total logical records rejected:         0
Total logical records discarded:        0
Run began on Thu Aug 09 00:14:15 2012
Run ended on Thu Aug 09 00:15:21 2012
Elapsed time was:     00:01:05.60                耗时65秒
CPU time was:         00:00:00.81
2.直接加载direct   10万行记录->表LEO_TEST_SQLLOAD1
LS@LEO> select df.tablespace_name "表空间名",totalspace "总空间M",freespace "剩余空间M",round((1-freespace/totalspace)*100,2) "使用率%"
from (select tablespace_name,round(sum(bytes)/1024/1024) totalspace from dba_data_files group by tablespace_name) df,
(select tablespace_name,round(sum(bytes)/1024/1024) freespace from dba_free_space group by tablespace_name) fs
 where df.tablespace_name=fs.tablespace_name order by df.tablespace_name ;  2    3    4    5
表空间名                           总空间M     剩余空间M     使用率%
------------------------------ ---------- ------------- ----------
CTXSYS                                 32            27      15.63
EXAMPLE                               200           199         .5
SYSAUX                                325           266      18.15
SYSTEM                                325            84      74.15
UNDOTBS                               200           189        5.5
USERS                                 600           501       16.5  没有加载表leo_test_sqlload1之前空间情况
sqlldr userid=ls/ls control=leo_test1.ctl data=leo_test.data log=leo_test1.log direct=true    直接加载10万行数据
LS@LEO> select count(*) from leo_test_sqlload1;
  COUNT(*)
----------
    100000 (3M)
LS@LEO>  select df.tablespace_name "表空间名",totalspace "总空间M",freespace "剩余空间M",round((1-freespace/totalspace)*100,2) "使用
率%"
from
(select tablespace_name,round(sum(bytes)/1024/1024) totalspace from dba_data_files group by tablespace_name) df,
 (select tablespace_name,round(sum(bytes)/1024/1024) freespace from dba_free_space group by tablespace_name) fs
 where df.tablespace_name=fs.tablespace_name order by df.tablespace_name ;   2    3    4    5
表空间名                          总空间M      剩余空间M    使用率%
------------------------------ ---------- ------------- ----------
CTXSYS                                 32            27      15.63
EXAMPLE                               200           199         .5
SYSAUX                                325           266      18.15
SYSTEM                                325            84      74.15
UNDOTBS                               200           189        5.5
USERS                                 600           498         17   10万行记录加载后使用了3M空间
SQL*Loader: Release 10.2.0.1.0 - Production on Thu Aug 9 01:07:52 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Control File:   leo_test1.ctl        控制文件
Data File:      leo_test.data        数据文件,10万行数据,9个字段
  Bad File:     leo_test.bad         坏文件
  Discard File:  none specified
 (Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Continuation:    none specified
Path used:      Direct               sqlload采用直接加载方式,数据不通过缓冲区和sql语法引擎直接加载到表中
Table LEO_TEST_SQLLOAD1, loaded from every logical record.
Insert option in effect for this table: APPEND     采用追加的方式加载,新数据不覆盖旧数据,而是结尾累加
TRAILING NULLCOLS option in effect
   Column Name                  Position   Len  Term Encl Datatype             列信息
------------------------------ ---------- ----- ---- ---- ---------------------
START_TIME                          FIRST     *   |       DATE YYYY-MM-DD HH24:MI:SS
END_TIME                             NEXT     *   |       DATE YYYY-MM-DD HH24:MI:SS
PROTOCOL                             NEXT     *   |       CHARACTER
PRIVATE_IP                           NEXT     *   |       CHARACTER
PRIVATE_PORT                         NEXT     *   |       CHARACTER
SRC_IP                               NEXT     *   |       CHARACTER
SRC_PORT                             NEXT     *   |       CHARACTER
DEST_IP                              NEXT     *   |       CHARACTER
DEST_PORT                            NEXT     *   |       CHARACTER
Table LEO_TEST_SQLLOAD1:
  100000 Rows successfully loaded.                     10万行记录成功加载,占用3M磁盘空间
  0 Rows not loaded due to data errors.
  0 Rows not loaded because all WHEN clauses were failed.
  0 Rows not loaded because all fields were null.
  Date cache:
   Max Size:      1000
   Entries :        65
   Hits    :    199935
   Misses  :         0
Bind array size not used in direct path.
Column array  rows :    5000
Stream buffer bytes:  256000
Read   buffer bytes: 1048576
Total logical records skipped:          0
Total logical records read:        100000
Total logical records rejected:         0
Total logical records discarded:        0
Total stream buffers loaded by SQL*Loader main thread:       26
Total stream buffers loaded by SQL*Loader load thread:       17
Run began on Thu Aug 09 01:07:52 2012
Run ended on Thu Aug 09 01:07:56 2012
Elapsed time was:     00:00:03.53                           耗时3秒.53  比  传统加载65秒节约了94%时间
CPU time was:         00:00:00.25
小结:因此我们知道直接加载要比传统加载执行效率高很多,当我们的系统负载不高,资源充裕时可以考虑使用直接加载direct方式批量导入数据,即减少了I/O和内存开销,又提高了数据加载效率。linux
相关资讯       Oracle并行原理 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款