Home > AWS, CentOS, Fedora 15 64 bit, Linux, PostgreSQL > Compile and install PostGIS 2.0.0 on replicated PostgreSQL 9.1.3 at Amazon Web Services (EC2 , S3)

Compile and install PostGIS 2.0.0 on replicated PostgreSQL 9.1.3 at Amazon Web Services (EC2 , S3)

How to install that :

1. get the source needed

cd /opt/installs
wget http://postgis.refractions.net/download/postgis-2.0.0.tar.gz
wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz
wget http://download.osgeo.org/geos/geos-3.3.3.tar.bz2
git clone https://github.com/json-c/json-c.git
wget http://download.osgeo.org/gdal/gdal-1.9.1RC2.tar.gz
wget http://sourceforge.net/projects/cunit/files/latest/download
wget http://prdownloads.sourceforge.net/dblatex/dblatex-0.3.2.tar.bz2?download

# NOTE, you may skip the CUnit and dblatext install, but you will get these warnings at the configure of the postgs:
# ==========================================================================================
# checking for dblatex... no
# configure: WARNING: dblatex is not installed so PDF documentation cannot be built
# checking CUnit/CUnit.h usability... no
# checking CUnit/CUnit.h presence... no
# checking for CUnit/CUnit.h... no
# configure: WARNING: could not locate CUnit required for liblwgeom unit tests
# ==========================================================================================

yum install tetex-tex4ht -y
yum install libxml2-devel -y
yum install ImageMagick* -y

2. Compile and install proj-4

tar xvfz proj-4.8.0.tar.gz
cd proj-4.8.0
./configure ; make -j3 install; ldconfig
# if you run 64bit distro, the postgis build will fail so link the proj.pc at the 64bit pkgconfig directory :  
ln -s /usr/local/lib/pkgconfig/proj.pc /usr/lib64/pkgconfig/

3. Compile and install geos:
in case you dont have installed c++, install it

yum install gcc-c++ -y
tar xvf geos-3.3.3.tar.bz2 
cd geos-3.3.3
./configure --disable-libtool-lock
make -j3  install; ldconfig

4. Compile and install json-c lib:

cd /opt/install
cd cd json-c/
make -j3 install; ldconfig
# if you run 64bit distro, link the jspn.pc at the 64bit pkgconfig directory :  
ln -s /usr/local/lib/pkgconfig/json.pc /usr/lib64/pkgconfig/

4. Compile and install gdal-1.9.1 lib:
gdal compilation takes some time, so its better to detach the make process:

cd /opt/installs
tar xvf gdal-1.9.1RC2.tar.gz
cd gdal-1.9.1
echo "make -j3 install; ldconfig | tee /tmp/gdal-1.9.1RC2.install.log" | at now 
tail -f /tmp/gdal-1.9.1RC2.install.log

6. Compile and install CUnit-2.1-2:

cd /opt/installs
tar xf CUnit-2.1-2-src.tar.bz2
cd CUnit-2.1-2
./configure  ; make -j3 install; ldconfig
# if you run 64bit distro, link the cunit.pc at the 64bit pkgconfig directory :  
ln -s /usr/local/lib/pkgconfig/cunit.pc /usr/lib64/pkgconfig/

6. Compile and install postgis-2.0.0

cd /opt/installs
tar xvfz postgis-2.0.0.tar.gz
cd postgis-2.0.0
# at the end you will see something like:
#  PostGIS is now configured for x86_64-unknown-linux-gnu
# -------------- Compiler Info ------------- 
#  C compiler:           gcc -g -O2
#  C++ compiler:         g++ -g -O2
# -------------- Dependencies -------------- 
#  GEOS config:          /usr/local/bin/geos-config
#  GEOS version:         3.3.3
#  GDAL config:          /usr/local/bin/gdal-config
#  GDAL version:         1.9.1
#  PostgreSQL config:    /usr/bin/pg_config
#  PostgreSQL version:   PostgreSQL 9.1.3
#  PROJ4 version:        48
#  Libxml2 config:       /usr/bin/xml2-config
#  Libxml2 version:      2.7.6
#  JSON-C support:       yes
#  PostGIS debug level:  0
#  Perl:                 /usr/bin/perl
# --------------- Extensions --------------- 
#  PostGIS Raster:       enabled
#  PostGIS Topology:     enabled
# -------- Documentation Generation -------- 
#  xsltproc:             /usr/bin/xsltproc
#  xsl style sheets:     /usr/share/sgml/docbook/xsl-stylesheets
#  dblatex:              /usr/bin/dblatex
#  convert:              /usr/bin/convert
#  mathml2.dtd:          http://www.w3.org/Math/DTD/mathml2/mathml2.dtd
make -j3

