DB2 data replication and migration practices, classic edition!

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

The following articles mainly introduce the actual operation methods of data replication and migration in DB2. The following methods are tested. In the environment of IBM x346, 3.2G × 2, 4G, RAID 1, run in DB2 V8.2.4 and Win2000 Adv Server. in DMS tablespace, 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 :/**

 
 
  1. * Create an export script
  2. * @ Param conn
  3. * @ Param creator: Table 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. Variables Ables where creator = '" + creator + "' and type = 'T '";
  9. Try {
  10. DbBase.exe cuteQuery (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. }

Appendix 2: Sample Code for generating the import Script :/**

 
 
  1. * Create a load script
  2. * @ Param conn
  3. * @ Param creator: Table 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. Variables Ables where creator = '" + creator + "' and type = 'T '";
  9. Try {
  10. DbBase.exe cuteQuery (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. }

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.