DB2数据复制与数据库迁移追根述源

数据库
我们今天主要向大家讲述的是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. 连接目标DB2数据复制执行import脚本;

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

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

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

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

附录3:export脚本示例db2 connect to testdb user test password test

  1. db2 "export to aa1.ixf of ixf select * from table1"  
  2. db2 "export to aa2.ixf of ixf select * from table2"  
  3. db2 connect reset  

附录4:import脚本示例db2 connect to testdb user test password test

  1. db2 "load from aa1.ixf of ixf replace into table1 COPY NO without prompting "  
  2. db2 "load from aa2.ixf of ixf replace into table2 COPY NO without prompting "  
  3. db2 connect reset  

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

责任编辑:佚名 来源: ibm.com
相关推荐

2009-07-06 17:34:26

远程复制DB2

2011-03-16 13:02:47

DB2数据复制迁移

2010-09-01 13:38:41

DB2数据复制

2010-08-04 16:18:48

DB2数据库

2010-08-19 10:32:07

BM DB2数据复制

2010-08-26 10:37:40

DB2Q复制

2010-08-20 13:39:23

DB2数据复制

2010-08-17 10:06:25

IBM DB2的数据复

2010-08-12 10:34:40

IBM DB2数据

2010-08-16 14:45:15

DB2数据库

2010-08-10 10:07:29

DB2 数据库

2010-08-04 12:39:55

2010-08-03 14:40:05

DB2数据库

2010-09-07 14:44:50

DB2 数据库

2010-08-03 13:56:11

DB2表复制

2010-08-25 10:50:48

DB2数据库

2011-03-11 16:02:03

DB2数据库安装

2010-09-30 11:49:21

DB2数据库权限

2010-11-01 11:30:41

DB2数据库权限

2010-11-03 16:21:18

DB2数据库授权
点赞
收藏

51CTO技术栈公众号