Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load package postgresql-libpq-0.9.0.0 [Fixed] #18

Open
rustyjam opened this issue May 6, 2014 · 10 comments
Open

Unable to load package postgresql-libpq-0.9.0.0 [Fixed] #18

rustyjam opened this issue May 6, 2014 · 10 comments

Comments

@rustyjam
Copy link

rustyjam commented May 6, 2014

Hi Leon, I was able to successfully install the package "postgresql-libpq-0.9.0.0" on GNU / Linux (Centos 6.5), however, the following runtime error occurs:
Unable to load packagepostgresql-libpq-0.9.0.0

$ ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> import Database.PostgreSQL.LibPQ
Prelude Database.PostgreSQL.LibPQ> connectdb undefined
Loading package array-0.4.0.1 ... linking ... done.
Loading package deepseq-1.3.0.1 ... linking ... done.
Loading package bytestring-0.10.0.2 ... linking ... done.
Loading package postgresql-libpq-0.9.0.0 ... linking ... : /home/haskell/.cabal/lib/postgresql-libpq-0.9.0.0/ghc-7.6.3/HSpostgresql-libpq-0.9.0.0.o: unknown symbol PQescapeIdentifier' ghc: unable to load packagepostgresql-libpq-0.9.0.0'
Prelude Database.PostgreSQL.LibPQ>

@rustyjam rustyjam changed the title Error Loading package postgresql-libpq-0.9.0.0 Unable to load package postgresql-libpq-0.9.0.0 May 6, 2014
@rustyjam
Copy link
Author

rustyjam commented May 6, 2014

Fixed: In my case I had to uninstall version 8.4 client postgres and install version 9.3 and it worked perfectly. The components were reinstalled:
postgresql93, postgresql93-devel postgresql93-libs, postgresql93-odb.
Ref: http://www.postgresql.org/message-id/435F180D.3050305@familyhealth.com.au

@rustyjam rustyjam changed the title Unable to load package postgresql-libpq-0.9.0.0 Unable to load package postgresql-libpq-0.9.0.0 [Fixed] May 6, 2014
@lpsmith
Copy link
Owner

lpsmith commented May 7, 2014

Yeah, postgresql-libpq version 0.9 introduced the requirement for libpq 9.0 or later. The postgresql community is dropping support for 8.4 this July, and the use case for PQescapeIdentifier is pretty compelling.

This is something that I could check in Setup.hs, come to think of it. Am I correct in understanding that you did not have any of the 9.* client libraries installed when you compiled it?

@lpsmith
Copy link
Owner

lpsmith commented May 7, 2014

Also, did you recompile postgresql-libpq when you installed the new client library? (You shouldn't have to, but I am curious for other reasons.)

@rustyjam
Copy link
Author

rustyjam commented May 7, 2014

Hello again, now with more time I summarize my experience installing postgresql- libpq and other packages that depend on it :

Note: This experience takes place on Centos 6.5 operating system with a client installation Postgresql 8.4:

1 - The hackage postgresql- libpq version 0.9.0.0 can be installed without difficulty. It requires a higher version of postgresql 9 but this is no impediment to a successful installation.

2 - Other dependent packages fail to install, eg: postgresql-simple, haskelldb and persistent-postgresql until the problem of "PQescapeIdentifier" is resolved

3 - El módulo "Database.PostgreSQL.LibPQ" puede ser cargado sin dificultad en una consola de GHC, sin embargo, la función "connectdb" falla debido al caso de uso relacionado con "PQescapeIdentifier". Este incidente está debidamente documentado en el sitio oficial de Postgresql)

4 - The above problem is solved by simply updating the postgres client to a version higher than 9.0 .

5 - Once the correct prostgres client version is installed you can run the " Database.PostgreSQL.LibPQ " module without difficulty, without having to recompile the package back to postgresql- libpq.

@jprider63
Copy link

I've run into this problem again on a new machine, but I have PostgreSQL 9.2.8 installed. Is there someway I specify which library to link to?

Here are some of my environment variables:

LIBRARY_PATH=/opt/rh/postgresql92/root/usr/lib64
LD_LIBRARY_PATH=/opt/rh/postgresql92/root/usr/lib64:/usr/lib64/openssl/engines

I've tried the following as well, but I still had the same problem:

cabal install postgresql-libpq --extra-include-dirs=/opt/rh/postgresql92/root/usr/include --extra-lib-dirs=/opt/rh/postgresql92/root/usr/lib64

@lpsmith
Copy link
Owner

lpsmith commented Jan 5, 2015

The current Setup.hs sets --extra-include-dirs and --extra-lib-dirs based on the first pg_config that is found in your path. Perhaps these shouldn't be overwritten... but...

I probably ought to take the time to understand the dynamic link process a bit better.

@jprider63
Copy link

That's odd then. It looks like pg_config is pointing to the correct locations. Is there a way I can tell what is actually being linked against?

