LOAD 速度:60–100 萬行/分。IN GATHER INDEX IN GATHER)。CREATE TABLESPACE GATHER ...。.ixf。
public void createExportFile(Connection conn, String creator, String filePath) throws Exception {
DBBase dbBase = new DBBase(conn);
String sql = "SELECT name FROM sysibm.systables WHERE creator = '" + creator + "' AND type = 'T'";
dbBase.executeQuery(sql);
DBResult result = dbBase.getSelectDBResult();
List list = new ArrayList<>();
while (result.next()) list.add(result.getString(1));
dbBase.close();
StringBuilder sb = new StringBuilder();
String nl = "\r\n";
for (int i = 0; i < list.size(); i++) {
sb.append("db2 \"export to aa").append(i+1).append(".ixf of ixf select * from ")
.append(list.get(i)).append("\"").append(nl);
}
FileUtility.saveStringToFile(filePath, sb.toString(), false);
}
public void createLoadFile(Connection conn, String creator, String filePath) throws Exception {
DBBase dbBase = new DBBase(conn);
String sql = "SELECT name FROM sysibm.systables WHERE creator = '" + creator + "' AND type = 'T'";
dbBase.executeQuery(sql);
DBResult result = dbBase.getSelectDBResult();
List list = new ArrayList<>();
while (result.next()) list.add(result.getString(1));
dbBase.close();
StringBuilder sb = new StringBuilder();
String nl = "\r\n";
for (int i = 0; i < list.size(); i++) {
sb.append("db2 \"load from aa").append(i+1).append(".ixf of ixf replace into ")
.append(list.get(i)).append(" COPY NO without prompting\"").append(nl);
}
FileUtility.saveStringToFile(filePath, sb.toString(), false);
}
-- export.bat
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
-- load.bat
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
LOAD 自動重建索引/檢查約束,比 DEL 快且安全。COPY YES USE TSM。LOAD 視窗,配合 CPU_PARALLELISM/DISK_PARALLELISM 壓榨 I/O。SET INTEGRITY ... OFF,載完 IMMEDIATE CHECKED,避免逐列檢查拖慢。RUNSTATS ... WITH DISTRIBUTION AND DETAILED INDEXES ALL,保證優化器看清新資料分布。「導 DDL → 改表空間 → 建新庫 → 自動化 Export/Load」四步走,配合 IXF 格式與 LOAD REPLACE COPY NO,可在數小時內完成 TB 級跨庫遷移。Java 自動化腳本一寫終身受用,是 DBA 遷移專案的標準化利器。