<<卸甲笔记>>-Oracle线下迁移到PPAS

迁移原则

1、尽量保持Oracle与PPAS一致,这会使得日后应用程序迁移更为简单

2、迁移前检查PPAS中是否有同名帐号及同名的Schema

a)如果有,建议考虑删除或改名

b)如果没有,先手工建立与Oracle同名的帐号及Schema

3、用MTK迁移时,配置文件中目标数据库建议使用与Oracle同名的帐号(如本案例中使用scott),这样可以保持目标数据库中所有表和对象的主属用户都和Oracle中一致

一 环境准备

Oracle环境

a)       IP:192.168.1.113,管理员用户 :sys,system,SID:prod

b)       普通用户scott,密码 scott

c)       Oralce 源数据库分析

PPAS环境(Linux)

a)       安装PPAS

[[email protected] PPAS9.3GA]#tar zxvf ppasmeta-9.3.1.3-linux-x64.tar.gz

[[email protected] PPAS9.3GA]# cd ppasmeta-9.3.1.3-linux-x64

[[email protected] ppasmeta-9.3.1.3-linux-x64]# setenforce Permissive

[[email protected] ppasmeta-9.3.1.3-linux-x64]# ./ppasmeta-9.3.1.3-linux-x64.run --mode text

Language Selection

Please select the installation language

[1] English - English

[2] Japanese - 日本語

[3] Simplified Chinese - 简体中文

[4] Traditional Chinese - 繁体中文

[5] Korean - ???

Please choose an option [1] :

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

Welcome to the Postgres Plus Advanced Server Setup Wizard.

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

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

Please specify the directory where Postgres Plus Advanced Server will be installed.

Installation Directory [/opt/PostgresPlus/9.3AS]:

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

Select the components you want to install.

Database Server [Y/n] :Y

Connectors [Y/n] :Y

Infinite Cache [Y/n] :Y

Migration Toolkit [Y/n] :Y

Postgres Enterprise Manager Client [Y/n] :Y

pgpool-II [Y/n] :Y

EDB*Plus [Y/n] :Y

Slony Replication [Y/n] :Y

PgBouncer [Y/n] :Y

Is the selection above correct? [Y/n]: Y

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

Additional Directories

Please select a directory under which to store your data.

Data Directory [/opt/PostgresPlus/9.3AS/data]:

Please select a directory under which to store your Write-Ahead Logs.

Write-Ahead Log (WAL) Directory [/opt/PostgresPlus/9.3AS/data/pg_xlog]:

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

Configuration Mode

Postgres Plus Advanced Server always installs with Oracle(R) compatibility features and maintains full PostgreSQL compliance. Select your style preference for installation defaults and samples.

The Oracle configuration will cause the use of certain objects  (e.g. DATE data types, string operations, etc.) to produce Oracle compatible results, create the same Oracle sample tables, and have the database match Oracle examples used in the documentation.

Configuration Mode

[1] Oracle Compatible

[2] PostgreSQL Compatible

Please choose an option [1] :

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

……

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

Pre Installation Summary

Following settings will be used for installation:

Installation Directory: /opt/PostgresPlus/9.3AS

Data Directory: /opt/PostgresPlus/9.3AS/data

WAL Directory: /opt/PostgresPlus/9.3AS/data/pg_xlog

Database Port: 5444

Database Superuser: enterprisedb

Operating System Account: enterprisedb

Database Service: ppas-9.3

PgBouncer Listening Port: 6432

Press [Enter] to continue :

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

Setup is now ready to begin installing Postgres Plus Advanced Server on your computer.

Do you want to continue? [Y/n]: Y

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

Please wait while Setup installs Postgres Plus Advanced Server on your computer.

Installing Postgres Plus Advanced Server

0% ______________ 50% ______________ 100%

#########################################

Installing Database Server ...

Installing pgAgent ...

Installing Connectors ...

Installing Migration Toolkit ...

Installing EDB*Plus ...

Installing Infinite Cache ...

Installing Postgres Enterprise Manager Client ...

Installing Slony Replication ...

Installing pgpool-II ...

Installing PgBouncer ...

Installing StackBuilder Plus ...

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

Setup has finished installing Postgres Plus Advanced Server on your computer.

[[email protected] ppasmeta-9.3.1.3-linux-x64]# ps hf -u enterprisedb -o cmd

/opt/PostgresPlus/9.3AS/bin/pgbouncer -d /opt/PostgresPlus/9.3AS/share/pgbouncer.ini

