BMDB2数据复制与迁移大讲堂

I此文主要向大家讲述的是BM DB2数据复制与迁移的实际操作方法,以下的方法是经过测试的,在环境IBM x346,3.2G×2,4G,RAID 1,DB2 V8.2.4,Win2000 Adv Server,DMS表空间中,数据的load速度在60-100万条/min左右。

目前成都创新互联已为上千余家的企业提供了网站建设、域名、虚拟主机、网站改版维护、企业网站设计、崇阳网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

背景:

需要更改数据库表空间,或者需要将数据库中所有表的数据迁移到一个新的数据库中。

步骤:

1.通过db2控制台(db2cc)选中源IBM DB2数据复制数据库中的所有表,将其导出成DDL脚本;

2.根据需要对脚本进行必要的修改,譬如更改表空间为GATHER;

3.新建数据库,新建DMS表空间:GATHER;

4.将DDL脚本在此数据库中执行;

5.编写代码查询源数据库中的所有表,自动生成export脚本;

6.编写代码查询源数据库中的所有表,自动生成import脚本;

7.连接源数据库执行export脚本;

8.连接目标数据库执行import脚本;

附录1:生成export脚本代码示例:

 
 
 
  1. /**   
  2. * 创建导出脚本   
  3. * @param conn   
  4. * @param creator 表创建者   
  5. * @param filePath   
  6. */   
  7. public void createExportFile(Connection conn,String creator,String filePath) throws Exception {   
  8. DBBase dbBase = new DBBase(conn);   
  9. String selectTableSql = "select name from sysibm.systables where creator = '" + creator + "' and type='T'";   
  10. try {   
  11. dbBase.executeQuery(selectTableSql);   
  12. } catch (Exception ex) {   
  13. throw ex;   
  14. } finally {   
  15. dbBase.close();   
  16. }   
  17. DBResult result = dbBase.getSelectDBResult();   
  18. List list = new ArrayList();   
  19. while (result.next()) {   
  20. String table = result.getString(1);   
  21. list.add(table);   
  22. }   
  23. StringBuffer sb = new StringBuffer();   
  24. String enterFlag = "\r\n";   
  25. for (int i = 0; i < list.size();i++) {   
  26. String tableName = (String)list.get(i);   
  27. sb.append("db2 \"export to aa" + String.valueOf(i+1)+ ".ixf of ixf select * from " + tableName + "\"");   
  28. sb.append(enterFlag);   
  29. }   
  30. String str = sb.toString();   
  31. FileUtility.saveStringToFile(filePath, str, false);   
  32. }   

附录2:生成import脚本代码示例:

 
 
 
  1. /**   
  2. * 创建装载脚本   
  3. * @param conn   
  4. * @param creator 表创建者  
  5. * @param filePath   
  6. */   
  7. public void createLoadFile(Connection conn,String creator,String filePath) throws Exception {   
  8. DBBase dbBase = new DBBase(conn);   
  9. String selectTableSql = "select name from sysibm.systables where creator = '" + creator + "' and type='T'";   
  10. try {   
  11. dbBase.executeQuery(selectTableSql);   
  12. } catch (Exception ex) {   
  13. throw ex;   
  14. } finally {   
  15. dbBase.close();   
  16. }   
  17. DBResult result = dbBase.getSelectDBResult();   
  18. List list = new ArrayList();   
  19. while (result.next()) {   
  20. String table = result.getString(1);   
  21. list.add(table);   
  22. }   
  23. StringBuffer sb = new StringBuffer();   
  24. String enterFlag = "\r\n";   
  25. for (int i = 0; i < list.size();i++) {   
  26. String tableName = (String)list.get(i);   
  27. sb.append("db2 \"load from aa" + String.valueOf(i+1)+ ".ixf of ixf into " + tableName + " COPY NO without prompting \"");   
  28. sb.append(enterFlag);   
  29. }   
  30. String str = sb.toString();   
  31. FileUtility.saveStringToFile(filePath, str, false);   
  32. }   

附录3:export脚本示例

 
 
 
  1. db2 connect to testdb user test password test   
  2. db2 "export to aa1.ixf of ixf select * from table1"   
  3. db2 "export to aa2.ixf of ixf select * from table2"   
  4. db2 connect reset   

附录4:import脚本示例

 
 
 
  1. db2 connect to testdb user test password test   
  2. db2 "load from aa1.ixf of ixf replace into table1 COPY NO without prompting "   
  3. db2 "load from aa2.ixf of ixf replace into table2 COPY NO without prompting "   
  4. db2 connect reset   

以上的相关内容就是对IBM DB2数据复制和迁移方法的介绍,望你能有所收获。

网页标题:BMDB2数据复制与迁移大讲堂
文章链接:http://www.shufengxianlan.com/qtweb/news25/276625.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联