rust连接oracle数据库遇到DPI-1047: Cannot locate a 64-bit Oracle Client library的解决方案

这两天要实现一个用rust连接远程的oracle数据库的需求,所以就需要用rust连接oracle。

在github上面找到一个库,地址:https://github.com/kubo/rust-oracle

直接使用时,发现报错,打印报错信息:

Err(DpiError(DbError { code: 0, offset: 3416999480, message: "DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help", fn_name: "dpiContext_createWithParams", action: "load library" }))

根据 https://oracle.github.io/odpi/doc/installation.html#linux 上的说明,大概查了一下,大概明白了。

这个rust-oracle不是直接连接远程oracle的,而是需要在服务器上加载一个oracle客户端的库,然后调用这个库才可以连接到oracle上。

  • oracle客户端下载地址:https://www.oracle.com/database/technologies/instant-client/downloads.html

本来是在macos m1上面开发的,但是m1是arm架构的,而官网只有x64架构的,所以就只能使用虚拟机上的ubuntu了。

下面是操作步骤:

1. sudo mkdir -p /opt/oracle	#创建一个目录来保存oracle客户端文件
2. cd /opt/oracle	#进入上面创建的这个目录
3. wget https://download.oracle.com/otn_software/linux/instantclient/191000/instantclient-basic-linux.arm64-19.10.0.0.0dbru.zip	#下载客户端文件,我下载的是zip格式的,等下再解压
4. unzip instantclient-basic-linux.arm64-19.10.0.0.0dbru.zip	#解压下载好的文件到当前目录
 
 解压好之后,ls看一下,可以看到当前目录多了一个目录instantclient_19_10 这个目录里面的文件就是需要的.so库文件,剩下的任务就是要在rust里面能够加载到这个库.
 
//意思是把/opt/oracle/instantclient_19_10写入到/etc/ld.so.conf.d/oracle-instantclient.conf文件,文件不存在则新建
5. sudo sh -c "echo /opt/oracle/instantclient_19_10 > /etc/ld.so.conf.d/oracle-instantclient.conf"  

//用ldconfig 执行文件将 /etc/ld.so.conf(也就是/etc/ld.so.conf.d/文件夹下面的所有conf文件)的数据读入高速缓存中,同时记录到/etc/ld.so.cache文件中。
6.ldconfig

这样的话,linux系统就能把客户端库加载到,然后rust-oracle就能连接到oracle了。

参考资料:

  • https://oracle.github.io/odpi/doc/installation.html#oracle-instant-client-zip-files
  • https://man7.org/linux/man-pages/man8/ld.so.8.html

你可能感兴趣的:(rust连接oracle数据库遇到DPI-1047: Cannot locate a 64-bit Oracle Client library的解决方案)