How can we use DB2 data replication and migration correctly?

Source: Internet
Author: User
Tags db2 connect db2 connect to

The following articles mainly describe the actual operation solution for DB2 data replication and migration. The following method is tested by professionals 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.

Steps:

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;

Appendix 1: Sample Code for generating an export Script :/**

Create an export script

 
 
  1. @ Param conn
  2. @ Param creator: Table 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. Variables Ables where creator = '" + creator + "' and type = 'T '";
  8. Try {
  9. DbBase.exe cuteQuery (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 );
  30. }

Appendix 2: generate the DB2 data copy import script code example :/**

Create a load script

 
 
  1. @ Param conn
  2. @ Param creator: Table creator
  3. @ Param filePath
  4. */
  5. Public void createLoadFile (Connection conn, String creator, String filePath) throws Exception {
  6. DBBase dbBase = new DBBase (conn );
  7. String selectTableSql = "select name from sysibm. Variables Ables where creator = '" + creator + "' and type = 'T '";
  8. Try {
  9. DbBase.exe cuteQuery (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 \" load from aa "+ String. valueOf (I + 1) + ". ixf of ixf into "+ tableName +" copy no without prompting \"");
  26. Sb. append (enterFlag );
  27. }
  28. String str = sb. toString ();
  29. FileUtility. saveStringToFile (filePath, str, false );
  30. }

Appendix 3: export script example 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  

Appendix 4: import script example 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  

The above content is an introduction to the DB2 data replication and migration methods. I hope you will have some gains.

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.