1

我在我的 RHEL 6 上运行了 PostgreSQL 驱动程序。但是在我安装 Microsoft® SQL Server® ODBC Driver 1.0 for Linux 后,我无法再连接到 PosgreSQL 数据源。我可以很好地连接到 SQL Server 数据源。

当我一周前遇到同样的问题时,我从 Linux 上卸载了 MS SQL Server ODBC 驱动程序,它解决了这个问题。我通过执行以下命令删除了 MS SQL Server ODBC 驱动程序:

rm /usr/bin/bcp
rm /usr/bin/sqlcmd
odbcinst -u -d -n "SQL Server Native Client 11.0"
rm -r /opt/microsoft/sqlncli

我仍然必须psqlodbcw.so从另一台运行 PostgreSQL 驱动程序的 Linux 机器上复制文件(MS 驱动程序安装使它们无法访问,尽管它们存在)。

同样,我需要使用 MS SQL 驱动程序,因此再次安装。再次安装 MS SQL 驱动程序 - 我再次无法连接到 PostgreSQL 驱动程序。不过,我没有卸载 MS SQL 驱动程序并检查了发生了什么。这次我发现安装文件已被删除:/usr/lib64/libodbcpsqlS.so. 但是,补充文件并没有解决问题,因为我没有像前一种情况那样卸载 MS SQL。

尽管文件存在rwx权限,但我仍然收到以下错误消息:

[root@localhost lib64]# isql -v STUDENT dsname pwd12345
[01000][unixODBC][Driver Manager]Can't open lib '/usr/lib64/psqlodbc.so' : file not found
[ISQL]ERROR: Could not SQLConnect
[root@localhost lib64]# 

这是文件权限的打印输出:

[root@localhost lib64]# ls -al p*.so
lrwxrwxrwx. 1 root root     12 Dec  7 09:15 psqlodbc.so -> psqlodbcw.so
-rwxr-xr-x. 1 root root 519496 Dec  7 09:35 psqlodbcw.so

我的odbcinst.ini文件如下所示:

[PostgreSQL]
Description=ODBC for PostgreSQL
Driver=/usr/lib/psqlodbc.so
Driver64=/usr/lib64/psqlodbc.so
Setup=/usr/lib/libodbcpsqlS.so
Setup64=/usr/lib64/libodbcpsqlS.so
FileUsage=1
UsageCount=4

我还提到了这个链接: http: //mailman.unixodbc.org/pipermail/unixodbc-support/2010-September.txt

运行输出:

[root@localhost bin]# ldd /usr/lib64/psqlodbc.so 
    linux-vdso.so.1 =>  (0x00007fff371ea000)
    libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007f55f288f000)
    libpq.so.5 => /usr/lib64/libpq.so.5 (0x00007f55f2667000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f55f2449000)
    libodbcinst.so.2 => not found
    libodbc.so.2 => not found
    libc.so.6 => /lib64/libc.so.6 (0x00007f55f20b5000)
    libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f55f1e73000)
    libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f55f1b94000)
    libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f55f198f000)
    libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f55f1763000)
    libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007f55f13c9000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f55f11c4000)
    libz.so.1 => /lib64/libz.so.1 (0x00007f55f0fae000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f55f0d77000)
    libldap_r-2.4.so.2 => /lib64/libldap_r-2.4.so.2 (0x00007f55f0b23000)
    /lib64/ld-linux-x86-64.so.2 (0x0000003d6f600000)
    libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f55f0918000)
    libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f55f0715000)
    libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f55f04fa000)
    libfreebl3.so => /lib64/libfreebl3.so (0x00007f55f0298000)
    liblber-2.4.so.2 => /lib64/liblber-2.4.so.2 (0x00007f55f0088000)
    libssl3.so => /usr/lib64/libssl3.so (0x00007f55efe4c000)
    libsmime3.so => /usr/lib64/libsmime3.so (0x00007f55efc20000)
    libnss3.so => /usr/lib64/libnss3.so (0x00007f55ef8e3000)
    libnssutil3.so => /usr/lib64/libnssutil3.so (0x00007f55ef6bd000)
    libplds4.so => /lib64/libplds4.so (0x00007f55ef4b9000)
    libplc4.so => /lib64/libplc4.so (0x00007f55ef2b3000)
    libnspr4.so => /lib64/libnspr4.so (0x00007f55ef076000)
    libsasl2.so.2 => /usr/lib64/libsasl2.so.2 (0x00007f55eee5c000)
    libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f55eec3c000)

