[DB2]IBM DB2 的数据复制、迁移方法

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 = " ";

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 = " ";

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]全新移民:迁移到DB2 Express
下一篇:[DB2]IBM DB2数据库日常维护小常识
最新评论共有 0 位网友发表了评论 , 查看所有评论
发表评论( 不能超过250字,需审核,请自觉遵守互联网相关政策法规。 )
匿名?
数据挖掘网站导航 数据挖掘论坛导航
  • 数据挖掘工具
  • 数据挖掘论坛
  • DataCruncher - Cognos
  • MineSet - MathSoft
  • Intelligent Miner - GainSmarts
  • Sqlserver - SAS - Clementine
  • CART - Weka - WizSoft
  • NeuroShell - ModelQuest
  • data mining tools - Darwin
  • 数据挖掘交友
  • 数据挖掘博客
  • 数据挖掘工具
  • 数据挖掘资源
  • 数据挖掘技术算法
  • 数据挖掘相关期刊、会议
  • 研究院联盟合作专区
  • 数据挖掘基础与相关技术
  • 数据挖掘厂商与就业
  • 数据挖掘研究者乐园
  • 知名厂商数据挖掘工具资料
  • 国内数据挖掘实验室
  • Foreign Data Mining Lab
  • 热点关注
  • Windows Communication Foundation - Part
  • Industry Leaders Line Up Behind Informat
  • IBM DB2 日常维护汇总(八)
  • DB2 Data Warehouse Edition V9.1 overview
  • DB2编程序技巧 (二)
  • IBM DB2前世今生之DB2的诞生
  • IBM DB2 日常维护汇总(二)
  • DB2编程序技巧 (十)
  • DB2的数据同步经验总结
  • DB2编程序技巧 (六)
  • 论坛最新话题
  • Foundations of Statistical Natural Langu
  • Game Theory meet Data Mining: A Recent P
  • System Building: How does it help or hin
  • 数据挖掘与Clementine培训
  • 新手报到
  • 求 SASEM 客户流失预测分析
  • 数据挖掘工程师/搜索研究院—北京——无线
  • 数据挖掘入门介绍(如何着手数据挖掘)
  • Information Overload Survey Results
  • The INEX 2005 Workshop on Element Retrie
  • 相关资讯
  • IBM DB2前世今生之DB2的诞生
  • Modernizing the Mainframe Through SOA: T
  • Industry Leaders Line Up Behind Informat
  • DB2编程序技巧 (七)
  • DB2编程序技巧 (九)
  • DB2编程序技巧 (一)
  • DB2编程序技巧 (十)
  • DB2编程序技巧 (六)
  • DB2编程序技巧 (八)
  • DB2编程序技巧 (三)
  • 数据挖掘实验室资料
  • 数据挖掘博客地址
  • 数据挖掘实验室网站地址
  • Prepare for Medicare audits by using dat
  • 注册成为SAS用户与爱好者俱乐部会员
  • 水南梅
  • 明日烟
  • 新人报道
  • 下载
  • 厦门服务器托管,450元/月—0592-5177319 高
  • 买空间送域名--0592-5177319 高静