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
*/
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 to replace into table1 COPY NO without prompting"
DB2 "Load from AA2.IXF of IXF to replace into table2 COPY NO without prompting"
DB2 Connect Reset