前言:
有的时候有需求需要迁移Oracle数据库的数据到postgresql,那么,其实可供选择的工具是比较多的,但从迁移效率,准确度这些角度来选择的话,无疑还是GitHub上的开源免费工具ora2pg比较合适的。
ora2pg的优点是免费,迁移速度快,迁移数据准确,部署简单,快速
下面将介绍如何在A服务器 centos7下面部署安装ora2pg,在另一台服务器B上通过docker安装部署一个Oracle,并简单的写一些数据
环境简介:
A服务器的IP是192.168.123.11,操作系统是centos,安装有postgresql数据库
B服务器的IP是192.168.123.12,操作系统是centos,安装有docker启动的Oracle数据库
一,
postgresql的概况
pg数据库所在服务器的IP地址是 192.168.123.11
计划在此服务器上安装ora2pg
二,
ora2pg的安装部署
####注:这一部分相关部署都是在192.168.123.11上的哦
相关文件下载:
相关文件在百度网盘上,地址如下:
链接:https://pan.baidu.com/s/1ixb6Vi7aCvNXfzWOqM13rw?pwd=ora2
提取码:ora2
--来自百度网盘超级会员V5的分享
版本说明:
ora2pg的版本选用的比较高,考虑到pg数据库版本是12,Oracle数据库的版本是11g,还算比较新,并且ora2pg版本高一点,功能会稍微多一点。
架构说明:
ora2pg的工作原理是利用Oracle的客户端,通过dbd插件和dbi插件连接Oracle数据库,读取预设的自定义规则(自定义规则定义在ora2pg的配置文件内),按照设定规则扫描Oracle数据库内的目标表,逆向生成可供postgresql数据库直接使用的SQL存储语句
1,
dbi的安装
yum install -y perl-DBI perl-DBD-Pg perl-ExtUtils-MakeMaker perl-ExtUtils-CBuilder perl-CPAN perl-ExtUtils-eBuilder
yum install perl perl-devel make gcc gcc-c++ -y
yum install perl-Time-HiRes perl-tests cpan perl-Time-HiRes -y
该插件基本不需要考虑太多版本问题,直接本地仓库yum安装即可
####注意,perl的版本必须是5.0以上!!!!!!!!!!
2,
oracle的客户端安装
#####注,必须先安Oracle的客户端,否则后面的dbd::oracle会安装不了报错
unzip instantclient-basic-linux.x64-19.20.0.0.0dbru.zip
unzip instantclient-sdk-linux.x64-19.20.0.0.0dbru.zip
unzip instantclient-sqlplus-linux.x64-19.20.0.0.0dbru.zip
mkdir -p /opt/user/lib
mv instantclient_19_20 /opt/user/lib
cd /opt/user/lib
chmod 755 /opt/user/lib/instantclient_19_20/
chmod 755 -Rf /opt/user/lib/instantclient_19_20/
echo "export PATH=/opt/user/lib/instantclient_19_20/:$PATH">>/etc/profile
echo "export
LD_LIBRARY_PATH=/opt/user/lib/instantclient_19_20/:$LD_LIBRARY_PATH">>/etc/profile
source /etc/profile
3,
dbd的安装
####注:再次重申,必须先安装oracle的客户端
cd DBD-Oracle-1.83/
perl Makefile.PL -l
make
make install
大体输出如下;
[root@centos9 DBD-Oracle-1.83]# perl Makefile.PL -l
Using DBI 1.627 (for perl 5.016003 on x86_64-linux-thread-multi) installed in /usr/lib64/perl5/vendor_perl/auto/DBI/
Configuring DBD::Oracle for perl 5.016003 on linux (x86_64-linux-thread-multi)If you encounter any problem, a collection of troubleshooting
guides are available under lib/DBD/Oracle/Troubleshooting.
'DBD::Oracle::Troubleshooting' is the general troubleshooting
guide, while platform-specific troubleshooting hints
live in their labelled sub-document (e.g., Win32
hints are gathered in 'lib/DBD/Oracle/Troubleshooting/Win32.pod').Trying to find an ORACLE_HOME
Found /opt/user/lib/instantclient_19_20/WARNING: Setting ORACLE_HOME env var to /opt/user/lib/instantclient_19_20/ for you.
WARNING: If these tests fail you may have to set ORACLE_HOME yourself!
Installing on a linux, Ver#3.10
Using Oracle in /opt/user/lib/instantclient_19_20/
DEFINE _SQLPLUS_RELEASE = "1920000000" (CHAR)
Oracle Version 19.20.0.0 (19.20)
Looks like an Instant Client installation, okay
Your LD_LIBRARY_PATH env var is set to '/opt/user/lib/instantclient_19_20/:'
Oracle sysliblist:
Found header files in /opt/user/lib/instantclient_19_20//sdk/include.client_version=19.20DEFINE= -Wall -Wno-comment -DUTF8_SUPPORT -DORA_OCI_VERSION=\"19.20.0.0\" -DORA_OCI_102 -DORA_OCI_112Checking for functioning wait.phSystem: perl5.016003 linux x86-01.bsys.centos.org 3.10.0-693.17.1.el7.x86_64 #1 smp thu jan 25 20:13:58 utc 2018 x86_64 x86_64 x86_64 gnulinux
Compiler: gcc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
Linker: /usr/bin/ld
Sysliblist:
Linking with -lclntsh.Checking if your kit is complete...
Looks good
Unrecognized argument in LIBS ignored: '-Wl,-rpath,/opt/user/lib/instantclient_19_20/'
LD_RUN_PATH=/opt/user/lib/instantclient_19_20
Using DBD::Oracle 1.83.
Using DBD::Oracle 1.83.
Using DBI 1.627 (for perl 5.016003 on x86_64-linux-thread-multi) installed in /usr/lib64/perl5/vendor_perl/auto/DBI/
基本没什么好说的,基础的编译环境具备就可以了
4,
ora2pg的安装
该安装类似DBD的安装,没什么好说的
####注:ora2pg安装完毕后会自动将可执行文件加入环境变量,无需过多设置
cd ora2pg-23.1/perl Makefile.PL -lecho $?makeecho $?make installecho $?
命令输出如下:
[root@centos9 ora2pg]# cd ora2pg-23.1
[root@centos9 ora2pg-23.1]# ls
changelog doc INSTALL lib LICENSE Makefile.PL MANIFEST packaging README scripts
[root@centos9 ora2pg-23.1]# perl Makefile.PL -l
Checking if your kit is complete...
Looks good
Writing Makefile for Ora2PgDone...
------------------------------------------------------------------------------
Please read documentation at http://ora2pg.darold.net/ before asking for help
------------------------------------------------------------------------------
Now type: make && make install
[root@centos9 ora2pg-23.1]# make && make install
cp lib/Ora2Pg.pm blib/lib/Ora2Pg.pm
cp lib/Ora2Pg/GEOM.pm blib/lib/Ora2Pg/GEOM.pm
cp lib/Ora2Pg/Oracle.pm blib/lib/Ora2Pg/Oracle.pm
cp lib/Ora2Pg/PLSQL.pm blib/lib/Ora2Pg/PLSQL.pm
cp lib/Ora2Pg/MySQL.pm blib/lib/Ora2Pg/MySQL.pm
cp scripts/ora2pg blib/script/ora2pg
/usr/bin/perl -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/ora2pg
cp scripts/ora2pg_scanner blib/script/ora2pg_scanner
/usr/bin/perl -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/ora2pg_scanner
Manifying blib/man3/ora2pg.3
Installing /usr/local/share/perl5/Ora2Pg.pm
Installing /usr/local/share/perl5/Ora2Pg/GEOM.pm
Installing /usr/local/share/perl5/Ora2Pg/Oracle.pm
Installing /usr/local/share/perl5/Ora2Pg/PLSQL.pm
Installing /usr/local/share/perl5/Ora2Pg/MySQL.pm
Installing /usr/local/share/man/man3/ora2pg.3
Installing /usr/local/bin/ora2pg
Installing /usr/local/bin/ora2pg_scanner
Installing default configuration file (ora2pg.conf.dist) to /etc/ora2pg
Appending installation info to /usr/lib64/perl5/perllocal.pod
[root@centos9 ora2pg-23.1]# echo $?
三,
Oracle数据库的部署
Oracle数据库部署非常简单,因为是测试性质,因此,使用docker结合docker-compose拉起Oracle数据库即可
#####注:此数据库安装在192.168.123.12服务器上,启动数据库命令为:
[root@oula2 ~]# cat oracle.yaml
version: '3'
services:
oracle:
restart: always
image: hub.c.163.com/springwen/oracle12c
container_name: oracle
volumes:
- /usr/local/oracle/data:/u01/app/oracle
- /usr/local/oracle/source:/docker-entrypoint-initdb.d
environment:
- "TZ=Asia/Shanghai"
- "DBCA_TOTAL_MEMORY=16192"
- "IMPORT_FROM_VOLUME=true"
ports:
- 53432:1521
- 36888:8080
logging:
driver: "json-file"
options:
max-size: "1g"
使用sqldeveloper连接该数据库:
####注:sys用户的密码是oracle
创建emp测试表:
CREATE TABLE emp ( emp_id NUMBER(10) PRIMARY KEY, emp_name VARCHAR2(50), emp_age NUMBER(3), emp_sal NUMBER(10, 2)
);
创建测试用户:
####注,该用户的密码是gzmpc,此用户是普通用户
create tablespace gzmoc_wk
datafile '/u01/app/oracle/gzmoc_wk.DBF'
size 100m
autoextend on next 10m maxsize 500m
permanent
extent management local;
CREATE USER gzmpc
IDENTIFIED BY PASSWORD
DEFAULT TABLESPACE gzmoc_wk;
grant create session to gzmpc;
grant create table to gzmpc;
grant unlimited tablespace to gzmpc;
ALTER USER gzmpc IDENTIFIED BY gzmpc;
四,
迁移配置
主要的最为关键的就是ora2pg的配置文件了,此文件是有模版的,该模版文件在/etc/ora2pg目录下,大概是1300行,内容比较多的
下面将就此配置文件做一个详细的解读
未完待续!!!!!!!!!!