大大量匯入匯出資料的一點體會。

來源:互聯網
上載者:User

 今天我測試了下大量匯入匯出資料。

 

首先,我用spool從A資料庫中匯出資料到一個文字檔,但是發現速度有些慢。因為表中資料有120多萬條。後來就用pl/sql裡面的export query將資料匯出到csv檔案,這樣速度是快。可是這樣匯出的檔案,用sqlldr匯入到新庫中去的時候,老是報錯。而我查了資料,資料是沒有問題的。最後,我用toad裡面的"Save Grid Contents",匯出檔案格式為txt,這個時候,資料才沒有問題。可以順利的匯入到新庫中去。只是匯入速度上還不是特別滿意,但是還湊合著用了。估計是我機器效能不是太好的原因。

 

Save Grid Contents的按鈕如下:

 

 

樣本:

1,exp_customer.sql。   查詢資料。這個用過,但是速度不行。還不如用toad匯出資料為txt。

set echo off            --是否顯示執行的命令內容 
set feedback off       --是否顯示 *   rows   selected 
set heading off        --是否顯示欄位的名稱
set verify off         --是否顯示替代變數被替代前後的語句。fil
set trimspool off      --去欄位空格
set pagesize 50000     --頁面大小
set linesize 50           --linesize設定盡量根據需要來設定,大了產生的檔案也大
define fil= 'E:/1120/customer_data.txt'
spool &fil
select customerid || '@@' || customername || '@@' || sex || '@@' ||
       customertype || '@@' || papertype || '@@' || paperno || '@@' ||
       customerclass || '@@' || industry || '@@' || status || '@@' ||
       postlevel || '@@' || operatorcode || '@@' ||
       to_char(createtime, 'yyyy-mm-dd hh24:mi:ss') || '@@' || remark || '@@' ||
       busipassword || '@@' || customerprops || '@@' ||
       to_char(statusupdatetime, 'yyyy-mm-dd hh24:mi:ss') || '@@' ||
       passwdlevel
  from t_customerinfo ci;
spool off

2,customer.ctl。控制檔案。為sqlldr所用。

OPTIONS (ROWS=10000)
LOAD DATA
INFILE 'cust_20091120.txt'
BADFILE 'customer.bad'
replace
INTO TABLE t_customerinfo
FIELDS TERMINATED BY "@@"
(customerid,customername,sex,customertype,papertype,paperno,customerclass,industry,status,postlevel,operatorcode,createtime"TO_DATE(:createtime,'yyyy-mm-dd hh24:mi:ss')",remark,busipassword,customerprops,statusupdatetime"TO_DATE(:statusupdatetime,'yyyy-mm-dd hh24:mi:ss')",passwdlevel)

3,customerimp.cmd。批次檔,執行匯入。

sqlldr lzf/lzf@testdb control=customer.ctl

 

 


最後,需要提醒的是,在匯入之前,表上面最好不要有主鍵、索引之類的,因為會非常影響速度。

我剛開始沒有刪除主鍵、索引,所以速度很慢,刪除這些東西後,匯入進去120多萬條資料,只需要1分多鐘。

等到資料全部匯入之後,在在表上建主鍵、索引。
我測試的結果是,120w條資料,建立主鍵所花費的時間是17秒。

索引則更快些。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.