迁移背景
源端 |
AIX 5.3.0.0 DB2 V9.1 |
目标端 |
SUSE 11.4 DB2 V9.7 |
迁移步骤
1. 导出源端数据库对象DDL
[db2inst1]# db2look -d DBNAME -e -a -l -x -f -o DBNAME.ddl
2. 使用db2move导出源端数据
[db2inst1]# db2move DBNAME export
主要文件介绍:
- db2move.lst:导出的表清单以及对应的导出文件信息;
- EXPORT.out:导出表对象的概要信息;
- .ixf:导出表的数据文件;
- *.msg:导出对应表时产生的日志。
3. 将导出的数据以二进制的方式传输到目标端
4. 目标端执行DDL生成对应的表空间和对象
[db2inst1]# db2 -tvf DBNAME.ddl
5. 目标端导入数据之前需要先将拥有表的“外键约束”禁用,否则导入数据库后表无法查看报SQL0668N错误
查看那些表拥有外键约束
[db2inst1]# db2 "select substr(table_name,1,30),substr(CONSTRAINT_NAME,1,30),CONSTRAINT_TYPE from sysibm.TABLE_CONSTRAINTS where CONSTRAINT_TYPE like '%FOREIGN KEY%'"
禁用外键约束
[db2inst1]# db2 "alter table TABNAME alter foreign key FK_NAME not enforced"
6. 目标端导入数据
[db2inst1]# db2move DBNAME load
7. 重新启用表的外键约束
[db2inst1]# db2 "alter table TABNAME alter foreign key FK_NAME enforced"
8. 根据需求调整“源端”与“目标端”参数配置
[db2inst1]# db2set -all
[db2inst1]# db2 get dbm cfg
[db2inst1]# db2 get db cfg for DBNAME
9. 比对“源端”与“目标端”数据库对象个数
[db2inst1]# db2 "select count(*) from SYSCAT.TABLES where TABSCHEMA not like 'SYS%'"
[db2inst1]# db2 "select COUNT(*) from SYSCAT.INDEXES where INDSCHEMA not like 'SYS%'"
[db2inst1]# db2 "select COUNT(*) from SYSCAT.VIEWS where VIEWSCHEMA not like 'SYS%'"
[db2inst1]# db2 "select count(*) from SYSCAT.TRIGGERS where TRIGSCHEMA not like 'SYS%'"
[db2inst1]# db2 "select count(*) from SYSCAT.ROUTINES where ROUTINESCHEMA not like 'SYS%'"
[db2inst1]# db2 "select count(*) from SYSCAT.FUNCTIONS where FUNCSCHEMA not like 'SYS%'"
[db2inst1]# db2 "select count(*) from SYSCAT.PROCEDURES where PROCSCHEMA not like 'SYS%'"