/opt/PostgresPlus/9.3AS/bin/pgagent -l 1 -s /var/log/ppas-agent-9.3.log hostaddr=localhost port=5444 dbname=edb user=enterprisedb

/opt/PostgresPlus/9.3AS/bin/edb-postgres -D /opt/PostgresPlus/9.3AS/data

\_ postgres: logger process

\_ postgres: checkpointer process

\_ postgres: writer process

\_ postgres: wal writer process

\_ postgres: autovacuum launcher process

\_ postgres: stats collector process

\_ postgres: enterprisedb edb ::1[36172] idle

b)       PPAS pg_hba.conf文件基础配置

-bash-4.1$ vim /opt/PostgresPlus/9.3AS/data/pg_hba.conf

host    all             all             0.0.0.0/0               md5

c)       重新启动PPAS服务

[[email protected] data]# /etc/init.d/ppas-9.3 restart

Restarting Postgres Plus Advanced Server 9.3:

waiting for server to shut down.... done

server stopped

waiting for server to start.... done

server started

Postgres Plus Advanced Server 9.3 restarted successfully

d)       Oracle Client安装

[[email protected] ppasmeta-9.3.1.3-linux-x64]# rpm -ql oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64

package oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64 is not installed

[[email protected] oralceclient]# ls

oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.rpm

[[email protected] oralceclient]# rpm -ivh oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.rpm

Preparing...                ########################################### [100%]

1:oracle-instantclient11.########################################### [100%]

[[email protected] oralceclient]# rpm -ql oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64

/usr/lib/oracle/11.2/client64/bin/adrci

/usr/lib/oracle/11.2/client64/bin/genezi

/usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1

/usr/lib/oracle/11.2/client64/lib/libnnz11.so

/usr/lib/oracle/11.2/client64/lib/libocci.so.11.1

/usr/lib/oracle/11.2/client64/lib/libociei.so

/usr/lib/oracle/11.2/client64/lib/libocijdbc11.so

/usr/lib/oracle/11.2/client64/lib/ojdbc5.jar

/usr/lib/oracle/11.2/client64/lib/ojdbc6.jar

/usr/lib/oracle/11.2/client64/lib/xstreams.jar

e)       JDK确认(1.6以上)

[[email protected] ppasmeta-9.3.1.3-linux-x64]# rpm -qa|grep java

java-1.7.0-openjdk-devel-1.7.0.45-2.4.3.3.el6.x86_64

java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64

tzdata-java-2013g-1.el6.noarch

gcc-java-4.4.7-4.el6.x86_64

java_cup-0.10k-5.el6.x86_64

java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64

java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64

libvirt-java-0.4.9-1.el6.noarch

java-1.6.0-openjdk-devel-1.6.0.0-1.66.1.13.0.el6.x86_64

libvirt-java-devel-0.4.9-1.el6.noarch

[[email protected] ppasmeta-9.3.1.3-linux-x64]# which java

/usr/bin/java

[[email protected] ppasmeta-9.3.1.3-linux-x64]# ll /usr/bin/java

lrwxrwxrwx. 1 root root 22 Jun 13  2016 /usr/bin/java -> /etc/alternatives/java

f)        JDBC配置

[[email protected] ext]# cp /usr/lib/oracle/11.2/client64/lib/ojdbc6.jar /usr/lib/jvm/jre-1.7.0/lib/ext/

[[email protected] ext]# ls

dnsns.jar              localedata.jar  ojdbc6.jar      sunjce_provider.jar  zipfs.jar

gnome-java-bridge.jar  meta-index      pulse-java.jar  sunpkcs11.jar

二、迁移测试

在PPAS中建立测试用户及数据库

[[email protected] ppasmeta-9.3.1.3-linux-x64]# su – enterprisedb

-bash-4.1$ psql

psql.bin (9.3.1.3)

Type "help" for help.

edb=# create user scott password ‘scott‘ createrole createuser createdb login;

CREATE ROLE

edb=# create database scott owner scott;

CREATE DATABASE

MTK配置文件toolkit.properties

/opt/PostgresPlus/9.3AS/etc/toolkit.properties

[[email protected] etc]# vim toolkit.properties

SRC_DB_URL=jdbc:oracle:thin:@192.168.1.113:1521:prod

SRC_DB_USER=scott

SRC_DB_PASSWORD=scott

TARGET_DB_URL=jdbc:edb://localhost:5444/scott

TARGET_DB_USER=scott

TARGET_DB_PASSWORD=scott

/opt/PostgresPlus/9.3AS/bin/runMTK.sh

运行/runMTK.sh进行数据迁移

