国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > DB2 > 正文

IBM DB2 的數據復制、遷移方法

2024-09-06 23:58:07
字體:
來源:轉載
供稿:網友

db2數據復制、遷移方法

以下方法經測試,在環境ibm x346,3.2g×2,4g,raid 1,db2 v8.2.4,win2000 adv server,dms表空間中,數據的load速度在60-100萬條/min左右。

背景:需要更改數據庫表空間,或者需要將數據庫中所有表的數據遷移到一個新的數據庫中。

步驟:

1.通過db2控制臺(db2cc)選中源數據庫中的所有表,將其導出成ddl腳本;

2.根據需要對腳本進行必要的修改,譬如更改表空間為gather;

3.新建數據庫,新建dms表空間:gather;

4.將ddl腳本在此數據庫中執行;

5.編寫代碼查詢源數據庫中的所有表,自動生成export腳本;

6.編寫代碼查詢源數據庫中的所有表,自動生成import腳本;

7.連接源數據庫執行export腳本;

8.連接目標數據庫執行import腳本;

附錄1:生成export腳本代碼示例:

/**

* 創建導出腳本

* @param conn

* @param creator 表創建者

* @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腳本代碼示例:

/**

* 創建裝載腳本

* @param conn

* @param creator 表創建者

* @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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宜兰市| 田阳县| 景洪市| 盐边县| 广汉市| 临邑县| 仙游县| 濮阳市| 南皮县| 西平县| 鄂托克前旗| 西乡县| 长春市| 克山县| 商都县| 南木林县| 灵璧县| 东港市| 精河县| 天等县| 兴化市| 芦山县| 麦盖提县| 高淳县| 常山县| 阿坝县| 乡宁县| 伊川县| 光泽县| 商都县| 宁蒗| 外汇| 巴彦淖尔市| 定兴县| 彭阳县| 花垣县| 新邵县| 花垣县| 灵璧县| 河间市| 秦安县|