7

I am unable to create the PostGIS extension on new databases in Ubuntu 14.04:

$  psql pg_testing -c "create extension postgis"
ERROR:  could not load library "/usr/lib/postgresql/9.3/lib/postgis-2.1.so": /usr/lib/liblwgeom-2.1.3.so: undefined symbol: GEOSDelaunayTriangulation

All the software was installed from the Postgres repositories:

$ dpkg -l | grep postgres
ii  libpostgresql-jdbc-java                               9.2-1002-1                                          all          Java database (JDBC) driver for PostgreSQL
ii  pgdg-keyring                                          2013.2                                              all          keyring for apt.postgresql.org
ii  postgresql                                            9.3+154.pgdg14.04+1                                 all          object-relational SQL database (supported version)
ii  postgresql-9.3                                        9.3.4-1.pgdg14.04+1                                 amd64        object-relational SQL database, version 9.3 server
ii  postgresql-9.3-dbg                                    9.3.4-1.pgdg14.04+1                                 amd64        debug symbols for postgresql-9.3
ii  postgresql-9.3-postgis-2.1                            2.1.3+dfsg-3.pgdg14.04+2                            amd64        Geographic objects support for PostgreSQL 9.3
ii  postgresql-9.3-postgis-scripts                        2.1.3+dfsg-3.pgdg14.04+2                            all          Geographic objects support for PostgreSQL 9.3 -- scripts
ii  postgresql-client                                     9.3+154.pgdg14.04+1                                 all          front-end programs for PostgreSQL (supported version)
ii  postgresql-client-9.1                                 9.1.13-1.pgdg14.04+1                                amd64        front-end programs for PostgreSQL 9.1
ii  postgresql-client-9.3                                 9.3.4-1.pgdg14.04+1                                 amd64        front-end programs for PostgreSQL 9.3
ii  postgresql-client-common                              154.pgdg14.04+1                                     all          manager for multiple PostgreSQL client versions
ii  postgresql-common                                     154.pgdg14.04+1                                     all          PostgreSQL database-cluster manager
ii  postgresql-contrib                                    9.3+154.pgdg14.04+1                                 all          additional facilities for PostgreSQL (supported version)
ii  postgresql-contrib-9.3                                9.3.4-1.pgdg14.04+1                                 amd64        additional facilities for PostgreSQL
ii  postgresql-server-dev-9.3                             9.3.4-1.pgdg14.04+1                                 amd64        development files for PostgreSQL 9.3 server-side programming

$ apt-cache policy postgresql-9.3
postgresql-9.3:
  Installed: 9.3.4-1.pgdg14.04+1
  Candidate: 9.3.4-1.pgdg14.04+1
  Version table:
 *** 9.3.4-1.pgdg14.04+1 0
        500 http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg/main amd64 Packages
        100 /var/lib/dpkg/status
     9.3.4-1 0
        500 http://de.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages

$ apt-cache policy postgresql-9.3-postgis-2.1
postgresql-9.3-postgis-2.1:
  Installed: 2.1.3+dfsg-3.pgdg14.04+2
  Candidate: 2.1.3+dfsg-3.pgdg14.04+2
  Version table:
 *** 2.1.3+dfsg-3.pgdg14.04+2 0
        500 http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg/main amd64 Packages
        100 /var/lib/dpkg/status
     2.1.2+dfsg-2 0
        500 http://de.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages

And regarding GEOS:

$ dpkg -l | grep libgeos
ii  libgeos-3.4.2                                         3.4.2-4ubuntu1                                      amd64        Geometry engine for Geographic Information Systems - C++ Library
ii  libgeos-c1                                            3.4.2-4ubuntu1                                      amd64        Geometry engine for Geographic Information Systems - C Library
ii  libgeos-dev                                           3.4.2-4ubuntu1                                      amd64        Geometry engine for GIS - Development files

$ apt-cache policy libgeos-3.4.2
libgeos-3.4.2:
  Installed: 3.4.2-4ubuntu1
  Candidate: 3.4.2-4ubuntu1
  Version table:
 *** 3.4.2-4ubuntu1 0
        500 http://de.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
        100 /var/lib/dpkg/status

My guess is that PostGIS is expecting a different version of GEOS. The question is which? And where from to install it?

Update: There are some hints of this issue being caused by an outdated version of liblwgeom. I thus removed all related packages (apt-get purge liblwgeom*) and re-installed PostGIS. This is what I have now:

$ dpkg -l | grep liblwgeom
ii  liblwgeom-2.1.3                                       2.1.3+dfsg-3.pgdg14.04+2                            amd64        PostGIS "Lightweight Geometry" library

But the problem remains.