There is huge possibility the build process to fail with the following error:

gcc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DLINUX_OOM_ADJ=0 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wformat-security -fno-strict-aliasing -fwrapv -fpic -I/usr/local/include   -I/usr/include/libxml2 -I../liblwgeom -I../libpgcommon -I. -I. -I/usr/include/pgsql/server -I/usr/include/pgsql/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o lwgeom_in_geojson.o lwgeom_in_geojson.c
In file included from lwgeom_in_geojson.c:31:
/usr/local/include/json/json.h:27:34: error: json_object_iterator.h: No such file or directory
lwgeom_in_geojson.c:467: warning: no previous prototype for ‘postgis_libjson_version’
make[1]: *** [lwgeom_in_geojson.o] Error 1
make[1]: Leaving directory `/opt/installs/postgis-2.0.0/postgis'
make: *** [all] Error 1
root@ip-10-28-187-67-node-2:[Fri May 18 13:01:52]:[/opt/installs/postgis-2.0.0]$

The issue is the following :

line 27 of /usr/local/include/json/json.h defined json_object_iterator.h to be included, but that file is missing in the include directory:

root@ip-10-28-187-67-node-2:[Fri May 18 15:57:29]:[/var/log]$ sed '27,27!d' /usr/local/include/json/json.h 
#include "json_object_iterator.h"
root@ip-10-28-187-67-node-2:[Fri May 18 13:03:14]:[/opt/installs/postgis-2.0.0]$ ls -lrht /usr/local/include/json/
total 72K
-rw-r--r-- 1 root root 6.0K May 18 12:54 json_tokener.h
-rw-r--r-- 1 root root 1.1K May 18 12:54 json_object_private.h
-rw-r--r-- 1 root root  17K May 18 12:54 json_object.h
-rw-r--r-- 1 root root  579 May 18 12:54 json_inttypes.h
-rw-r--r-- 1 root root  671 May 18 12:54 json.h
-rw-r--r-- 1 root root  163 May 18 12:54 json_config.h
-rw-r--r-- 1 root root 1.7K May 18 12:54 debug.h
-rw-r--r-- 1 root root  693 May 18 12:54 bits.h
-rw-r--r-- 1 root root 1.1K May 18 12:54 arraylist.h
-rw-r--r-- 1 root root 2.2K May 18 12:54 printbuf.h
-rw-r--r-- 1 root root 6.6K May 18 12:54 linkhash.h
-rw-r--r-- 1 root root  971 May 18 12:54 json_util.h

root@ip-10-28-187-67-node-2:[Fri May 18 13:03:11]:[/opt/installs/postgis-2.0.0]$ locate json_object_iterator.h

#how to fix the issue :
cp -vvv /opt/installs/json-c/json_object_iterator.h /usr/local/include/json/

so, clean the build and do it again:

cd /opt/installs/postgis-2.0.0
make clean 
echo "make -j3 install | tee -a /tmp/postgis-2.0.0.install.log" | at now 
tail -f /tmp/postgis-2.0.0.install.log

that is all for the install

now, we have to test it , before to claim it will work:
NOTE: do not test on a slave node in case the replication is active, the test will fail :

make test 
Creating spatial db postgis_reg 
createdb: database creation failed: ERROR:  cannot execute CREATE DATABASE in a read-only transaction
createlang: could not connect to database postgis_reg: FATAL:  database "postgis_reg" does not exist
psql: FATAL:  database "postgis_reg" does not exist
dropdb: database removal failed: ERROR:  cannot execute DROP DATABASE in a read-only transaction
Preparing spatial db postgis_reg 

 Something went wrong during db initialization (core module).
 For details, check /tmp/pgis_reg/regress_log

dropdb: database removal failed: ERROR:  cannot execute DROP DATABASE in a read-only transaction
make[1]: *** [check] Error 1
make[1]: Leaving directory `/opt/installs/postgis-2.0.0/regress'
make: *** [check] Error 1