我不想从我的 Linux 机器上卸载 MS SQL 驱动程序来让 PostgreSQL 驱动程序工作。我希望这两个驱动程序都可以在 Linux 上运行。

Craig Ringer 建议运行:

[root@localhost bin]# LD_DEBUG=libs isql -v STUDENT dsname pwd12345
     22029: find library=libodbc.so.1 [0]; searching
     22029:  search path=/usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64      (system search path)
     22029:   trying file=/usr/lib64/tls/x86_64/libodbc.so.1
     22029:   trying file=/usr/lib64/tls/libodbc.so.1
     22029:   trying file=/usr/lib64/x86_64/libodbc.so.1
     22029:   trying file=/usr/lib64/libodbc.so.1
     22029: 
     22029: find library=libdl.so.2 [0]; searching
     22029:  search path=/usr/lib64/tls:/usr/lib64      (system search path)
     22029:   trying file=/usr/lib64/tls/libdl.so.2
     22029:   trying file=/usr/lib64/libdl.so.2
     22029:  search cache=/etc/ld.so.cache
     22029:   trying file=/lib64/libdl.so.2
     22029: 
     22029: find library=libpthread.so.0 [0]; searching
     22029:  search path=/usr/lib64/tls:/usr/lib64      (system search path)
     22029:   trying file=/usr/lib64/tls/libpthread.so.0
     22029:   trying file=/usr/lib64/libpthread.so.0
     22029:  search cache=/etc/ld.so.cache
     22029:   trying file=/lib64/libpthread.so.0
     22029: 
     22029: find library=libc.so.6 [0]; searching
     22029:  search path=/usr/lib64/tls:/usr/lib64      (system search path)
     22029:   trying file=/usr/lib64/tls/libc.so.6
     22029:   trying file=/usr/lib64/libc.so.6
     22029:  search cache=/etc/ld.so.cache
     22029:   trying file=/lib64/libc.so.6
     22029: 
     22029: 
     22029: prelink checking: ok
     22029: 
     22029: calling init: /lib64/libpthread.so.0
     22029: 
     22029: 
     22029: calling init: /lib64/libc.so.6
     22029: 
     22029: 
     22029: calling init: /lib64/libdl.so.2
     22029: 
     22029: 
     22029: calling init: /usr/lib64/libodbc.so.1
     22029: 
     22029: 
     22029: initialize program: isql
     22029: 
     22029: 
     22029: transferring control: isql
     22029: 
     22029: find library=libnss_files.so.2 [0]; searching
     22029:  search path=/usr/lib64/tls:/usr/lib64      (system search path)
     22029:   trying file=/usr/lib64/tls/libnss_files.so.2
     22029:   trying file=/usr/lib64/libnss_files.so.2
     22029:  search cache=/etc/ld.so.cache
     22029:   trying file=/lib64/libnss_files.so.2
     22029: 
     22029: 
     22029: calling init: /lib64/libnss_files.so.2
     22029: 
     22029: 
     22029: calling init: /usr/lib64/gconv/UTF-16.so
     22029: 
     22029: find library=libssl.so.10 [0]; searching
     22029:  search path=/usr/lib64/tls:/usr/lib64      (system search path)
     22029:   trying file=/usr/lib64/tls/libssl.so.10
     22029:   trying file=/usr/lib64/libssl.so.10
     22029: 
     22029: find library=libpq.so.5 [0]; searching
     22029:  search path=/usr/lib64/tls:/usr/lib64      (system search path)
     22029:   trying file=/usr/lib64/tls/libpq.so.5
     22029:   trying file=/usr/lib64/libpq.so.5
     22029: 
     22029: find library=libodbcinst.so.2 [0]; searching
     22029:  search path=/usr/lib64/tls:/usr/lib64      (system search path)
     22029:   trying file=/usr/lib64/tls/libodbcinst.so.2
     22029:   trying file=/usr/lib64/libodbcinst.so.2
     22029:  search cache=/etc/ld.so.cache
     22029:  search path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/usr/lib64/tls:/usr/lib64        (system search path)
     22029:   trying file=/lib64/tls/x86_64/libodbcinst.so.2
     22029:   trying file=/lib64/tls/libodbcinst.so.2
     22029:   trying file=/lib64/x86_64/libodbcinst.so.2
     22029:   trying file=/lib64/libodbcinst.so.2
     22029:   trying file=/usr/lib64/tls/libodbcinst.so.2
     22029:   trying file=/usr/lib64/libodbcinst.so.2
     22029: 