[[email protected] etc]# cd /opt/PostgresPlus/9.3AS/bin/

[[email protected] bin]# ./runMTK.sh  scott

Source database connectivity info...

conn =jdbc:oracle:thin:@192.168.1.113:1521:prod

user =scott

password=******

Target database connectivity info...

conn =jdbc:edb://localhost:5444/scott

user =scott

password=******

Connecting with source Oracle database server...

Connecting with target EnterpriseDB database server...

Importing redwood schema scott...

Creating Schema...scott

Creating Tables...

Creating Table: BONUS

Creating Table: DEPT

Creating Table: EMP

Creating Table: SALGRADE

Created 4 tables.

Loading Table Data in 8 MB batches...

Loading Table: BONUS ...

[BONUS] Table Data Load Summary: Total Time(s): 0.04 Total Rows: 0

Loading Table: DEPT ...

[DEPT] Migrated 4 rows.

[DEPT] Table Data Load Summary: Total Time(s): 0.01 Total Rows: 4

Loading Table: EMP ...

[EMP] Migrated 14 rows.

[EMP] Table Data Load Summary: Total Time(s): 0.049 Total Rows: 14

Loading Table: SALGRADE ...

[SALGRADE] Migrated 5 rows.

[SALGRADE] Table Data Load Summary: Total Time(s): 0.008 Total Rows: 5

Data Load Summary: Total Time (sec): 0.371 Total Rows: 23 Total Size(MB): 0.0

Creating Constraint: PK_DEPT

Creating Constraint: PK_EMP

Creating Constraint: FK_DEPTNO

Schema scott imported successfully.

Creating User: SCOTT

Error Creating User SCOTT (由于已经在目标端数据库创建了一个名为scott的用户,所以重新创建同名Scott用户时出错,如果目标端没有scott用户则不会出现错误。)

One or more schema objects could not be imported during the migration process. Please review the migration output for more details.

Migration logs have been saved to /root/.enterprisedb/migration-toolkit/logs

******************** Migration Summary ********************

Tables: 4 out of 4

Constraints: 3 out of 3

Users: 0 out of 1

Total objects: 8

Successful count: 7

Failure count: 1

List of failed objects

======================

Users

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

1. SCOTT

*************************************************************

查看迁移日志

[[email protected] etc]#  ll /root/.enterprisedb/migration-toolkit/logs/*

-rw-r--r--. 1 root root 2229 Jun 15 11:13 /root/.enterprisedb/migration-toolkit/logs/mtk_20160615111238.log

PPAS数据验证

-bash-4.1$ psql -h localhost -p 5444 -U scott -d scott

Password for user scott:

psql.bin (9.3.1.3)

Type "help" for help.

scott=# \d scott.*

Table "scott.bonus"

Column |         Type          | Modifiers

--------+-----------------------+-----------

ename  | character varying(10) |

job    | character varying(9)  |

sal    | numeric               |

comm   | numeric               |

Table "scott.dept"

Column |         Type          | Modifiers

--------+-----------------------+-----------

deptno | numeric(2,0)          | not null

dname  | character varying(14) |

loc    | character varying(13) |

Indexes:

"pk_dept" PRIMARY KEY, btree (deptno)

Referenced by:

TABLE "emp" CONSTRAINT "fk_deptno" FOREIGN KEY (deptno) REFERENCES dept(deptno) MATCH FULL

Table "scott.emp"

Column  |            Type             | Modifiers

----------+-----------------------------+-----------

empno    | numeric(4,0)                | not null

ename    | character varying(10)       |

job      | character varying(9)        |

mgr      | numeric(4,0)                |

hiredate | timestamp without time zone |

sal      | numeric(7,2)                |

comm     | numeric(7,2)                |

deptno   | numeric(2,0)                |

Indexes:

"pk_emp" PRIMARY KEY, btree (empno)

Foreign-key constraints:

"fk_deptno" FOREIGN KEY (deptno) REFERENCES dept(deptno) MATCH FULL

Index "scott.pk_dept"

Column |     Type     | Definition

--------+--------------+------------

deptno | numeric(2,0) | deptno

primary key, btree, for table "scott.dept"

Index "scott.pk_emp"

Column |     Type     | Definition

--------+--------------+------------

empno  | numeric(4,0) | empno

primary key, btree, for table "scott.emp"

Table "scott.salgrade"

Column |  Type   | Modifiers

--------+---------+-----------

grade  | numeric |

losal  | numeric |

hisal  | numeric |

scott=# select * from scott.emp ;

