Installing & Setting Up PostgreSQL With PostGIS

Author: Dan Blomberg | Last updated February 13th, 2010 at 01:06pm

Introduction

This tutorial will guide you through the steps involved with installing PostgreSQL and PostGIS on your Windows based PC.  PostGIS is a requirement for the way GPSFileDepot creates Garmin compatible maps.

Instructions

This tutorial last updated for version 8.4.3.

PostgreSQL

  1. Go the the PostgreSQL windows downloads.
  2. Download the "one click installer".
  3. Click windows on the EnterpriseDB page.
  4. Run the .exe that has been downloaded to install PostgreSQL.
  5. The default install directories should be good.  When prompted enter a password that you can remember.
  6. The normal settings should be good. 
  7. Make sure the "Launch Stack Builder at exist?" box is unchecked and click finish.
  8. Now we will make it so you can connect without a password (this is optional but makes life easier)
  9. Stop the service from running: (start>all programs> postgresql X.X>Stop Service)
  10. Open pg_hba.conf (start>all programs>postgresql X.X>Configurations Files>Edit pg_hba.conf
    Note: In v 8.4+ you have to access the pg_hba.conf by browsing to the PostgreSQL folder, then version number, then data and then open pg_hba.conf
  11. Change the line reading:
    host    all         all         127.0.0.1/32          md5
    to
    host    all         all         127.0.0.1/32          trust
    If you use IPv6 change the next line below it as well.
  12. Reload the configuration files (start>all programs>postgresql X.X>Reload configuration)
  13. Restart the server (start>all programs>postgresql X.X>Restart Server)

PostGIS

  1. Start the Application Stack Builder (in PostgreSQL's start menu)
  2.  Select your local server:
  3. Under "Spatial Extensions" check the most recent version of PostGIS:
  4. Pick a server near you and click "Next"
  5. Leave the download location alone and click "Next"
  6. After the download finishes click next to start installing.
    Note: In windows 7 I ran into an "elevation" problem.  Due to this I had to go to the location where the file was download (in my case the Temp directory) and right click on the PostGIS_1_4_gp84.exe and select run as administrator.
  7. Make sure create spatial database is checked.
  8. Leave the default options.  Make sure you enter your password if needed.

Now you should have a fully operational postgis database.

Creating More Databases

You may, at some point, need to create more postGIS databases.  In this case you need to create them with a template file.

  1. Open pgAdmin III
  2. Connect to your local server
  3. Right click on databases and click "New Database..."
  4. Enter a name for your new database
  5. Select the username you've been using as the owner (default is "postgres")
  6. For the template select "template_postgis"
  7. Click okay.

A new database has now been created.  You have to use a template in order to have it be a spatial database.

If you have any questions about this tutorial please contact us or post in the forums.