[01000][unixODBC][Driver Manager]Can't open lib '/usr/lib64/psqlodbc.so' : file not found
[ISQL]ERROR: Could not SQLConnect
     22029: 
     22029: calling fini: isql [0]
     22029: 
     22029: 
     22029: calling fini: /usr/lib64/libodbc.so.1 [0]
     22029: 
     22029: 
     22029: calling fini: /lib64/libdl.so.2 [0]
     22029: 
     22029: 
     22029: calling fini: /lib64/libpthread.so.0 [0]
     22029: 
     22029: 
     22029: calling fini: /lib64/libnss_files.so.2 [0]
     22029: 
     22029: 
     22029: calling fini: /usr/lib64/gconv/UTF-16.so [0]
     22029: 
     22029: 
     22029: calling fini: /lib64/libc.so.6 [0]
     22029: 
[root@localhost bin]# 

约翰格林建议:

[root@localhost bin]# ldd /usr/bin/isql 
    linux-vdso.so.1 =>  (0x00007fff12cf9000)
    libodbc.so.1 => /usr/lib64/libodbc.so.1 (0x0000003ef0800000)
    libdl.so.2 => /lib64/libdl.so.2 (0x0000003d6fe00000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003d70200000)
    libc.so.6 => /lib64/libc.so.6 (0x0000003d6fa00000)
    /lib64/ld-linux-x86-64.so.2 (0x0000003d6f600000)
4

2 回答 2

3

找出为什么找不到库文件的一些非常酷的技巧。

  1. 您的 isql 在哪里寻找库?:
    ldd <insert-path>/isql

  2. 如果没有“未找到”... 可以找到,请尝试按照代码查看未打开的位置:
    strace -f isql -v STUDENT dsname pwd12345

    并寻找像这样的开放失败(最常见的符号链接失败):

    open("/usr/lib64/psqlodbc.so", O_RDONLY) = -1 ENOENT (No such file or directory)

  3. 否则,检查 /etc/ld.so.conf 或 /etc/ld.so.conf.d/ 是否缺少诸如

    /usr/lib64


我想在 /etc/ld.so.conf.d/local.conf 中保留以下内容
/usr/local/lib64
/usr/local/lib
/usr/lib64
/usr/lib

如果对 /etc/ld.so.conf* 进行了任何更改,请确保重新加载库系统缓存(再次):
ldconfig -v

于 2012-12-12T00:25:03.063 回答
1

我跑了:rpm -q unixODBC检查是否仍然安装了 unixODBC,不幸的是发现它不是。在没有明确干预的情况下安装 SQL Server 驱动程序后,unixODBC 驱动程序不知何故被卸载。我安装了yum install unixODBC.x86_64. 第一次,我让 SQL Server 驱动程序、PostgreSQL 驱动程序和其他驱动程序从同一台机器(RHEL 6)连接到它们各自的数据源。

于 2012-12-13T17:46:55.507 回答