PostGIS in osx and debian

PostGIS in osx and debian

I'm working in some cool GIS stuff using some shapefiles so i've finished using postgis... well... that was the idea, but i had some issues trying to setup everything in my mac so after some research i've found a gist that saved my life and here it is with some minor modifications. Hopefully in a few days i'll upload a tele script for it.

All the fame and fortune belongs to this gist

OSX

      #0. Setup some stuff
      db_name='name'
      db_user='user'

      # As in Postgres 9.0.1 in brew initdb causes some malloc issues
      sudo sysctl -w kern.sysv.shmall=65536
      sudo sysctl -w kern.sysv.shmmax=16777216

      # To make the changes permanent instead of just the running kernel
      echo "kern.sysv.shmall=65536\nkern.sysv.shmmax=16777216" >> /etc/sysctl.conf

      #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

      # Import Postgis Data
      psql -d postgis_template -f
      /usr/local/Cellar/postgis/1.5.3/share/postgis/postgis.sql
      psql -d postgis_template -f
      /usr/local/Cellar/postgis/1.5.3/share/postgis/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 an app to your application
      createuser -i -l -S -R -P -d $db_user

      echo "GRANT gisgroup TO $db_user;\q" | psql -d postgres

      #5. Create your app database
      createdb -T postgis_template -O $db_user $db_name;
    

Debian

      #0. Setup some stuff
      db_name='name'
      db_user='user'

      #1. Install PostgreSQL postgis and postgres

      sudo apt-get install postgresql postgresql-client postgresql-contrib
      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 an app to your application
      createuser -i -l -S -R -P -d $db_user

      echo "GRANT gisgroup TO $db_user;\q" | psql -d postgres

      #5. Create your app database
      createdb -T postgis_template -O $db_user $db_name;