$ pg_config
BINDIR = /opt/rh/postgresql92/root/usr/bin
DOCDIR = /opt/rh/postgresql92/root/usr/share/doc/pgsql
HTMLDIR = /opt/rh/postgresql92/root/usr/share/doc/pgsql
INCLUDEDIR = /opt/rh/postgresql92/root/usr/include
PKGINCLUDEDIR = /opt/rh/postgresql92/root/usr/include/pgsql
INCLUDEDIR-SERVER = /opt/rh/postgresql92/root/usr/include/pgsql/server
LIBDIR = /opt/rh/postgresql92/root/usr/lib64
PKGLIBDIR = /opt/rh/postgresql92/root/usr/lib64/pgsql
LOCALEDIR = /opt/rh/postgresql92/root/usr/share/locale
MANDIR = /opt/rh/postgresql92/root/usr/share/man
SHAREDIR = /opt/rh/postgresql92/root/usr/share/pgsql
SYSCONFDIR = /opt/rh/postgresql92/root/etc
PGXS = /opt/rh/postgresql92/root/usr/lib64/pgsql/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/opt/rh/postgresql92/root/usr' '--exec-prefix=/opt/rh/postgresql92/root/usr' '--bindir=/opt/rh/postgresql92/root/usr/bin' '--sbindir=/opt/rh/postgresql92/root/usr/sbin' '--sysconfdir=/opt/rh/postgresql92/root/etc' '--datadir=/opt/rh/postgresql92/root/usr/share' '--includedir=/opt/rh/postgresql92/root/usr/include' '--libdir=/opt/rh/postgresql92/root/usr/lib64' '--libexecdir=/opt/rh/postgresql92/root/usr/libexec' '--localstatedir=/opt/rh/postgresql92/root/var' '--sharedstatedir=/opt/rh/postgresql92/root/usr/com' '--mandir=/opt/rh/postgresql92/root/usr/share/man' '--infodir=/opt/rh/postgresql92/root/usr/share/info' '--disable-rpath' '--with-perl' '--with-tcl' '--with-tclconfig=/usr/lib64' '--with-python' '--with-ldap' '--with-openssl' '--with-pam' '--with-krb5' '--with-gssapi' '--with-ossp-uuid' '--with-libxml' '--with-libxslt' '--enable-nls' '--enable-dtrace' '--with-system-tzdata=/usr/share/zoneinfo' '--datadir=/opt/rh/postgresql92/root/usr/share/pgsql' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' 'target_alias=x86_64-redhat-linux-gnu' 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DLINUX_OOM_SCORE_ADJ=0'
CC = gcc
CPPFLAGS = -D_GNU_SOURCE -I/usr/include/libxml2
CFLAGS = -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DLINUX_OOM_SCORE_ADJ=0 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv
CFLAGS_SL = -fpic
LDFLAGS = -Wl,--as-needed
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgport -lxslt -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lcrypt -ldl -lm
VERSION = PostgreSQL 9.2.8

@lpsmith
Copy link
Owner

lpsmith commented Jan 7, 2015

My suggestion for finding out what this is being linked against at runtime is to strace it. Perhaps there is a better method... but that's the one I know about. (Alternatively, you can look at /proc/$PID/maps, but that only works if the library has already been successfully linked)

I also saw your questions on #haskell but you ducked out of the channel before I replied. I've found that with GHC 7.8, I need to compile postgresql-libpq with --enable-shared, otherwise GHCi and Template Haskell doesn't work. IIRC, that should fix the "not a dynamic executable" error, unless I'm misremembering the error message that that fixes.

@jprider63
Copy link

Sorry, I had to run last night.

Ok, here's an strace of ghci loading Database.PostgreSQL.LibPQ. It looks like it is linking against 8.4:

$ ls -la /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libpq.so
lrwxrwxrwx 1 root root 12 Feb 26  2014 /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libpq.so -> libpq.so.5.2

I need it to link against 9.2:

$ ls -la /opt/rh/postgresql92/root/usr/lib64/libpq.so.postgresql92-5
lrwxrwxrwx 1 root root 25 Jun  5  2014 /opt/rh/postgresql92/root/usr/lib64/libpq.so.postgresql92-5 -> libpq.so.postgresql92-5.5

It's weird because it looks like other libraries are loading from 9.2. Unfortunately, I can't uninstall 8.4 since this is a managed system.

@jprider63
Copy link

Ok, I finally figured out the problem. The linker is looking for a file called libpq.so, but the installed file is libpq.so.postgresql92-5.5. Since I don't have root, I created a symlink in ~/lib that points to the library:

$ ls -la ~/lib
lrwxrwxrwx  1 nobody jprider   61 Jan 12 10:28 libpq.so -> /opt/rh/postgresql92/root/usr/lib64/libpq.so.postgresql92-5.5

Then when you install, use --extra-lib-dirs to specify ~/lib:

cabal install postgresql-libpq --extra-lib-dirs=/mc2homes/jprider/lib/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants