markdibley has asked for the wisdom of the Perl Monks concerning the following question:

Hi. Hope someone can help me with this unusual (for me anyway) error message. I have been given a RHEL 6 server to install some code on. The code does a bunch of database queries and some number crunching on the data. However, it fails to run with the following error message.
install_driver(Pg) failed: Can't load '/usr/lib64/perl5/vendor_perl/au +to/DBD/Pg/Pg.so' for module DBD::Pg: libpq.so.5: cannot open shared o +bject file: No such file or directory at /usr/lib64/perl5/DynaLoader. +pm line 190. at (eval 58) line 3. Compilation failed in require at (eval 58) line 3. Perhaps a required shared library or dll isn't installed where expecte +d at /usr/local/ztest/ztest_home/src/perl/lib/ZTEST/DB.pm line 123.

The shared object is definitely where it is meant to be and with the correct permissions. I checked perl -V and got

Platform: osname=linux, osvers=2.6.32-754.12.1.el6.x86_64, archname=x86_64-l +inux-thread-multi uname='linux x86-vm-22.build.eng.bos.redhat.com 2.6.32-754.12.1.el +6.x86_64 #1 smp thu mar 7 22:07:44 est 2019 x86_64 x86_64 x86_64 gnul +inux ' config_args='-des -Doptimize=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOU +RCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 + -grecord-gcc-switches -m64 -mtune=generic -Dccdlflags=-Wl,--enable +-new-dtags -Dlddlflags=-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOUR +CE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 +-grecord-gcc-switches -m64 -mtune=generic -Wl,-z,relro -DDEBUGGING +=-g -Dversion=5.16.3 -Dmyhostname=localhost -Dperladmin=root@localhos +t -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dprefix=/usr -Dvendorprefix=/usr -D +siteprefix=/usr/local -Dsitelib=/usr/local/share/perl5 -Dsitearch=/us +r/local/lib64/perl5 -Dprivlib=/usr/share/perl5 -Dvendorlib=/usr/share +/perl5/vendor_perl -Darchlib=/usr/lib64/perl5 -Dvendorarch=/usr/lib64 +/perl5/vendor_perl -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr +/local/lib64 /lib64 /usr/lib64 -Duseshrplib -Dusethreads -Duseithread +s -Dusedtrace=/usr/bin/dtrace -Duselargefiles -Dd_semctl_semun -Di_db + -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -D +installusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/le +ss -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_ +r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endserven +t_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/bin -Dusesitecustom +ize' hint=recommended, useposix=true, d_sigaction=define useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=und +ef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing + -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_ +FILE_OFFSET_BITS=64', optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions +-fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switc +hes -m64 -mtune=generic', cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -f +stack-protector -I/usr/local/include' ccversion='', gccversion='4.8.5 20150623 (Red Hat 4.8.5-44)', gcco +sandvers='' intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +6 ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='gcc', ldflags =' -fstack-protector' libpth=/usr/local/lib64 /lib64 /usr/lib64 libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread +-lc -lgdbm_compat perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc libc=, so=so, useshrplib=true, libperl=libperl.so gnulibc_version='2.17' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,--en +able-new-dtags -Wl,-rpath,/usr/lib64/perl5/CORE' cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall -Wp,-D_F +ORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buf +fer-size=4 -grecord-gcc-switches -m64 -mtune=generic Wl,-z,relro ' Characteristics of this binary (from libperl): Compile-time options: HAS_TIMES MULTIPLICITY PERLIO_LAYERS PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP PERL_PRESERVE_IVUV USE_64_BIT +_ALL USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF USE_REENTRANT_API USE_SITECUSTOMIZE Locally applied patches: Fedora Patch1: Removes date check, Fedora/RHEL specific Fedora Patch3: support for libdir64 Fedora Patch4: use libresolv instead of libbind Fedora Patch5: USE_MM_LD_RUN_PATH Fedora Patch6: Skip hostname tests, due to builders not + being network capable Fedora Patch7: Dont run one io test due to random build +er failures Fedora Patch9: Fix find2perl to translate ? glob proper +ly (RT#113054) Fedora Patch10: Fix broken atof (RT#109318) Fedora Patch13: Clear $@ before "do" I/O error (RT#1137 +30) Fedora Patch14: Do not truncate syscall() return value +to 32 bits (RT#113980) Fedora Patch15: Override the Pod::Simple::parse_file (C +PANRT#77530) Fedora Patch16: Do not leak with attribute on my variab +le (RT#114764) Fedora Patch17: Allow operator after numeric keyword ar +gument (RT#105924) Fedora Patch18: Extend stack in File::Glob::glob, (RT#1 +14984) Fedora Patch19: Do not crash when vivifying $| Fedora Patch20: Fix misparsing of maketext strings (CVE +-2012-6329) Fedora Patch21: Add NAME headings to CPAN modules (CPAN +RT#73396) Fedora Patch22: Fix leaking tied hashes (RT#107000) [1] Fedora Patch23: Fix leaking tied hashes (RT#107000) [2] Fedora Patch24: Fix leaking tied hashes (RT#107000) [3] Fedora Patch25: Fix dead lock in PerlIO after fork from + thread (RT#106212) Fedora Patch26: Make regexp safe in a signal handler (R +T#114878) Fedora Patch27: Update h2ph(1) documentation (RT#117647 +) Fedora Patch28: Update pod2html(1) documentation (RT#11 +7623) Fedora Patch29: Document Math::BigInt::CalcEmu requires + Math::BigInt (CPAN RT#85015) RHEL Patch30: Use stronger algorithm needed for FIPS in + t/op/crypt.t (RT#121591) RHEL Patch31: Make *DBM_File desctructors thread-safe ( +RT#61912) RHEL Patch32: Use stronger algorithm needed for FIPS in + t/op/taint.t (RT#123338) RHEL Patch33: Remove CPU-speed-sensitive test in Benchm +ark test RHEL Patch34: Make File::Glob work with threads again RHEL Patch35: Fix CRLF conversion in ASCII FTP upload ( +CPAN RT#41642) RHEL Patch36: Do not leak the temp utf8 copy of namepv +(CPAN RT#123786) RHEL Patch37: Fix duplicating PerlIO::encoding when spa +wning threads (RT#31923) RHEL Patch38: Add SSL support to Net::SMTP (CPAN RT#938 +23) [1] RHEL Patch39: Add SSL support to Net::SMTP (CPAN RT#938 +23) [2] RHEL Patch40: Add SSL support to Net::SMTP (CPAN RT#938 +23) [3] RHEL Patch41: Add SSL support to Net::SMTP (CPAN RT#938 +23) [4] RHEL Patch42: Do not overload ".." in Math::BigInt (CPA +N RT#80182) RHEL Patch43: Fix CVE-2018-18311 Integer overflow leadi +ng to buffer overflow RHEL Patch44: Fix a spurious timeout in Net::FTP::close + (CPAN RT#18504) RHEL Patch45: Fix day of year parsing (CPAN RT#88211) RHEL Patch47: Fix CVE-2020-12723 (GH#16947) RHEL Patch48: Fix CVE-2020-10543 RHEL Patch49: Fix CVE-2020-10878 Built under linux Compiled at Jan 15 2021 09:24:16 @INC: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5
The /usr/lib64/perl5/vendor_perl directory is listed. But PERL5LIB is not exported. When I did which perl it says it is using /bin/perl I am at a bit of a loss as to why this isn't working. What am I missing? Or what do I need to do to connect perl up to the shared object?

