Skip to content

Instantly share code, notes, and snippets.

@juniorz
Created July 14, 2011 03:49
Show Gist options
  • Star 55 You must be signed in to star a gist
  • Fork 24 You must be signed in to fork a gist
  • Save juniorz/1081907 to your computer and use it in GitHub Desktop.
Save juniorz/1081907 to your computer and use it in GitHub Desktop.
Installing PostGIS on Mac OS X and Ubuntu
# 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 postgis_template
createlang plpgsql postgis_template
#[Mac OSX] Import Postgis Data
psql -d postgis_template -f /usr/local/Cellar/postgis/2.0.0/share/postgis/postgis.sql
psql -d postgis_template -f /usr/local/Cellar/postgis/2.0.0/share/postgis/spatial_ref_sys.sql
# If you want Raster support
psql -d postgis_template -f /usr/local/Cellar/postgis/2.0.0/share/postgis/rtpostgis.sql
psql -d postgis_template -f /usr/local/Cellar/postgis/2.0.0/share/postgis/topology.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 your app's user
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>;
# 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-8.4 postgresql-client-8.4 postgresql-contrib-8.4
# Maybe you may need to install from this repository:
# https://launchpad.net/~ubuntugis/+archive/ubuntugis-unstable
sudo apt-get install postgresql-8.4-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/8.4/contrib/postgis-1.5/postgis.sql
psql -d postgis_template -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.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 your app's user
createuser -i -l -S -R -d <app_user>
psql -d postgres
GRANT gisgroup TO <app_user>;
\q
# Note: Remember to adding the <app_user> to your /etc/postgresql/8.4/main/pg_hba.conf
# Example: local all <app_user> trust
#5. Create your app database
createdb -T postgis_template -O <app_user> <app_db>;
@klebervirgilio
Copy link

Hey man! Perfect!! It works pretty well!

@vibze
Copy link

vibze commented Jan 18, 2012

Many thanks. I found postgis installation on mac os to be a huge pain. Looks like brew was the 'mac way' to do it.

Copy link

ghost commented Sep 8, 2012

Good work man. Thanks

@ecantor
Copy link

ecantor commented Dec 27, 2012

This gist installs postgis1.5; any idea how to get postgis 2 up and running? Have tried macports and kyngchaos on Postgres 9.1 but am not having any luck.

@erdostom
Copy link

Thank you 👍

@mcordone
Copy link

mcordone commented Mar 5, 2015

Great! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment