Loading...
  所在位置:论坛首页 -> ┈┋电脑网络技术区┋┈ -> 数据库技术 -> 详细讲解IBM DB2的数据复制和迁移方法
标题:详细讲解IBM DB2的数据复制和迁移方法收藏 编辑 删除 楼主 | 上一篇 下一篇
为你写诗
等级:社区游民
权限:普通用户
积分:0
金钱:166
声望:0
经验:0
发帖数:34
注册:2008年5月2日
资料 短消息2008-6-6 10:06:59
以下方法经测试,在环境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

2008-6-6 10:06:59 顶部
第1页 共页 共0个回复     <<    >>    
 快速回复
  • 支持UBB,HTML标签

  • 高级回复

  • 操作选项:评分 加精 解精 奖惩 设专题 设公告 解公告 固顶 总固顶 解固顶 结帖 解结帖 锁帖 解锁 移帖 删帖
      首页 | 购买指南 | 商业版本 | 虚拟主机 | 特色介绍 | 下载中心 | 支付方式
    Copyright 2004-2008 BBSGood.com Powered By: BBSGood.Speed Version 5.0
      咨询电话:0575-85513832、0575-85513825(传真)、7*24小时咨询服务:13606552007 不良信息举报中心 浙ICP备05029817号
      业务QQ:38958768、客服QQ1:415896239、客服QQ2:343896043、MSN:jccsxx@hotmail.com