Replies are listed 'Best First'.
Re: Cannot load Postgres Shared Object
by Fletch (Bishop) on Oct 25, 2022 at 19:12 UTC

    ld.so is complaining it can't find libpq.so.5 when it's loading the Pg perl module. You need to make sure you have whatever the OS' postgresql package which provides THAT is installed. You can check that it's found correctly by running ldd on the perl module's .so file.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Postgres was compiled/installed from source files rather than yum. And that installation completed successfully. The libpq.so.5 file was present for the local installation, but the same file was missing file from /usr/lib64. In past server setups that /usr/lib64 version is present.

      I don't know if the yum install of perl(DBI) or perl(DBD::Pg) has installed it in the past (or another package that isn't immediately obvious), but following your advice I found that the following yum install provided the missing files and fixed the problem

      sudo yum install -y postgresql-libs

      Thanks for your help!

        libpq is the C application programmer's interface to PostgreSQL. libpq + is a set of library functions that allow client programs to pass que +ries to the PostgreSQL backend server and to receive the results of t +hese queries. libpq is also the underlying engine for several other PostgreSQL appli +cation interfaces, including those written for C++, Perl, Python, Tcl + and ECPG. So some aspects of libpq's behavior will be important to y +ou if you use one of those packages (from https://www.postgresql.org/ +docs/current/libpq.htm)

        If you installed from source, then it may be that it does not install libpq by default although it's contained in the source, perhaps for doing some testing. Check the makefile targets, perhaps there is one to install libpq.

        For installing Pg with your package manager, it could be that libpq is considered optional (this is what I sensed from cited doc) and therefore it is not bundled with the standard Pg package. In fedora there is a separate libpq package available. And you found the package for your system.

Re: Cannot load Postgres Shared Object
by NetWallah (Canon) on Oct 25, 2022 at 19:30 UTC
    This article on StackOverflow has some potentially useful answers to this specific issue for RHEL.

                    "These opinions are my own, though for a small fee they be yours too."

      That did indeed help. Thank you!