Posts Tagged ‘PostGIS’

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

May 18, 2012 6 comments

How to install that :

1. get the source needed

cd /opt/installs
git clone

# 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:
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 🙂