test on the master:

# Note at the test time the slave will be catching up 
# Start the test detached as it will take some time, at AWS micro instance it takes a lot 🙂  
echo "make -j3 test | tee -a /tmp/postgis-2.0.0.make.test.log" | at now 
tail -f  /tmp/postgis-2.0.0.make.test.log
Creating spatial db postgis_reg 
Preparing spatial db postgis_reg 
TMPDIR is /tmp/pgis_reg
PATH is /usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin

 PostgreSQL 9.1.3 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3), 64-bit
 Postgis 2.0.0 - r9605 - 2012-05-18 17:38:33
   GEOS: 3.3.3-CAPI-1.7.4
   PROJ: Rel. 4.8.0, 6 March 2012

Running tests

 loader/Point ....................... ok 
 loader/PointM ....................... ok 
 loader/PointZ .....

postgres@kida:5432::postgres=[Fri May 18 12:32:41 EDT 2012]# \l
                                    List of databases
     Name      |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
 kannel        | mtel     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgis_reg   | root     | UTF8     | C           | en_US.UTF-8 | 
 postgres      | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 regression    | root     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 

postgres@juan:5432::postgres=[Fri May 18 12:37:36 EDT 2012]# select pg_current_xlog_location();
(1 row)

Time: 500.731 ms

postgres@kida:5432::postgres=[Fri May 18 12:37:38 EDT 2012]# select pg_last_xlog_replay_location()
(1 row)

Time: 162.957 ms

And that is all, you have now a Master – slave cluster with the Latest PostGIS ready for the devs ..:)


aaand …
Slackware4LIFE 🙂

  1. Dan Devine
    October 19, 2012 at 9:32 am

    This is really great. Thanks for the detail, that’s what got me through.
    Just as a note, the folks at GEOS have a ticket open about a failure I was seeing tonight while trying to rebuild.


    However, following the steps here, I no longer got it. Oddly enough, my install had a c/c++ compiler already, although I’m not sure which comes with the AWS image. In any case, when installing the gcc-c++ as noted above, I no longer had that error. It seemed like it was already there, as there were no complaints from the tool chain, other than the error in the middle of postgis-2.0.1

    Another interesting bit was the byacc vs bison install. I was seeing another failure that went away with the specific packages listed above.

    Great work Dragkh, it’s 2:26 am right now, and I wouldn’t be going home to sleep without you! Thanks for the posting.


  2. dragkh
    October 27, 2012 at 3:46 pm

    well the install took me like 3 hours digging and fixing 🙂

  3. Dan Devine
    October 27, 2012 at 4:45 pm

    One of the issues I saw, related to the JSON-C module.

    It appears that the latest version had some difficulty with autoconf. To get a successful build, I omitted the autogen step when building from source, went straight to ./configure, and disabled static linking with the configure switch.

    What a mess, it shouldn’t take 3 hours (or in my case, 3 days for my first successful build) to do this.

    Thanks dragkh

  4. November 9, 2012 at 3:02 pm

    Thanks! I got here searching for that json header file error. I wouldn’t have known what to do.

  5. Jeppe
    December 6, 2012 at 1:11 pm

    Thanks for a really neat guide!

    I stumbled upon three issues when issuing the “make test” of Postgis.

    1) authentication failed for user “root”
    I could not find any way to set the user to “postgres”. I solved this by temporarily adding a “root” super user via pgAdmin and setting hb_conf:
    nano /var/lib/pgsql9/data/pg_hba.conf
    and changing the two lines to trust (change them back to md5 afterwards)
    local all all trust
    host all all trust

    2) I got a permission denied to acces a file in the regress directory. I solved this by issuing a
    chmod a+x ~

    3) I got an error that I could not load library libgeos_c.so.1
    I solved this by manually adding the lib dirs to ld.so.conf
    echo ‘/usr/local/lib’ >> /etc/ld.so.conf
    echo ‘/usr/lib’ >> /etc/ld.so.conf
    echo ‘/usr/lib64’ >> /etc/ld.so.conf

  1. May 18, 2012 at 7:04 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: