Perl/Postgresql: 未编译 SSL 支持时 sslmode 值 "require" 无效

Perl/Postgresql: sslmode value "require" invalid when SSL support is not compiled

我试图在 SLES12 机器上使用 Perl 5.26.1 连接到 Postgresql 12.1 数据库实例,但 运行 遇到错误。我的测试脚本很简单。

#!/usr/pkgs/perl/5.26.1/bin/perl

use DBI;
my $dbname = "XXX";  
my $host = "XXX";  
my $port = XXX;  
my $username = "XXX";  
my $password = "XXX";

my $dbh = DBI -> connect("dbi:Pg:dbname=$dbname;sslmode=require;host=$host;port=$port",  
                            $username,
                            $password,
                            {AutoCommit => 0, RaiseError => 1}
                         ) or die $DBI::errstr;

当我运行这个脚本时,我得到以下错误:sslmode value "require" invalid when SSL support is not compiled in at...

我已将 LD_LIBRARY_PATH 设置为指向 libpq 库(从源 postgresql-13.3 构建)的本地版本。我在 --open-ssl 支持下构建了这个库。我用 pg_config --configure.

确认了这一点
$ ./bin/pg_config --configure
 '--prefix' '/myworkarea/tmp/local' '--with-perl' '--with-python' '--with-tcl' '--with-openssl' '--with-ldap' '--with-pam' '--with-libxml' '--with-libxslt'

我可以使用 pgAdmin 毫无问题地连接到数据库。我确认它支持通过 DBD:Pg.

连接到 Postgres
$ perl -MDBI -e 'DBI->installed_versions'
  Perl            : 5.026001    (x86_64-linux)
  OS              : linux       (4.4.49-92.14-default)
  DBI             : 1.639
  DBD::mysql      : 4.043
  DBD::Sybase     : 1.16
  DBD::Sponge     : 12.010003
  DBD::SQLite     : 1.54
  DBD::Proxy      : 0.2004
  DBD::Pg         : 3.7.4
  DBD::Oracle     : 1.80
  DBD::ODBC       : 1.56
  DBD::Multiplex  : 2.11
  DBD::Mock       : 1.45
  DBD::Mem        : 0.001
  DBD::LDAP       : 0.22
  DBD::Gofer      : 0.015327
  DBD::File       : 0.44
  DBD::ExampleP   : 12.014311
  DBD::DBM        : 0.08
  DBD::CSV        : 0.49

但是我查看 Pg.so 来查找依赖项,但它似乎仍然指向系统安装文件而不是我的版本。我该如何解决这个问题?

$ ldd /usr/pkgs/perl/5.26.1/lib64/site_perl/x86_64-linux/auto/DBD/Pg/Pg.so
        linux-vdso.so.1 (0x00007ffff7ffa000)
        libpq.so.5 => /usr/pkgs/postgresql/9.5.0/lib/libpq.so.5 (0x00007ffff797b000)   <-- Not picking up my setting from LD_LIBRARY_PATH
        libm.so.6 => /lib64/libm.so.6 (0x00007ffff767e000)
        libc.so.6 => /lib64/libc.so.6 (0x00007ffff72d9000)
        libpthread.so.0 => /lib64/noelision/libpthread.so.0 (0x00007ffff70bc000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ffff7ddb000)

使用 DBD::Pg link 编辑的 PostgreSQL 客户端共享库 (libpq) 是在没有 SSL 支持的情况下构建的。那行不通的。您必须使用内置 SSL 支持的 libpq。

这需要做两件事:

  1. 使用 --with-openssl 开关配置 PostgreSQL。
  2. 通过设置 POSTGRES_LIBPOSTGRES_HOME 环境变量,使用 1) 中的库将 DBD:Pg 模块编译为 link。请参阅有关安装的自述文件部分。