milkbox.net

@2013-01-05 - Update: No longer needed…

You can replace the content below now by simply doing:

CREATE EXTENSION postgis;

Wow.

Requires PostgreSQL 9.1+. See Creating a spatial database using EXTENSIONS

Outdated:

@2012-06-04 - Currently requires PostGIS 1.5.x

Based on Django GIS documentation

Adding a new user and follow the prompts,

createuser -W

First create a template database template_postgis,

POSTGIS_SQL_PATH=/usr/local/share/postgis
createdb template_postgis 
createlang -d template_postgis plpgsql
psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';"
psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis.sql
psql -d template_postgis -f $POSTGIS_SQL_PATH/spatial_ref_sys.sql
psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;"
psql -d template_postgis -c "GRANT ALL ON geography_columns TO PUBLIC;"
psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"

Create DB from template,

createdb -T template_postgis stonesoup