Created
June 13, 2012 18:50
-
-
Save derek-schaefer/2925756 to your computer and use it in GitHub Desktop.
PostGIS Template Creation Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Run a command as the postgres user | |
AS_POSTGRES="sudo -u postgres" | |
# Set path to postgresql contrib path | |
POSTGIS_SQL_PATH=/usr/share/postgresql/9.1/contrib | |
#Create the template spatial database | |
$AS_POSTGRES createdb -E UTF8 -T template0 template_postgis | |
# Loading the PostGIS SQL routines. | |
$AS_POSTGRES psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis-1.5/postgis.sql | |
$AS_POSTGRES psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis-1.5/spatial_ref_sys.sql | |
# Enabling users to alter spatial tables. | |
$AS_POSTGRES psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;" | |
$AS_POSTGRES psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;" | |
# Garbage-collect and freeze. | |
$AS_POSTGRES psql -d template_postgis -c "VACUUM FULL;" | |
$AS_POSTGRES psql -d template_postgis -c "VACUUM FREEZE;" | |
# Allows non-superusers the ability to create from this template. | |
$AS_POSTGRES psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';" | |
$AS_POSTGRES psql -d postgres -c "UPDATE pg_database SET datallowconn='false' WHERE datname='template_postgis';" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment