C114首页 | 新闻 技术 市场 会展 黄页 人物 | 3G NGN VoIP IPTV WiMax FTTH |          通信人家园 | 通信人博客 | 通信商情网 | 通信人才网 | English
近期导读

·联通重组后何以对抗混战

·开幕式停电时我想起CMMB

·中国移动,大象如何跳舞

  技术 - 学院 - 网络基础 - 正文
详细讲解IBM DB2的数据复制和迁移方法
 
( 2008/6/6 10:15 )
本文关键字: 测试1, IBM1, 4G1

以下方法经测试,在环境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

作者:Baron    来源:赛迪网
  你是通信人才吗? C114通信人才网
  是通信人才就要上专业通信人才网! 专业、高效、低成本、资源广!
  助你迅速找到满意工作! 拥有中国最全的通信行业人才数据库资源。
C114-AdKey 行业广告系统 
C114 提醒您:1.尊重网上道德,遵守国家的各项法律法规;2.承担一切因为您的行为而导致的相关法律责任;

3.新闻留言板管理人员有权删减留言中的内容;4.您在留言板发表的作品,C114有权站内转载。

[参与本留言即表明您已经阅读并接受上述条款]

 
Copyright©1999-2008 c114 All Right Reserved
上海荧通网络信息技术有限公司版权所有
南方广告业务部: 021-54451141,54451142 E-mail:c114@c114.net
北方广告业务部: 010-63533177,63533977 E-mail:shi@c114.net.cn
编辑部联系:021-54451141,54451142 E-mail:editor@c114.net.cn
服务热线:021-54451141,54451142