empno | ename  |    job    | mgr  |      hiredate      |   sal   |  comm   | deptno

-------+--------+-----------+------+--------------------+---------+---------+--------

7369 | SMITH  | CLERK     | 7902 | 17-DEC-80 00:00:00 |  800.00 |         |     20

7499 | ALLEN  | SALESMAN  | 7698 | 20-FEB-81 00:00:00 | 1600.00 |  300.00 |     30

7521 | WARD   | SALESMAN  | 7698 | 22-FEB-81 00:00:00 | 1250.00 |  500.00 |     30

7566 | JONES  | MANAGER   | 7839 | 02-APR-81 00:00:00 | 2975.00 |         |     20

7654 | MARTIN | SALESMAN  | 7698 | 28-SEP-81 00:00:00 | 1250.00 | 1400.00 |     30

7698 | BLAKE  | MANAGER   | 7839 | 01-MAY-81 00:00:00 | 2850.00 |         |     30

7782 | CLARK  | MANAGER   | 7839 | 09-JUN-81 00:00:00 | 2450.00 |         |     10

7788 | SCOTT  | ANALYST   | 7566 | 19-APR-87 00:00:00 | 3000.00 |         |     20

7839 | KING   | PRESIDENT |      | 17-NOV-81 00:00:00 | 5000.00 |         |     10

7844 | TURNER | SALESMAN  | 7698 | 08-SEP-81 00:00:00 | 1500.00 |    0.00 |     30

7876 | ADAMS  | CLERK     | 7788 | 23-MAY-87 00:00:00 | 1100.00 |         |     20

7900 | JAMES  | CLERK     | 7698 | 03-DEC-81 00:00:00 |  950.00 |         |     30

7902 | FORD   | ANALYST   | 7566 | 03-DEC-81 00:00:00 | 3000.00 |         |     20

7934 | MILLER | CLERK     | 7782 | 23-JAN-82 00:00:00 | 1300.00 |         |     10

(14 rows)

Oracle端数据

SQL> select segment_name from dba_segments where owner=‘SCOTT‘;

SEGMENT_NAME

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

PK_EMP

PK_DEPT

SALGRADE

EMP

DEPT

SQL> conn scott/scott

Connected.

SQL> desc emp;

Name                                             Null?    Type

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

EMPNO                                          NOT NULL NUMBER(4)

ENAME                                                     VARCHAR2(10)

JOB                                                            VARCHAR2(9)

MGR                                                         NUMBER(4)

HIREDATE                                                DATE

SAL                                                   NUMBER(7,2)

COMM                                                     NUMBER(7,2)

DEPTNO                                                  NUMBER(2)

SQL> select * from emp;

EMPNO ENAME JOB MGR HIREDATE
---------- -------------------- ------------------ ---------- ------------
SAL COMM DEPTNO
---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20

7499 ALLEN SALESMAN 7698 20-FEB-81
1600 300 30

7521 WARD SALESMAN 7698 22-FEB-81
1250 500 30

EMPNO ENAME JOB MGR HIREDATE
---------- -------------------- ------------------ ---------- ------------
SAL COMM DEPTNO
---------- ---------- ----------
7566 JONES MANAGER 7839 02-APR-81
2975 20

7654 MARTIN SALESMAN 7698 28-SEP-81
1250 1400 30

7698 BLAKE MANAGER 7839 01-MAY-81
2850 30

EMPNO ENAME JOB MGR HIREDATE
---------- -------------------- ------------------ ---------- ------------
SAL COMM DEPTNO
---------- ---------- ----------
7782 CLARK MANAGER 7839 09-JUN-81
2450 10

7788 SCOTT ANALYST 7566 19-APR-87
3000 20

7839 KING PRESIDENT 17-NOV-81
5000 10

EMPNO ENAME JOB MGR HIREDATE
---------- -------------------- ------------------ ---------- ------------
SAL COMM DEPTNO
---------- ---------- ----------
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30

7876 ADAMS CLERK 7788 23-MAY-87
1100 20

7900 JAMES CLERK 7698 03-DEC-81
950 30

EMPNO ENAME JOB MGR HIREDATE
---------- -------------------- ------------------ ---------- ------------
SAL COMM DEPTNO
---------- ---------- ----------
7902 FORD ANALYST 7566 03-DEC-81
3000 20

7934 MILLER CLERK 7782 23-JAN-82
1300 10

14 rows selected.

本连载博客主要探讨Oracle与PPAS(PostgreSQL)数据库的差异,以帮助更多读者了解如何实现数据库迁移!

