IBM DB2 data replication and migration, as an Example

Source: Internet
Author: User
Tags ibm db2

The following articles mainly describe the application instance's introduction to IBM DB2 data replication and migration methods. The following methods have been tested in the Environment IBM x346, in 3.2G × 2, 4G, RAID 1, DB2 V8.2.4, Win2000 Adv Server, and DMS tablespaces, the data load speed is about 60-entries/min.

Background

You need to change the tablespace of the database, or migrate data from all tables in the database to a new database.

Procedure

1. Select all tables in the source database through the db2 Console (db2cc) and export them as DDL scripts;

2. Make necessary modifications to the script as needed, such as changing the tablespace to GATHER;

3. Create a database and create a DMS tablespace: GATHER;

4. Run the DDL script in this database;

5. write code to query all tables in the source database and generate an export script automatically;

6. write code to query all tables in the source database and generate an import script automatically;

7. Connect to the source database and execute the export script;

8. connect to the target database and execute the import script;

An example of the Code for generating an export script is as follows:

/**

* Create an export script

* @ Param conn

* @ Param creator: Table creator

 
 
  1. * @param filePath  
  2. */  
  3. public void createExportFile(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  
  22. String tableName = (String)list.get(i);  
  23. sb.append("db2 \"export to aa" + String.valueOf(i+1)+ ".ixf of ixf select * from " + tableName + "\"");  
  24. sb.append(enterFlag);  
  25. }  
  26. String str = sb.toString();  
  27. FileUtility.saveStringToFile(filePath, str, false);  

The above content is an introduction to the application instance's practices for IBM DB2 data replication and migration.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.