IBM DB2数据复制与迁移方法的背景与实际操作步骤

数据库
我们今天主要向大家讲述的是IBM DB2数据复制与迁移方法的描述,以及对其在实际操作中要遇到的一些问题的描述,以下就是文章的主要内容讲述。

文章主要讲述的是IBM 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.连接目标数据库执行import脚本;

 

 

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

/**

 

* 创建导出脚本

 

 

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

 

 

 

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

/**

 

* 创建装载脚本

 

* @param conn

 

* @param creator 表创建者

 

 

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

 

 

 

附录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  
  5. TAG: IBM ibm   

 

 

 

责任编辑:佚名 来源: wpzune
相关推荐

2010-08-13 10:13:15

DB2数据复制

2010-08-06 11:21:45

IBM DB2 数据复

2010-08-12 10:34:40

IBM DB2数据

2010-08-17 10:06:25

IBM DB2的数据复

2010-08-03 13:56:11

DB2表复制

2010-08-03 09:32:19

DB2在线备份

2010-07-28 08:58:50

DB2并行索引

2010-08-20 13:39:23

DB2数据复制

2010-08-03 09:44:42

DB2在线增量备份

2010-07-27 11:20:02

DB2打补丁

2011-03-16 13:02:47

DB2数据复制迁移

2010-08-05 14:34:26

DB2存储过程

2010-08-12 09:06:30

DB2数据库自动备份

2010-08-03 09:49:58

DB2恢复数据库

2010-08-12 17:36:48

DB2还原某个表空间

2010-08-13 09:43:13

IBM DB2

2010-08-09 13:43:37

DB2数据迁移

2010-08-05 11:34:01

DB2 代码

2010-05-13 17:00:32

MySQL启动方法

2010-07-27 13:16:50

DB2使用所有内存
点赞
收藏

51CTO技术栈公众号