psql: error while loading shared libraries: libpq.so.rh-postgresql95-5: cannot open shared object file: No such file or directory
Well heck:
-bash-4.2$ psql
psql: error while loading shared libraries: libpq.so.rh-postgresql95-5: cannot open shared object file: No such file or directory
-bash-4.2$
So let's see what's going on:
[root@ovirt01 ~]# find / -iname libpq.so*
/usr/lib64/libpq.so.5
/usr/lib64/libpq.so.5.5
/opt/rh/rh-postgresql95/root/usr/lib64/libpq.so.rh-postgresql95-5
/opt/rh/rh-postgresql95/root/usr/lib64/libpq.so.rh-postgresql95-5.8
[root@ovirt01 ~]#
So we can see it's in the lib64 path. And within the root postgres folder, we see that usr/lib is empty that lib points too:
[root@ovirt01 root]# find / -iname psql
/opt/rh/rh-postgresql95/root/usr/bin/psql
[root@ovirt01 root]# pwd
/opt/rh/rh-postgresql95/root
[root@ovirt01 root]# ls -altrid lib
201829110 lrwxrwxrwx. 1 root root 7 Feb 12 11:08 lib -> usr/lib
[root@ovirt01 root]# pwd
/opt/rh/rh-postgresql95/root
[root@ovirt01 root]# ls -altri usr/lib/
total 4
134420487 dr-xr-xr-x. 2 root root 6 Feb 16 2016 .
67638534 drwxr-xr-x. 13 root root 4096 Feb 12 11:08 ..
[root@ovirt01 root]#
So obviously, nothing that uses usr/lib/ will get anything useful out of it. But the following path under the same folder above has lot's of usefull things:
[root@ovirt01 root]# ls -altrid lib64
201829111 lrwxrwxrwx. 1 root root 9 Feb 12 11:08 lib64 -> usr/lib64
[root@ovirt01 root]#
Since the lib folder doesn't have anything useful in it, a simple solution is to link lib to usr/lib64 instead. So let's do that. Sure enough:
201829110 lrwxrwxrwx. 1 root root 9 Apr 15 00:56 lib -> usr/lib64
And here we go again:
-bash-4.2$ strace psql
execve("/opt/rh/rh-postgresql95/root/usr/bin/psql", [“psql”], [/* 21 vars */]) = 0
brk(NULL) = 0x17b5000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa7a1ff5000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=42118, …}) = 0
mmap(NULL, 42118, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fa7a1fea000
close(3) = 0
open("/lib64/tls/x86_64/libpq.so.rh-postgresql95-5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib64/tls/x86_64", 0x7ffcdfe3c4a0) = -1 ENOENT (No such file or directory)
open("/lib64/tls/libpq.so.rh-postgresql95-5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib64/tls", {st_mode=S_IFDIR|0555, st_size=6, …}) = 0
open("/lib64/x86_64/libpq.so.rh-postgresql95-5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib64/x86_64", 0x7ffcdfe3c4a0) = -1 ENOENT (No such file or directory)
open("/lib64/libpq.so.rh-postgresql95-5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib64", {st_mode=S_IFDIR|0555, st_size=40960, …}) = 0
open("/usr/lib64/tls/x86_64/libpq.so.rh-postgresql95-5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib64/tls/x86_64", 0x7ffcdfe3c4a0) = -1 ENOENT (No such file or directory)
open("/usr/lib64/tls/libpq.so.rh-postgresql95-5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib64/tls", {st_mode=S_IFDIR|0555, st_size=6, …}) = 0
open("/usr/lib64/x86_64/libpq.so.rh-postgresql95-5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib64/x86_64", 0x7ffcdfe3c4a0) = -1 ENOENT (No such file or directory)
open("/usr/lib64/libpq.so.rh-postgresql95-5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib64", {st_mode=S_IFDIR|0555, st_size=40960, …}) = 0
writev(2, [{“psql”, 4}, {“: “, 2}, {“error while loading shared libra”…, 36}, {“: “, 2}, {“libpq.so.rh-postgresql95-5”, 26}, {“: “, 2}, {“cannot open shared object file”, 30}, {“: “, 2}, {“No such file or directory”, 25}, {“\n”, 1}], 10psql: error while loading shared libraries: libpq.so.rh-postgresql95-5: cannot open shared object file: No such file or directory
) = 130
exit_group(127) = ?
+++ exited with 127 +++
-bash-4.2$
So we need to add it to the default library path. Easy enough:
[root@ovirt01 ld.so.conf.d]#
[root@ovirt01 ld.so.conf.d]# cat postgres-x86_64.conf
/opt/rh/rh-postgresql95/root/lib
/opt/rh/rh-postgresql95/root/lib64
[root@ovirt01 ld.so.conf.d]# ldconfig
[root@ovirt01 ld.so.conf.d]# strings /etc/ld.so.cache |grep -Ei postgresql95
libpq.so.rh-postgresql95-5
/opt/rh/rh-postgresql95/root/lib64/libpq.so.rh-postgresql95-5
libpgtypes.so.rh-postgresql95-3
/opt/rh/rh-postgresql95/root/lib64/libpgtypes.so.rh-postgresql95-3
libecpg_compat.so.rh-postgresql95-3
/opt/rh/rh-postgresql95/root/lib64/libecpg_compat.so.rh-postgresql95-3
libecpg.so.rh-postgresql95-6
/opt/rh/rh-postgresql95/root/lib64/libecpg.so.rh-postgresql95-6
[root@ovirt01 ld.so.conf.d]#
And let's try again. And sure enough, we have a winner:
-bash-4.2$
-bash-4.2$ psql
psql (9.5.9)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
———————-+———————-+———-+————-+————-+———————–
engine | engine | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
ovirt_engine_history | ovirt_engine_history | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(5 rows)
postgres=#
Cheers,
TK