關於sybase中的快bcp

來源:互聯網
上載者:User

----------------------------------------------------------------------------

---- 本文為andkylee個人原創,請在尊重作者勞動成果的前提下進行轉載;

---- 轉載務必註明原始出處
:
http://blog.csdn.net/andkylee

---- 關鍵字: sybase BCP fast 日誌 索引  快bcp  慢bcp 完整備份 記錄備份

----------------------------------------------------------------------------

 

在sybase中複製資料時,經常能夠解決到bcp(bulk copy)。

bcp分兩種,快bcp和慢bcp。這兩種分法是針對bcp in。對於bcp out個人感覺沒有快、慢之分,反正就是從sybase的extent上大塊大塊的拷資料。

 

今天在bcp 資料in 到一個sybase server的時候,報下面的錯誤:

C:/Documents and Settings/Administrator>bcp test.dbo.tablename in d:/12<br />34 -c -Usa -Saix<br />Password:<br />Starting copy...<br />Server Message: SYB_AIX53 - Msg 4806, Level 16, State 1:<br />You cannot run the non-logged version of bulk copy in this database. Please chec<br />k with the DBO.<br />Server Message: SYB_AIX53 - Msg 3621, Level 10, State 0:<br />Command has been aborted.<br />CTLIB Message: - L1/O3/S0/N14/0/0:<br />blk_init(): blk layer: CT library error: Failed when CT_Lib routine ct_results()<br /> called.<br />blk_init failed.<br />bcp copy in failed

 

上error message & troubleshooting guide上查看一下錯誤編號為:4806的資訊。

解釋如下:

This error occurs when the select/into bulkcopy option is set to “false” and you
use “fast” bulk copy into a table that has no indexes.
Note
In newly created databases, the select into/bulkcopy option is set (by
default) to the same as that in model.

 

解決的辦法有兩種:

第一:

啟用目的庫的"select/into bulkcopy"選項,使用fast bcp模式。這樣會不計日誌(實際上是記錄很少很少的日誌記錄),也就是說:這不能保證資料庫日誌的一致性,最好對目的資料庫做一個完全備份(dump database),之後才能備份日誌。

 

補充一點:針對有些不計日誌的操作導致備份日誌不能執行的問題,唯一的辦法就是對庫做全備。但是,尤其在select into/bulk選項被開啟的資料庫上,你如何知道這個資料庫裡曾經執行了不計日誌的操作呢?15.0以前的版本是沒有好辦法的,只能在發出dump tran命令的時候提示不能備份日誌需先全備。這是很等的不方便啊~<br />終於在15.0版本中,千呼萬喚始出來。sybase給我們送來了福音。增加了函數:tran_dumptable_status(),用來返回一個是否允許 dump transaction 的真/ 假指示。<br />如果 tran_dumpable_status 返回 0,則可以對資料庫執行 dump transaction<br />命令。如果返回任何其它值,則無法執行該命令。非零值有:<br /> 1 — 指定名稱的資料庫不存在。<br /> 2 — 日誌沒有放置在單獨的裝置上。<br /> 4 — 日誌首頁位於僅限資料的磁碟片段地區內。<br /> 8 — 為資料庫設定了 trunc log on chkpt 選項。<br /> 16 — 在資料庫上發生了未記錄的寫入操作。<br /> 32 — 僅截斷 dump tran 已中止發送到傾印裝置的任意連續的轉儲<br />系列。<br /> 64 — 最近建立或升級了資料庫。在執行 dump database 之前,不會<br />轉儲交易記錄。<br />現在終於可以在備份指令碼加入tran_dumptable_status(),如果返回0,表示可以正常執行備份日誌任務。如果返回非0尤其16或者32的時候,先執行資料庫全備再執行dump tran操作。

 

 

第二:給將要拷貝資料的表上添加索引,讓bcp使用慢模式。這樣目的資料庫會正常的記錄日誌。就像一條一條的insert語句那樣。因此,不會出現完備後才能備份日誌的情況了。但是要注意防止大量的寫入操作導致目的資料庫日誌被寫滿。可以在bcp in的時候適當時間執行dump transaction with truncate_only,也可以資料分批bcp匯入(需要加入-b選項)。

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.