新聞中心
文章主要描述的是DB2數(shù)據(jù)復制與數(shù)據(jù)庫遷移的實際操作方法,文章所提供的方法是經過測試的,運行在環(huán)境IBM x346,3.2G×2,4G,RAID 1,DB2 V8.2.4,Win2000 Adv Server下,DMS表空間中,數(shù)據(jù)的load速度在60-100萬條/min左右。

創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都做網站、網站制作、企業(yè)官網、英文網站、手機端網站、網站推廣等服務,滿足客戶于互聯(lián)網時代的龍游網站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網解決方案。努力成為您成熟可靠的網絡建設合作伙伴!
背景:需要更改數(shù)據(jù)庫表空間,或者需要將數(shù)據(jù)庫中所有表的數(shù)據(jù)遷移到一個新的數(shù)據(jù)庫中。
步驟:
1. 通過db2控制臺(db2cc)選中源數(shù)據(jù)庫中的所有表,將其導出成DDL腳本;
2. 根據(jù)需要對腳本進行必要的修改,譬如更改表空間為GATHER;
3. 新建數(shù)據(jù)庫,新建DMS表空間:GATHER;
4. 將DDL腳本在此數(shù)據(jù)庫中執(zhí)行;
5. 編寫代碼查詢源數(shù)據(jù)庫中的所有表,自動生成export腳本;
6. 編寫代碼查詢源數(shù)據(jù)庫中的所有表,自動生成import腳本;
7. 連接源數(shù)據(jù)庫執(zhí)行export腳本;
8. 連接目標DB2數(shù)據(jù)復制執(zhí)行import腳本;
附錄1:生成export腳本代碼示例:/**
- * 創(chuàng)建導出腳本
- * @param conn
- * @param creator 表創(chuàng)建者
- * @param filePath
- */
- public void createExportFile(Connection conn,String creator,String filePath) throws Exception {
- DBBase dbBase = new DBBase(conn);
- String selectTableSql = "select name from sysibm.systables where creator = '" + creator + "' and type='T'";
- try {
- dbBase.executeQuery(selectTableSql);
- } catch (Exception ex) {
- throw ex;
- } finally {
- dbBase.close();
- }
- DBResult result = dbBase.getSelectDBResult();
- List list = new ArrayList();
- while (result.next()) {
- String table = result.getString(1);
- list.add(table);
- }
- StringBuffer sb = new StringBuffer();
- String enterFlag = "\r\n";
- for (int i = 0; i < list.size();i++) {
- String tableName = (String)list.get(i);
- sb.append("db2 \"export to aa" + String.valueOf(i+1)+ ".ixf of ixf select * from " + tableName + "\"");
- sb.append(enterFlag);
- }
- String str = sb.toString();
- FileUtility.saveStringToFile(filePath, str, false);
- }
附錄2:生成import腳本代碼示例:/**
- * 創(chuàng)建裝載腳本
- * @param conn
- * @param creator 表創(chuàng)建者
- * @param filePath
- */
- public void createLoadFile(Connection conn,String creator,String filePath) throws Exception {
- DBBase dbBase = new DBBase(conn);
- String selectTableSql = "select name from sysibm.systables where creator = '" + creator + "' and type='T'";
- try {
- dbBase.executeQuery(selectTableSql);
- } catch (Exception ex) {
- throw ex;
- } finally {
- dbBase.close();
- }
- DBResult result = dbBase.getSelectDBResult();
- List list = new ArrayList();
- while (result.next()) {
- String table = result.getString(1);
- list.add(table);
- }
- StringBuffer sb = new StringBuffer();
- String enterFlag = "\r\n";
- for (int i = 0; i < list.size();i++) {
- String tableName = (String)list.get(i);
- sb.append("db2 \"load from aa" + String.valueOf(i+1)+ ".ixf of ixf into " + tableName + " COPY NO without prompting \"");
- sb.append(enterFlag);
- }
- String str = sb.toString();
- FileUtility.saveStringToFile(filePath, str, false);
- }
附錄3:export腳本示例db2 connect to testdb user test password test
- db2 "export to aa1.ixf of ixf select * from table1"
- db2 "export to aa2.ixf of ixf select * from table2"
- db2 connect reset
附錄4:import腳本示例db2 connect to testdb user test password test
- db2 "load from aa1.ixf of ixf replace into table1 COPY NO without prompting "
- db2 "load from aa2.ixf of ixf replace into table2 COPY NO without prompting "
- db2 connect reset
以上的相關內容就是對DB2數(shù)據(jù)復制和遷移方法的介紹,望你能有所收獲。
當前文章:DB2數(shù)據(jù)復制與數(shù)據(jù)庫遷移追根述源
文章網址:http://m.fisionsoft.com.cn/article/copcoee.html


咨詢
建站咨詢
