Chapter 2. Installation

Table of Contents
PostGIS
JDBC
Loader/Dumper

PostGIS

The PostGIS module is a extension to the PostgreSQL backend server. As such, PostGIS 0.6 requires a full copy of the PostgreSQL 7.1.x source tree in order to compile. The PostgreSQL source code is available at http://www.postgresql.org.

PostGIS 0.6 has been built and tested against PostgreSQL 7.1.2. It will probably work with any of the 7.1.x versions. It will not work with any version prior to 7.1, or with version 7.2 (not yet released at date of writing). The next version, PostGIS 0.7, will work with PostgreSQL version 7.2.

  1. Before you can compile the postgis server modules, you must compile and install the PostgreSQL package.

  2. Retrieve the PostGIS source archive from http://postgis.refractions.net/postgis-0.6.tar.gz. Uncompress and untar the archive in the "contrib" directory of the PostgreSQL source tree.

      # cd [postgresql source tree]/contrib 
      # gzip -d -c	postgis-0.6.tar.gz | tar xvf -
  3. Once your PostgreSQL installation is up-to-date, enter the "postgis" directory, and run the compile and install commands.

      # cd ./postgis-0.6 
      # make 
      # make install
  4. As of version 0.6, PostGIS requires the PL/pgSQL procedural language extension. Before loading the postgis.sql file, you must first enable PL/pgSQL. The code snippet below gives an example, substitute the correct location of your plpgsql.so library.

      CREATE FUNCTION plpgsql_call_handler () RETURNS OPAQUE AS
         '/usr/local/pgsql/lib/plpgsql.so' LANGUAGE 'C';
      CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql'
         HANDLER plpgsql_call_handler
         LANCOMPILER 'PL/pgSQL';
  5. Finally, you must load the PostGIS object and function definitions into your database.

      # psql -d [yourdatabase] -f	postgis.sql

    The PostGIS server extensions are now loaded and ready to use.

Upgrading

Upgrading PostGIS can be tricky, because the underlying C libraries which support the object types and geometries may have changed between versions. To avoid problems when upgrading, you will have to dump all the tables in your database, destroy the database, create a new one, execute the new postgis.sql file, then upload your database dump:

  # pg_dump -t "*" -f dumpfile.sql yourdatabase
  # dropdb yourdatabase
  # createdb yourdatabase
  # psql -f postgis.sql -d yourdatabase
  # psql -f dumpfile.sql -d yourdatabase
  # vacuumdb -z yourdatabase

Note: When upgrading to 0.6, all your geometries will be created with an SRID of -1. To create valid OpenGIS geometries, you will have to create a valid SRID in the SPATIAL_REF_SYS table, and then update your geometries to reference the SRID with the following SQL (with the appropriate substitutions:

  UPDATE TABLE <table> SET <geocolumn> = SetSRID(<geocolumn>,<SRID>);