dazuma/activerecord-postgis-adapter — Issue #13: postgis_template alternative
Author: s01ipsist
Created: 2011-12-05 09:24:12+00:00
State: open

I use a quite simple alternative to your proposed options for: Dealing With PostGIS Definitions

I set up a template database once that already has the definitions in it; and never need to worry about it again as Rails allows you to specify a different template in the database.yml
template: template_postgis

For example, in my current server my notes were.

-----

sudo su postgres

createdb template_postgis
createlang plpgsql template_postgis
psql -d template_postgis -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql
psql -d template_postgis -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql
psql -d template_postgis -f /usr/share/postgresql/8.4/contrib/postgis_comments.sql

psql template_postgis
-- in a production environment you may want to
-- give role based permissions, but granting all for now
GRANT ALL ON geometry_columns TO PUBLIC;
GRANT ALL ON spatial_ref_sys TO PUBLIC;
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';

-- vacuum freeze: it will guarantee that all rows in the database are
-- "frozen" and will not be subject to transaction ID wraparound
-- problems.
VACUUM FREEZE;
----
When installing postgis on Windows, the installation sets up a template database called postgis also.

Is there any benefit to the (what I perceive as more complicated) method suggested?