UPDATE: Since this article was written, Yum now comes packaged with PostGIS 1.5. Please refer to
PostGIS Yum Install for PostgreSQL 9.0 if you want to go with a faster more idiot proof install process
A couple of people have asked this, so thought we would address the common issues people run into
with compiling PostGIS.
The first question, some will ask is Why don't you just take the packaged PostGIS that comes with the PostgreSQL
Yum repository?
There are two reasons for not installing PostGIS under using Yum and our general reasons for not.
- We like running a newer GEOS than what is generally packaged with Yum because certain PostGIS functionality
is not enabled with older versions of GEOS. For example GEOS 3.1 introduced a couple of new functions like ST_Covers and
ST_CoveredBy, ST_ContainedProperly
the Cascaded Union and prepared geometry speed enhancements require GEOS 3.1+. GEOS 3.2 brought more robust support for dealing with topological
exceptions, new buffering features like one-sided buffer (which the upcoming PostGIS 1.5 exposes if and only if you are running
GEOS 3.2+), faster buffering, and several memory leak cleanups. We highly recommend using GEOS 3.2.0. It is just a more robust product than prior GEOS versions.
- We generally like to run newer versions of PostGIS than what Yum provides and also run multiple versions of PostGIS
on the same server. This is a bit tricky to do with Yum since it only exposes one and generally an older one than what we
care for. PostGIS 1.5 will be especially great since it will have the geodetic support and cool functions like ST_ClosestPoint
and other major goodies.
NOTE: PostGIS 1.3, PostGIS 1.4, PostGIS 1.5 can coexist on the same PostgreSQL daemon service as long as they are installed in different databases. They will all share the same Proj and GEOS. So installing PostGIS 1.5 will not break your
PostGIS 1.4 or 1.3 installs. The newer GEOS 3.2.0 C-API is backward compatible with older GEOS C-API and the C-API is what PostGIS uses.
Now that we answered the why, the next is How?. For this How section, we'll outline the things you need
to compile first which are NOT packaged with PostGIS. We will also be focusing on the upcoming PostGIS 1.5.
We will also outline the common issues people run into. Issues are most common on a 64-bit Linux Centos/Redhat EL.
Basic overview steps
- Install PostgreSQL using Yum as we outlined in PostgreSQL 8.4 Yum Install. Also remember to yum install postgresql-dev.
Do not yum install postgis.
- download, compile, install proj 4.6+, don't forget nad datum shift folder
- download, compile, install geos 3.2 from http://trac.osgeo.org/geos/ . Note seem to run into fewer linking issues if you download from SVN, but then you have to do a yum install svn to install subversion client.
- download, compile, install libxml 2.6+ - ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz (this is a new dependency for PostGIS 1.5 to support the ST_GeomFromGML and ST_GeomFromKML functions). It is not required for older versions of PostGIS.
- download, compile, install postgis http://www.postgis.org/downloads
- Fix geos / proj linking errors if you run into them. This seems to be more of an issue with 64-bit Linux
than any other we have run into. We'll go over how to discover missing links and fix them.
Preprep
Yum Installs you need. As mentioned you need to Yum install PostgreSQL and postgresql-devel.
Missing G++, GCC
If you run into issues like complaints about no gcc+ compiler, then you probably need to:
yum install gcc-c++
mkdir /sources
cd /sources
Download and install Proj
cd /sources
mkdir proj
cd proj
wget http://download.osgeo.org/proj/proj-4.6.1.tar.gz
tar -xvf proj-4.6.1.tar.gz
wget http://download.osgeo.org/proj/proj-datumgrid-1.4.zip
unzip proj-datumgrid-1.4.zip -d proj-4.6.1/nad
cd proj-4.6.1
./configure
make
make install
ldconfig
Download and install GEOS
cd /sources
mkdir geos
cd geos
wget http://download.osgeo.org/geos/geos-3.2.0.tar.bz2
tar -xvf geos-3.2.0.tar.bz2
cd geos-3.2.0
./configure
make & make install
make check
ldconfig
Download and install libxml
This is only needed for PostGIS 1.5+
cd /sources
mkdir libxml
cd libxml
wget ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz
tar -xvf libxml2-2.7.6.tar.gz
cd libxml2-2.7.6
./configure
make & make install
ldconfig
Download and install PostGIS 1.5 SVN
You may swap this out with PostGIS 1.4.1 for mission critical production use, but we are demonstrating PostGIS 1.5 SVN.
This is going to be a really exciting release once we get all our ducks in a row hopefully by early to Mid January 2010.
cd /sources
mkdir postgis
cd postgis
wget http://www.postgis.org/download/postgis-1.5.0SVN.tar.gz
tar -xvf postgis-1.5.0SVN.tar.gz
cd postgis-1.5.0SVN
./configure
make
make install
make check
ldconfig
Problems
Its very common to run into linking issues particularly with GEOS or Proj on a 64-bit that its either pointing at an old version or non-existent location. To detect said linking issues do the following:
ldd -d /usr/lib64/pgsql/postgis-1.5.so (to show all the dependencies (or ldd -d /usr/lib/pgsql/postgis-1.5.so if you are on 32-bit)
ldd -d /usr/lib64/pgsql/postgis-1.5.so | grep libgeos (or ldd -d /usr/lib/pgsql/postgis-1.5.so if you are on 32-bit)
ldd -d /usr/lib64/pgsql/postgis-1.5.so | grep libproj (or ldd -d /usr/lib/pgsql/postgis-1.5.so if you are on 32-bit)
You should get something of the form below which would tell me my geos is pointing at an older version
libgeos_c.so.1 => /usr/lib64/libgeos_c.so.1
libgeos-3.1.0.so => /usr/local/lib/libgeos-3.1.0.so (0x00110000)
To fix, may not be the best of solutions, but I destroy the symlinks and relink them something of the form:
rm /usr/lib/libgeos_c.so.1
ln -s /usr/local/lib/libgeos_c.so.1.6.0 /usr/lib64/libgeos_c.so.1
ln -s /usr/local/lib/libproj.so /usr/lib64/libproj.so.0
Installing PostGIS in a db
The insall path will be changing shortly -- but you can always find the sql files in the source folder: Here we are creating a template_postgis15.
createdb template_postgis15 -U postgres
cd /sources/postgis/postgis-1.5.0SVN
psql -d template_postgis15 -U postgres -c "CREATE LANGUAGE plpgsql"
psql -d template_postgis15 -U postgres -f postgis/postgis.sql
psql -d template_postgis15 -U postgres -f spatial_ref_sys.sql
#this installs the help description for each function you can search via psql or pgadmin
psql -d template_postgis15 -U postgres -f doc/postgis_comments.sql
To verify all is good, run the below command in the database you just created using psql or PgAdminIII
SELECT postgis_full_version();
You should get an output something like:
POSTGIS="1.5.0SVN" GEOS="3.2.0-CAPI-1.6.0" PROJ="Rel. 4.6.1, 21 August 2008" LIBXML="2.7.6" USE_STATS