对达梦连接oracle进行配置,实验使用oci方式进行测试,使用19c的OCI连接达梦数据库,即便Oracle版本是11g也没有关系,因为oci版本是向下兼容的。
本次测试环境:
操作系统版本:Redhat 7.3
Oracle数据库版本:Oracle 19.3.0.0
DM数据库版本:DM V8 1-2-70 ENT
Oracle Instant Client包版本:19.25
一.OCI方式
达梦端安装oracle客户端工具oci进行配置连接到Oracle
达梦:
1.检查glibc版本
[root@localhost ~]# rpm -qi glibc
Name : glibc
Version : 2.17
Release : 307.el7.1
Architecture: x86_64
Install Date: Mon 02 Aug 2021 03:28:10 PM CST
Group : System Environment/Libraries
Size : 14100570
License : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+
Signature : RSA/SHA256, Sat 04 Apr 2020 04:52:25 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM : glibc-2.17-307.el7.1.src.rpm
Build Date : Wed 01 Apr 2020 06:33:57 AM CST
Build Host : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://www.gnu.org/software/glibc/
Summary : The GNU libc libraries
Description :
The glibc package contains standard libraries which are used by
multiple programs on the system. In order to save disk space and
memory, as well as to make upgrading easier, common system code is
kept in one place and shared between programs. This particular package
contains the most important sets of shared libraries: the standard C
library and the standard math library. Without these two libraries, a
Linux system will not function.
[root@localhost ~]# ldd --version
ldd (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
2.检查libaio包
[root@localhost ~]# rpm -qa|grep libaio
libaio-0.3.109-13.el7.x86_64#如果没有执行安装
[root@localhost ~]# yum -y install libaio*
3.安装Oracle Instant Client包
[root@localhost ~]# mkdir -p /opt/oracle
[root@localhost ~]# unzip instantclient-basic-linux.x64-19.25.0.0.0dbru.zip -d /opt/oracle
[root@localhost ~]# unzip instantclient-odbc-linux.x64-19.25.0.0.0dbru.zip -d /opt/oracle
[root@localhost oracle]# cd instantclient_19_25/
[root@localhost instantclient_19_25]# pwd
/opt/oracle/instantclient_19_25
##所有的驱动包都在/opt/oracle/instantclient_19_25目录下
如果Instant Client安装包是18.3 之前的版本,还需要创建几个动态库的软链接。不然会在创建dblink和使用时提示加载库文件失败
4.配置环境变量
[root@localhost ~]# echo /opt/oracle/instantclient_19_25 > /etc/ld.so.conf.d/oracle-instantclient.conf
[root@localhost ~]# cat /etc/ld.so.conf.d/oracle-instantclient.conf
/opt/oracle/instantclient_19_25
[root@localhost ~]# ldconfig
修改dmdba用户下的.bash_profile文件,添加LD_LIBRARY_PATH环境变量
vi .bash_profile
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/oracle/instantclient_19_25"
source ~/.bash_profile
5.创建dblink连接
我这里是连接到Oracle19c 中的pdb容器下的user1用户
create link "LINKORA" connect 'oracle' with "USER1" identified by "123456" using '(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.171.132)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = PDB2)
)
)';
这里需要注意user名大小写,第一次创建后进行查询提示[-6033]:DBLINK连接丢失;查询DMserver日志才知道
6.测试dblink
test1为oracle数据库提前建好的表数据
SQL> select * from test1@LINKORA;
行号 ID NAME VALUE
---------- -- ----- -----
1 1 aqj1 1
2 2 aqj2 2
3 3 aqj3 3
4 4 aqj4 4
5 5 aqj5 5
6 6 aqj6 6
7 7 aqj7 7
8 8 aqj8 8
9 9 aqj9 9
10 10 aqj10 10
11 11 aqj11 11
行号 ID NAME VALUE
---------- -- ----- -----
12 12 aqj12 12
7.删除dblink
drop link LINKORA;
注意每次使用dblink查询的时候,均会与远程数据库创建一个连接,dblink 应该不会自动释放这个连接,如果是大量使用 dblink 查询,会造成 web 项目的连接数不够,导致系统无法正常运行,导致系统无正常运行,并且对使用dblink连接的数据库、表不能做ddl操作