时间: 2024-08-24 16:05:43

<<卸甲笔记>>-Oracle线下迁移到PPAS的相关文章

《卸甲笔记》-多表查询之一

1查询emp表中数据量 14条数据Oracle```SQL> select count(*) from emp; COUNT(*)---------- 14```PPAS```scott=# select count(*) from emp; count ------- 14(1 row)```2查询dept表中的数据库 4条数据Oracle```SQL> select count(*) from dept; COUNT(*)---------- 4```PPAS```scott=# sele

《卸甲笔记》-限定查询与排序显示

限定查询与排序显示 限定查询指的是在数据查询时设置一系列的过滤条件,只有满足指定的条件后才可以进行显示 在SQL标准中限定查询的语法如下: select [distinct] *|列名称 [as] [列别名],列名称 [as] [列别名], … from 表名称 [表别名] [where 条件(s)] 1查看emp表中的数据量 Oracle SQL> select count(*) from emp; COUNT(*) ---------- 14 PPAS scott=# select coun

《卸甲笔记》-多表查询之二

13增加右外连接,显示部门40的信息Oracle```SQL> select * 2 from emp e,dept d 3 where e.deptno(+)=d.deptno; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO DEPTNO DNAME LOC---------- ---------- ---------- ---------- ------------ ---------- ---------- ---------- --------

《卸甲笔记》-分组统计查询

统计函数对比 1查询出公司每个月支出的月工资总和 Oracle SQL> select SUM(sal) from emp; SUM(SAL) ---------- 29025 PPAS scott=# select SUM(sal) from emp; sum ---------- 29025.00 (1 row) 2查询出公司的最高工资,最低工资,平均工资 Oracle SQL> select AVG(sal),ROUND(AVG(sal),2),MAX(sal),MIN(sal) fro

《卸甲笔记》-子查询

1查询公司中工资最低的雇员的完整信息 Oracle SQL> select * 2  from emp 3  where sal=( 4  select MIN(sal) from emp); EMPNO ENAME      JOB            MGR HIREDATE                 SAL     COMM    DEPTNO ---------- ---------- ---------- ---------- ------------ ---------- -

【Linux】将Oracle安装目录从根目录下迁移到逻辑卷

[Linux]将Oracle安装目录从根目录下迁移到逻辑卷 1.1  BLOG文档结构图 1.2  前言部分 1.2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~O(∩_∩)O~: ① Linux逻辑卷的创建和管理(重点) 1.2.2  相关文章链接 linux逻辑卷管理:http://blog.itpub.net/26736162/viewspace-2124620/,这篇文章非常不错. 1.2.3  本文简介 由于Oracle

MS SQL到Oracle的数据迁移笔记

MS SQL到Oracle的数据迁移笔记 一.任务背景 旧系统使用MS SQL Server数据库,新系统使用Oracle数据库,现在需要将旧系统中的数据迁移到新系统中,旧数据按照约定的规则转换后,能够在新系统中使用或查询.另外,新系统的实施人员并不清楚旧系统的数据结构,且两个新旧两个系统的使用的数据结构有较大的差异.为了叙述方便,将旧系统维护人员简称为A,新系统实施人员简称为B. 二.总体思路 1.  A与B根据各自了解的信息,一起制定中间表: 2.  A从MS SQL Server提取数据,

深喉起底APP线下预装市场,如何一夜间拥有千万用户

注:预装对于中国的移动互联网创业者有多重要?i黑马知道这样一个内幕,某商务告诉我他们公司的前2000万用户就是靠预装打下来的,总部在北京,直接派驻商务长期扎根在深圳搞定手机厂商.而这家公司初期发展得益于此,如今已经成长为估值5亿美金的中国互联网新贵,并且在前段时间由于风头太盛而被产业群起而攻之. 总之,搞好预装,对于创业者来说,可能就意味能轻松获得几百万甚至几千万用户,这种用户基量可以快速催生出下一个移动互联网新贵. 这篇关于预装的文章,拖了有大概两周.再不写都要鄙视自己了. 事情的起因是这样的

oracle学习-数据迁移

如果只是迁移表空间或者数据文件,可以先将表空间或者数据文件offline之后移动位置,并通过 alert database rename 和 alter tablespace rename 将位置变化写入控制文件即可 例 迁移数据文件 ALTER DATABASE DATAFILE '所要迁移的数据文件' OFFLINE; 拷贝到新位置 ALTER DATABASE RENAME FILE '索要迁移的数据文件' TO '新位置的数据文件'; 介质恢复 RECOVE DATAFILE '新位置的