IBM DB2 data replication and Migration methods

Source: Internet
Author: User
Tags db2 db2 connect db2 connect to ibm db2 connect reset tostring stringbuffer

The following methods have been tested, in the environment IBM X346,3.2gx2,4g,raid 1,DB2 v8.2.4,win2000 ADV Server,dms tablespace, the data load speed is around 601 million/min.

Background: You need to change the database table space, or you need to migrate the data from all the 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 the necessary modifications to the script as needed, such as changing the tablespace to gather;

3. New database, new DMS table space: GATHER;

4. Execute the DDL script in this database;

5. Write code to query all tables in the source database, automatically generate export script;

6. Write code to query all tables in the source database and automatically generate import scripts;

7. Connect the source database to execute export script;

8. Connect the target database to execute the import script;

Appendix 1: Generate Export script code sample:

/**
* Create export Script
* @param Conn
* @param creator Table Creator
* @param FilePath
*/
* Create export Script
* @param Conn
* @param creator Table Creator
* @param FilePath
public void Createexportfile (Connection conn,string creator,string filePath) throws Exception {
Dbbase dbbase = new Dbbase (conn);
String selecttablesql = "SELECT name from sysibm.systables where creator = '" + Creator + "' and type= ' T '";
try {
Dbbase.executequery (Selecttablesql);
catch (Exception ex) {
Throw ex;
finally {
Dbbase.close ();
}
Dbresult result = Dbbase.getselectdbresult ();
List List = new ArrayList ();
while (Result.next ()) {
String table = result.getstring (1);
List.add (table);
}
StringBuffer sb = new StringBuffer ();
String Enterflag = "\ r \ n";
for (int i = 0; i < list.size (); i++) {
String tablename = (string) list.get (i);
Sb.append ("DB2" "Export to AA" + string.valueof (i+1) + ". IXF of IXF Select * from" + tablename + "\");
Sb.append (Enterflag);
}
String str = sb.tostring ();
Fileutility.savestringtofile (FilePath, str, false);
}

Appendix 2: Generate an Import script code example:

/**
* Create Mount Script
* @param Conn
* @param creator Table Creator
* @param FilePath
*/
public void Createloadfile (Connection conn,string creator,string filePath) throws Exception {
Dbbase dbbase = new Dbbase (conn);
String selecttablesql = "SELECT name from sysibm.systables where creator = '" + Creator + "' and type= ' T '";
try {
Dbbase.executequery (Selecttablesql);
catch (Exception ex) {
Throw ex;
finally {
Dbbase.close ();
}
Dbresult result = Dbbase.getselectdbresult ();
List List = new ArrayList ();
while (Result.next ()) {
String table = result.getstring (1);
List.add (table);
}
StringBuffer sb = new StringBuffer ();
String Enterflag = "\ r \ n";
for (int i = 0; i < list.size (); i++) {
String tablename = (string) list.get (i);
Sb.append ("DB2 \" Load from AA "+ string.valueof (i+1) +". Ixf of IXF into "+ tablename +" COPY NO without prompting \ "");
Sb.append (Enterflag);
}
String str = sb.tostring ();
Fileutility.savestringtofile (FilePath, str, false);
}

Appendix 3:export Script Sample

db2 connect to testdb user test password test
db2 "export to aa1.ixf of ixf select * from table1"
db2 "export to aa2.ixf of ixf select * from table2"
db2 connect reset

Appendix 4:import Script Sample

db2 connect to testdb user test password test
db2 "load from aa1.ixf of ixf replace into table1 COPY NO without prompting "
db2 "load from aa2.ixf of ixf replace into table2 COPY NO without prompting "
db2 connect reset

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.