IBM DB2数据的复制与迁移的实现步骤

数据库
我们今天是要和大家一起讨论的是IBM DB2数据复制与迁移的实际操作方法,以及对其的实际操作背景的详细解说,以下就是正文的描述。

文章主要描述的是IBM DB2数据复制与迁移的实际操作方法,你如果对IBM DB2数据复制与迁移的实际操作方法有兴趣的话你就可以点击以下的文章进行观看了,以下就是文章的主要内容的详细描述。

IBM, 数据, 迁移, 讲解IBM, 数据, 迁移, 讲解

 

关键词: 迁移 , 复制 , 方法 , IBM , DB2 , 数据

 

 

以下方法经测试,在环境IBM x346,3.2G×2,4G,RAID 1,DB2 V8.2.4,Win2000 Adv Server,DMS表空间中,数据的load速度在60-100万条/min左右。

背景:

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

 

步骤:

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

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

 

创建导出脚本

 

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

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

创建装载脚本

 

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

附录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数据的复制和迁移方法的介绍,望你能有所收获。

【编辑推荐】

  1. DB2数据库和PostgreSQL在开发的异同点有哪些?
  2. DB2 Cube View元数据桥的正确构建方案
  3. DB2 9打开打开通往 XML 之门的钥匙
  4. 如何看待IBM DB2 9数据服务器的发展?
  5. 对DB2日志设置参数正确用法的描述
责任编辑:佚名 来源: 环球企业家
相关推荐

2010-08-17 10:06:25

IBM DB2的数据复

2010-08-10 14:02:26

IBM DB2数据复制

2010-08-04 12:39:55

2011-03-16 13:02:47

DB2数据复制迁移

2010-08-20 13:39:23

DB2数据复制

2010-08-19 17:41:46

IBM DB2跨平台数

2010-08-19 10:32:07

BM DB2数据复制

2010-08-13 09:43:13

IBM DB2

2010-08-06 10:05:18

IBM DB2包重绑定

2010-08-13 16:29:03

DB2数据复制

2010-08-13 10:13:15

DB2数据复制

2010-08-03 13:56:11

DB2表复制

2010-08-17 16:24:32

IBM DB2数据库

2010-08-17 09:18:29

DB2 备份

2009-07-06 17:34:26

远程复制DB2

2010-08-06 11:21:45

IBM DB2 数据复

2009-03-25 17:43:09

备份DB2IBM

2010-08-12 10:54:21

IBM DB2数据库

2012-11-12 10:30:25

IBMdw

2010-09-01 13:38:41

DB2数据复制
点赞
收藏

51CTO技术栈公众号