Luís de Sousa
  • 3,935
  • 1
  • 29
  • 61
  • GEOS 3.4 after Prerequisites http://trac.osgeo.org/postgis/wiki/UsersWikiPostGIS21Ubuntu1310src – Mapperz Jul 24 '14 at 14:51
  • Hi Mapperz, I do have GEOS 3.4.2 installed (check the output of dpkg -l | grep libgeos in the question). What is exactly your point? – Luís de Sousa Jul 25 '14 at 07:35
  • 1
    You are not the only one: http://stackoverflow.com/questions/23598384/ubuntu-14-04-liblwgeom-2-1-1-postgres and http://gis.stackexchange.com/questions/97871/postgis-2-1-error-after-update as well as https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=749015 and http://comments.gmane.org/gmane.comp.gis.postgis/36963 – AndreJ Jul 28 '14 at 07:29

3 Answers3

15

Following the advice at the postgis-users maillist it was possible to identify the existence of outdated ligbeos libraries as the source of the problem:

$ locate libgeos_c.so
/usr/lib/libgeos_c.so
/usr/lib/libgeos_c.so.1
/usr/lib/libgeos_c.so.1.8.2
/usr/local/lib/libgeos_c.so
/usr/local/lib/libgeos_c.so.1
/usr/local/lib/libgeos_c.so.1.7.1
/usr/local/src/geos-3.3.1/capi/.libs/libgeos_c.so
/usr/local/src/geos-3.3.1/capi/.libs/libgeos_c.so.1
/usr/local/src/geos-3.3.1/capi/.libs/libgeos_c.so.1.7.1
/usr/local/src/geos-3.3.1/capi/.libs/libgeos_c.so.1.7.1T
/usr/share/gvSIG-desktop-2.0.0/gvSIG/extensiones/org.gvsig.raster.tilecache.app/install/files/native/libgeos_c.so.1
/usr/share/gvSIG-desktop-2.0.0/native/libgeos_c.so.1

Either during the upgrade to Ubuntu 14.04, or during the removal of old libgeos packages some .so files were inadvertently left behind. The fix was then to remove them and re-link:

$ sudo rm /usr/local/lib/libgeos_c.so*
$ sudo rm /usr/local/src/geos-3.3.1/capi/.libs/libgeos_c.so*
$ sudo ldconfig
$ sudo su postgres
$ /etc/init.d/postgresql restart 
$ psql pg_testing -c "create extension postgis"
CREATE EXTENSION

Usually, removing libraries manually in a system fully managed with the package manager is not a good idea, leading to other problems later on. In principle this will not be the case with these libraries.

Luís de Sousa
  • 3,935
  • 1
  • 29
  • 61
  • Worked like a charm. I didn't have anything in /usr/local/src/ so I skipped that line; didn't seem to cause any issues. – Nat Mar 22 '15 at 20:27
3

The only way I could get POSTGis on "Trusty" was to build from Sources, here is what I used ..

sudo mkdir postgis-build

cd postgis-build

------------------------------------------------------
then put the script below in a shell script file

sudo nano build.sh

make it executable and run it

sudo chmod a+x build.sh
------------------------------------------------------

sudo wget http://download.osgeo.org/geos/geos-3.4.2.tar.bz2
sudo tar xfj geos-3.4.2.tar.bz2
cd geos-3.4.2
sudo ./configure
sudo make
sudo make install
cd ..
sudo wget http://download.osgeo.org/postgis/source/postgis-2.1.3.tar.gz
sudo tar xfz postgis-2.1.3.tar.gz
cd postgis-2.1.3
sudo ./configure
sudo make
sudo make install
sudo ldconfig
sudo make comments-install
cd ..
sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/shp2pgsql
sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/pgsql2shp
sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/raster2pgsql
Mark Cupitt
  • 3,884
  • 4
  • 30
  • 54
  • 1
    Hi Mark, this might solve the issue, but only on a temporary basis. Mixing packages compiled from sources with packages installed from the repositories will always break up things at some point. With the automatic updates, the compiled packages eventually go out of step with those installed from the repositories. – Luís de Sousa Jul 25 '14 at 07:20
  • Don't disagree at all, but nothing form sources would work ... and I guess there are still some issues .. – Mark Cupitt Jul 25 '14 at 07:35
2

This doesn't answer your question directly - Mapperz has probably pointed you in the right direction. But I recommend using the UbuntuGIS package(s) as they've proven to be e-a-s-y to install and all the dependencies are there.

#    UbuntuGIS package:

sudo apt-add-repository ppa:ubuntugis/ppa
sudo apt-get update

#or for bleeding edge:
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
mtn.biker
  • 1,162
  • 8
  • 13