Home > Backend Development > PHP Tutorial > Detailed steps for cross-platform migration of application systems based on DB2 and PHP (1)_PHP Tutorial

Detailed steps for cross-platform migration of application systems based on DB2 and PHP (1)_PHP Tutorial

WBOY
Release: 2016-07-13 17:36:09
Original
1090 people have browsed it

本文主要介绍如何完成基于 DB2 的 PHP 应用系统从 AIX 平台到 Linux 平台的移植过程。文中包含了底层的 DB2 数据库移植、上层的 PHP 应用系统移植的详细步骤以及移植过程中可能遇到的问题和解决方法。

任务概述

系统迁移的工作主要分为以下几个方面:

1.DB2 数据库系统的跨平台迁移

2.Apache 服务器与 php 应用系统的安装和配置

下面我们就分 2 个方面分别介绍迁移和配置的具体步骤。

DB2 数据库系统的跨平台迁移

数据库环境

源环境:AIX+DB2 v8.1

目标环境:Linux+DB2 v8.1

其中源数据库中包含了 2 个数据库 Instance:SRCDB1 与 SRCDB2。在 SRCDB1/SRCDB2 数据库中,均包含了上百张数据库表,并有很多的索引、外键约束、触发器、存储过程以及一些含有自增字段的表(含有 GENERATED ALWAYS AS IDENTITY 定义字段的表)。更为困难的是,我们并没有关于这些数据库对象的准确创建脚本。

迁移方案的选择

如果迁移的源系统与目的系统属于同一类型操作系统,例如 Linux 之间的迁移,或者 AIX 系统之间的迁移,则情况相对简单,DB2 本身已经提供相关的实用工具来实现这种同类型平台之间的数据库移植,如: BACKUP 和 RESTORE 命令。当然,根据不同的情况还需要对实用工具所提供的参数有比较清楚的了解,譬如源系统与目标系统使用不同的表空间,就会涉及到表空间重定向的问题。由于本文的重点在于跨平台的移植,这种方案显然无法满足需求,在此不再熬述。

那么,如何处理跨平台的数据库迁移问题?是不是可以使用实用工具 db2move 呢? db2move 只能迁移表中的数据,而无法对索引、外键约束、触发器和存储过程等数据库对象也实现迁移操作,而且对于包含自增字段数据的表来说,db2move 也有一定的限制。并且 db2move 只能把数据导入到已存在的数据库的表中,无法显示指定表空间的位置。由于在数据库的系统迁移过程中,不仅需要迁移表中的数据,还有索引、外键约束、触发器和存储过程等数据库对象,与本文所选方案相比,还是后者更具优势。可以将 db2move 仅作为迁移表数据的一种备用方案。

而对于 export 和 import 来说,一次只能针对一张表进行导出导入操作,并且需要手动输入 export 和 import 的命令以及需要导入导出的数据表名,在数据库表的数量不多的情况下,这种方案也许还可以考虑,但也不并是最佳的方案。而在数据库中表数量众多的情况下,这种做法则是基本不现实的,而且 import 命令并不能保证自增字段的数据与原来的表数据保持一致。

本文根据 DB2 对数据库对象的处理机制,采用将 db2look 与 DDL、DML 脚本相结合的方式,并针对原数据库中的触发器、存储过程以及外键约束等分别处理,给出了一种跨平台 DB2 数据库系统移植的可行方案。

下面我们以 SRCDB1 为例介绍一下这种情况下的数据库整体迁移过程。SRCDB1 数据库中有 SRCDB1、ASN、DB2DBG 和 SQLDBA 这四个数据库模式。假设 SRCDB1 数据库的用户名为 user_srcdb1,密码:pw_srcdb1。

在源系统 (AIX) 上的相关操作

1.使用 db2look 命令抽取生成数据库对象的 DDL 脚本

清单 1. db2look 命令及参数

# db2look -d SRCDB1 -e -o srcdb1.ddl -a -i user_srcdb1 -w pw_srcdb1

db2look :生成 DDL 以便重新创建在数据库中定义的对象

语法: db2look -d DBname [-e] [-u Creator] [-z Schema]

[-t Tname1 Tname2...TnameN] [-tw Tname] [-h] [-o Fname] [-a]

[-m] [-c] [-r] [-l] [-x] [-xd] [-f] [-fd] [-td x]

[-noview] [-i userID] [-w password]

[-v Vname1 Vname2 ... VnameN] [-wrapper WrapperName]

[-server ServerName] [-nofed]

-d : 数据库名称,必选参数

-e : 抽取复制数据库所需要的 DDL 文件,此选项将生成包含 DDL 语句的脚本

-o : 将输出重定向到给定的文件名,如果未指定 -o 选项,则输出默认转到 stdout

-a : 为所有创建程序生成统计信息,如果指定了此选项,则将忽略 -u 选项

-i : 指定登录到数据库所在服务器时所使用的用户标识

-w : 指定登录到数据库所在服务器时所使用的密码

2.根据不同类型对象,分化数据库对象 DDL 脚本

Since each table data in the source database has been processed by database objects such as triggers and stored procedures, in order to ensure the consistency and integrity of the data in the database, these database objects should be created after importing the data. To prevent repeated execution of database objects such as triggers and stored procedures to generate erroneous data when importing table data. Use a text editor to edit srcdb1.ddl generated by db2look, divide the DDL statements that create tables and indexes, create foreign key constraints, and create triggers and stored procedures into four groups, and save them as the following four DDL script:


srcdb1_tables.ddl srcdb1_foriegnkeys.ddl

srcdb1_triggers.ddl srcdb1_procedures.ddl

