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
- * @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
- 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);
- }
The above content is an introduction to the application instance's practices for IBM DB2 data replication and migration.