Error when installing postgis extension to postgresql database

12,091

Solution 1

It's been a while since I've solved this problem, and almost forgot this question i asked before. I found still getting upvote from guys might having this issue.

So basically, I found this issue might be happening because of the postgis plugin which i installed by sudo apt-get install postgis wasn't properly installed into the position which PostgreSQl database preferred. Im really not a linux guy to make sure of this. But seems every time I try installing postgis this way, this error will just show up.

So the cure for this issue is, download, build and install the postgis from the source code.

I followed this wiki. hope its helpful to someone.

Solution 2

It's way easier to just use a sensible Linux distro like Ubuntu, Debian, Fedora, RHEL, etc. You can then just use http://apt.postgresql.org/ or http://yum.postgresql.org/ as appropriate and get all this stuff pre-built and easy to install. Amazon's PostgreSQL packaging is unsafe bordering on incompetent and should be avoided.

I suspect the immediate problem is /usr/local/lib not being on LD_LIBRARY_PATH and/or in /etc/ld.so.conf, so when PostgreSQL dlopen(...)'s postgis-2.0.so it tries to resolve libgeos_c.so.1 and fails to find it.

Another possibility would be if /usr/local/lib/libgeos_c.so.1 is a symbolic link to a file that does not exist.

Solution 3

If you installed the postgis by source, maybe you forgot to run sudo ldconfig. Running this worked for me!

Thank you Yunwei.W, i saw this in the wiki you shared!

Solution 4

I seem to have faced similar problem accidentally. On Cent OS 6 I installed binary PostgreSQL 9.3 from PostgreSQL YUM repository. Compiled GDAL library version 1.11.0 from official stable tar. Then compiled PostGIS 2.1.4dev from original PostGIS repository. Unit tests showed, that libgdal was not loaded because it was not found. Error message looked similar to one in the original question. @Craig gave idea of using strace. The point is in attaching strace specifically to the process that was created just after the connection of client to DBMS. After you attach strace to DBMS, make client ask server to CREATE EXTENSION postgis on current database and see the output of strace. In my case it gave this:

open("/lib64/tls/x86_64/libgdal.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/lib64/tls/x86_64", 0x7fffefb20290) = -1 ENOENT (No such file or directory)
open("/lib64/tls/libgdal.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/lib64/tls", {st_mode=S_IFDIR|0555, st_size=4096, ...}) = 0
open("/lib64/x86_64/libgdal.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/lib64/x86_64", 0x7fffefb20290)   = -1 ENOENT (No such file or directory)
open("/lib64/libgdal.so.1", O_RDONLY)   = -1 ENOENT (No such file or directory)
stat("/lib64", {st_mode=S_IFDIR|0555, st_size=12288, ...}) = 0
open("/usr/lib64/tls/x86_64/libgdal.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/lib64/tls/x86_64", 0x7fffefb20290) = -1 ENOENT (No such file or directory)
open("/usr/lib64/tls/libgdal.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/lib64/tls", {st_mode=S_IFDIR|0555, st_size=4096, ...}) = 0
open("/usr/lib64/x86_64/libgdal.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/lib64/x86_64", 0x7fffefb20290) = -1 ENOENT (No such file or directory)
open("/usr/lib64/libgdal.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/lib64", {st_mode=S_IFDIR|0555, st_size=12288, ...}) = 0

It shows which specific paths DBMS tries to find library in. In my situation library lies in /usr/local/lib/libgdal.so.1.18.0 with symbolic links for broader version use in same directory. My solution was to put symbolic links to these files into /usr/lib64 directory.

Solution 5

/etc/ld.so.conf.d/ should contain paths for postgresql libs dir and geos libs.

Example for postgresql 9.6.6 on Amazon linux:

-create postgresql-pgdg-libs.conf with "/usr/lib64/pgsql96/" path
-create libgeos.conf with "/usr/local/lib/" path 
-check the geos library present in 
 ldconfig -v | grep geos
- if yes compile the extension
sudo -u postgres -- psql -c "CREATE EXTENSION postgis;"
Share:
12,091
Yunwei.W
Author by

Yunwei.W

80%Rails, 80%Ruby, 20%Javascript, 0.5% PHP and others Update 2021 80%Javascript, 15%Ruby, 5% Python and others

Updated on June 29, 2022

Comments

  • Yunwei.W
    Yunwei.W almost 2 years

    Im having problem installing postgis to an existing database. but getting error like this:

    ERROR:  could not load library "/usr/local/pgsql/lib/postgis-2.0.so": libgeos_c.so.1: cannot open shared object file: No such file or directory
    

    the postgis-2.0.so is in /usr/local/pgsql/lib/postgis-2.0.so no problem. the libgeos_c.so.1 is installed in /usr/local/lib.

    So, what is the problem here?

    Any help would be appreciated.

    Thanks.

    BTW, I installed all these followed by this tutorial:

    http://www.codingsteps.com/installing-and-configuring-postgresql-in-amazon-linux-ami/

    update

    $ ldd /usr/local/lib/libgeos_c.so.1
    linux-vdso.so.1 =>  (0x00007fff6f55b000)
    libgeos-3.3.7.so => /usr/local/lib/libgeos-3.3.7.so (0x00007f53700d9000)
    libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f536fdd0000)
    libm.so.6 => /lib64/libm.so.6 (0x00007f536fb4c000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f536f7c0000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f536f5ab000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f537068d000)