srcdb1_tables.ddl: Contains ddl statements to create SEQUENCE, UDF, TABLE, VIEW and other database objects.

Listing 2. srcdb1_tables.ddl statement

CREATE SEQUENCE "SRCDB1"."SAMPLE_SEQ_1" AS INTEGER

MINVALUE 1 MAXVALUE 9999999999

START WITH 1 INCREMENT BY 1;

CREATE FUNCTION " SRCDB1"." SAMPLE _FUNC_1" (

VARCHAR(254),

VARCHAR(254),

VARCHAR(254)

) RETURNS VARCHAR(254)

SPECIFIC SAMPLE _FUNC_1 ……;

CREATE TABLE " SRCDB1"." SAMPLE _TAB_1" (

"TAB_COL1" CHAR(20) NOT NULL ,

"TAB_COL2" VARCHAR(70) NOT NULL ) ;

CREATE TABLE " SRCDB1"." SAMPLE _TAB_2" (…);

……

CREATE TABLE " SRCDB1"." SAMPLE _TAB_N" (…);

CREATE VIEW SRCDB1.SAMPLE_VIEW_1 (VIEW_COL1,VIEW_COL2) AS SELECT distinct

COL1 , COL2 FROM SAMPLE_TAB WHERE ……;

CREATE VIEW SRCDB1.SAMPLE_VIEW_2 ……;

……

CREATE VIEW SRCDB1.SAMPLE_VIEW_N ……;

srcdb1_foriegnkeys.ddl: Contains ddl statements to create foreign key constraints.

Listing 3. srcdb1_foriegnkeys.ddl statement

ALTER TABLE " SRCDB1"."SAMPLE_FK_1"

ADD CONSTRAINT "SQL030903143850120" FOREIGN KEY

("FK_COL1")

REFERENCES " SRCDB1"."SAMPLE_TABLE"

("COL1");

ALTER TABLE " SRCDB1"."SAMPLE_FK_2" ADD ……;

……

ALTER TABLE " SRCDB1"."SAMPLE_FK_N" ADD ……;

srcdb1_triggers.ddl: Contains ddl statements to create triggers.

Listing 4. srcdb1_triggers.ddl statement

CREATE TRIGGER SRCDB1.SAMPLE_TRIG_1 AFTER UPDATE OF col1 ON SRCDB1.SAMPLE_TAB


REFERENCING NEW AS n FOR EACH ROW MODE DB2SQL WHEN ( n.col1 > 3)

BEGIN ATOMIC

update SAMPLE_TAB

set(col2) = anotherValue where col1 = n.col1 ;--

END;

CREATE TRIGGER SRCDB1. SAMPLE_TRIG_2 ……;

……

CREATE TRIGGER SRCDB1. SAMPLE_TRIG_N ……;

srcdb1_procedures.ddl: Contains ddl statements to create SQL stored procedures and java stored procedures.

Listing 5. srcdb1_procedures.ddl statement

CREATE PROCEDURE " SRCDB1"." JAVA_PROCEDURE_1" (

OUT SQLSTATE CHARACTER(5),

OUT ROWS_SUBMITED INTEGER,

IN BATCH_ID INTEGER,

IN LEVEL VARCHAR(4000)

)

DYNAMIC RESULT SETS 0

SPECIFIC SUBMIT_BATCH

EXTERNAL NAME Submit_batch!submit_batch

LANGUAGE JAVA

PARAMETER STYLE JAVA

NOT DETERMINISTIC

FENCED THREADSAFE

MODIFIES SQL DATA

NO DBINFO;

CREATE PROCEDURE " SRCDB1"."JAVA_PROCEDURE_2" ……;

……

CREATE PROCEDURE " SRCDB1"."JAVA_PROCEDURE_N" ……;


SET CURRENT SCHEMA = " SRCDB1";

SET CURRENT PATH = "SYSIBM","SYSFUN"," SRCDB1";

CREATE PROCEDURE SRCDB1.SQL_PROCEDURE_1 (

IN hostname varchar(4000),

IN username varchar(4000),

OUT SQLCODE_OUT int )

SPECIFIC SRCDB1.SQL_PROCEDURE_1

LANGUAGE SQL

-------------------------------------------------- --

-- SQL Stored Procedure

-------------------------------------------------- --

P1: BEGIN

……

END P1 ;

CREATE PROCEDURE SRCDB1.SQL_PROCEDURE_2 ……;

……

CREATE PROCEDURE SRCDB1.SQL_PROCEDURE_N…;

It should be noted that the db2 v6 version of db2look has not yet implemented the ddl statement for extracting database objects such as UDF, TRIGGER, UserSpace, NodeGroup, BufferPool, etc. Starting from db2 v7, db2look can extract the DDL of the above objects, but it still cannot extract the ddl statement that creates the stored procedure object. Starting from db2 v8.2, support for the db2look function has been improved, and the extraction function of stored procedure ddl statements has been implemented. Since the source database system involved in this article is of a lower version (DB2 v8.1), the above solution needs to be adopted to obtain the DDL information of all database objects:

1). Perform a CATALOG operation on SRCDB1 (DB2 v8.1 version) from a DB2 v8.2 system:


db2 catalog db SRCDB1 as SRCDB1;

2). db2look extraction process of SRCDB1 from DB2 v8.2 system:

db2look -d SRCDB1 -e -o srcdb1.ddl -a -i user_srcdb1 -w pw_srcdb1;

This way you can get the complete database object DDL information.

3. Generate data export expo

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508263.htmlTechArticleThis article mainly introduces how to complete the transplantation process of PHP application system based on DB2 from AIX platform to Linux platform. The article includes the underlying DB2 database transplantation and the upper-level PHP application system...

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template