針對含 GENERATED ALWAYS AS IDENTITY 的表,LOAD 命令提供三種模式:
| 參數 | 行為 |
|---|---|
identityignore | 忽略資料檔中的自增值,由資料庫自動產生 |
identitymissing | 資料檔無自增值,資料庫自動產生 |
identityoverride | 使用資料檔中的自增值(本文採用,保持資料一致) |
操作:從 srcdb1_tables.ddl 找出所有自增表,在 srcdb1_load.sql 對應的 LOAD 行插入 modified by identityoverride。例:
db2 load from test.ixf of ixf modified by identityoverride insert into TEST;
# db2 -tvf srcdb1_export.sql # 匯出所有表為 IXF 格式
# 複製所有 DDL 腳本與 *.ixf 至 Linux 目標主機
# db2icrt SRCDB1
# db2 create database SRCDB1
# db2 connect to srcdb1
# db2 -tvf srcdb1_tables.ddl
# cd
# db2 -tvf srcdb1_load.sql
# db2 -tvf srcdb1_foreignkeys.ddl
# db2 -tvf srcdb1_triggers.ddl
# db2 -tvf srcdb1_procedures.ddl
完成上述步驟,資料庫遷移基本告成。
# $APACHE_HOME/bin/httpd -l
Compiled in modules:
core.c
prefork.c
http_core.c
mod_so.c <-- 必須存在
若無 mod_so.c 需重新編譯。
# tar zxvf httpd-2.0.54.tar.gz && cd httpd-2.0.54
# ./configure --prefix=/usr/local/apache2 --enable-module=so
# make && make install
# ln -s /usr/local/apache2/bin/apachectl /sbin/apachectl
# apachectl start
# tar zxvf php-4.4.4.tar.gz && cd php-4.4.4
# ./configure --prefix=/usr/local/php \
--with-apxs2=/usr/sbin/apxs \
--without-mysql \
--with-ibm-db2=/home/reportdb/sqllib
# cp php.ini-dist /usr/local/lib
# make && make install
# cp php.ini-dist /usr/local/lib/php.ini
DocumentRoot "/home/web/www/"
DirectoryIndex index.php index.html.var index.cgi index.html
AddType application/x-httpd-php .php .inc
LoadModule php4_module modules/libphp4.so
編輯 /usr/local/apache2/bin/apachectl,在啟動區塊加入:
if test -f /home/reportdb/sqllib/db2profile; then
. /home/reportdb/sqllib/db2profile
fi
# apachectl restart
# echo '' > /home/web/www/test.php
# 瀏覽器訪問 https://host/test.php 應顯示 PHP 資訊頁
本文完整記錄了從 AIX 到 Linux 的 DB2 資料庫遷移、自增欄位處理、Apache+PHP 編譯整合及 DB2 客戶端環境注入的實戰步驟。該方案經實測可行,亦可參考應用於其他平台遷移專案。