PostGIS

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

PostGIS 0.7 can be built against PostgreSQL 7.1.x or PostgreSQL 7.2.x. Earlier versions of PostgreSQL are not supported.

  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.7.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.7.tar.gz | tar xvf -
  3. Once your PostgreSQL installation is up-to-date, enter the "postgis" directory, and edit the Makefile.

    • If you are compiling against PostgreSQL 7.2.x, you must set the USE_PG72 variable to 1.

    • If want support for coordinate reprojection you must have the Proj4 library installed, and set the USE_PROJ variable to 1.

  4. Run the compile and install commands.

      # make 
      # make install

    All files are installed relative to the PostgreSQL install directory, [prefix].

    • Libraries are installed [prefix]/lib/contrib.

    • Important support files such as postgis.sql are installed in [prefix]/share/contrib.

    • Loader and dumber binaries are installed [prefix]/bin.

  5. PostGIS requires the PL/pgSQL procedural language extension. Before loading the postgis.sql file, you must first enable PL/pgSQL. You should use the createlang command. The PostgreSQL 7.1 Programmer's Guide has the details if you want to this manually for some reason.
      # createlang plpgsql [yourdatabase]

  6. Now load the PostGIS object and function definitions into your database by loading the postgis.sql definitions file.

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

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

  7. For a complete set of EPSG coordinate system definition identifiers, you can also load the spatial_ref_sys.sql definitions file and populate the SPATIAL_REF_SYS table.

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

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
  # createlang plpgsql yourdatabse
  # psql -f postgis.sql -d yourdatabase
  # psql -f dumpfile.sql -d yourdatabase
  # vacuumdb -z yourdatabase

Note: When upgrading from version 0.5 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>);