Skip to content

Instantly share code, notes, and snippets.

@dnordberg
Forked from lucasallan/install_postgis_osx.sh
Last active December 14, 2015 12:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dnordberg/5085901 to your computer and use it in GitHub Desktop.
Save dnordberg/5085901 to your computer and use it in GitHub Desktop.
# Some good references are:
# http://russbrooks.com/2010/11/25/install-postgresql-9-on-os-x
# http://www.paolocorti.net/2008/01/30/installing-postgis-on-ubuntu/
# http://postgis.refractions.net/documentation/manual-1.5/ch02.html#id2630392
#1. Install PostgreSQL postgis and postgres
brew install postgis
initdb /usr/local/var/postgres
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
#2. Create a template to be used on creating GIS-enabled databases
createdb -h localhost postgis_template
createlang -h localhost plpgsql postgis_template
#Prefix PATH with /usr/local/var/postgres
#[Mac OSX] Import Postgis Data
psql -h localhost -d postgis_template -f /usr/local/Cellar/postgis/2.0.2/share/postgis/postgis.sql
psql -h localhost -d postgis_template -f /usr/local/Cellar/postgis/2.0.2/share/postgis/spatial_ref_sys.sql
psql -h localhost -d postgis_template -f /usr/local/Cellar/postgis/2.0.2/share/postgis/legacy.sql
#Test if works
psql -h localhost -d postgis_template -c "SELECT postgis_full_version();"
#3. Set template permissions to gisgroup
createuser -h localhost -R -S -L -D -I gisgroup;
psql -h localhost -d postgis_template
ALTER DATABASE postgis_template OWNER TO gisgroup;
ALTER TABLE geometry_columns OWNER TO gisgroup;
ALTER TABLE spatial_ref_sys OWNER TO gisgroup;
CREATE SCHEMA gis_schema AUTHORIZATION gisgroup;
\q
#4. Adds an app to your application
createuser -h localhost -i -l -S -R -d <app_user>
psql -h localhost -d postgres
GRANT gisgroup TO <app_user>;
\q
#5. Create your app database
createdb -h localhost -T postgis_template -O <app_user> <app_db>;
# Some good references are:
# http://russbrooks.com/2010/11/25/install-postgresql-9-on-os-x
# http://www.paolocorti.net/2008/01/30/installing-postgis-on-ubuntu/
# http://postgis.refractions.net/documentation/manual-1.5/ch02.html#id2630392
#1. Install PostgreSQL postgis and postgres
sudo apt-get install postgresql-9.2 postgresql-client-9.2 postgresql-contrib-9.2
sudo apt-get install postgresql-9.2-postgis
#2. Create a template to be used on creating GIS-enabled databases
sudo su postgres
createdb postgis_template
createlang plpgsql postgis_template
#Import Postgis Data
psql -d postgis_template -f /usr/share/postgresql/9.2/contrib/postgis-2.0.2/postgis.sql
psql -d postgis_template -f /usr/share/postgresql/9.2/contrib/postgis-2.0.2/spatial_ref_sys.sql
psql -d postgis_template -f /usr/share/postgresql/9.2/contrib/postgis-2.0.2/legacy.sql
#Test if works
psql -d postgis_template -c "SELECT postgis_full_version();"
#3. Set template permissions to gisgroup
createuser -R -S -L -D -I gisgroup;
psql -d postgis_template
ALTER DATABASE postgis_template OWNER TO gisgroup;
ALTER TABLE geometry_columns OWNER TO gisgroup;
ALTER TABLE spatial_ref_sys OWNER TO gisgroup;
CREATE SCHEMA gis_schema AUTHORIZATION gisgroup;
\q
#4. Adds an app to your application
createuser -i -l -S -R -d <app_user>
psql -d postgres
GRANT gisgroup TO <app_user>;
\q
#5. Create your app database
createdb -T postgis_template -O <app_user> <app_db>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment