RSS
 

Installing PostgreSQL 8.4, PostGIS 1.4.1, and pgRouting 1.0.3 on Ubuntu 9.10 (Karmic Koala)

01 Feb

Go to the bathroom before we start this one! hehe

I’m breaking this into the following 3 sections:

  1. Installing PostgreSQL 8.4
  2. Installing PostGIS 1.4.1
  3. Installing pgRouting 1.0.3

Installing PostgreSQL 8.4

Get a working copy of PostgreSQL running. At the time of this writing, Ubuntu has deprecated PostgreSQL 8.3, and has 8.4 as stable. So that’s what aptitude will install here.

sudo apt-get install postgresql

Normally, you wouldn’t have access to the database right now. You need to use the postgres user to set up. I’d recommend not changing the password of the postgres user. Just create a PostgreSQL super user.

sudo su -l postgres
createuser -E -P -s dbsuperuser

Now, try to login to the database with the super user you just created.

psql -U dbsuperuser -W -h 127.0.0.1 postgres

You should come out with the following prompt:

postgres=#

Installing PostGIS 1.4.1

We’re compiling PostGIS, so we gotta get compilers. Normally you’d have them, unless you made a minimal install. I usually just get the build-essential package to get it over with.

sudo apt-get install build-essential
sudo apt-get install libgeos-dev
sudo apt-get install proj
sudo apt-get install postgresql-server-dev-8.4

You need the last one to be able to compile PostGIS. Had a lot of trouble without it, so I just added it. =)

Get the latest version of PostGIS here. At this time, PostGIS is at 1.4.1.

wget http://postgis.refractions.net/download/postgis-1.4.1.tar.gz
tar zxvf postgis-1.4.1.tar.gz
cd postgis-1.4.1
./configure
make
sudo make install

Everything should be compiled. Now we need to create the PostGIS database template. I normally have the naming scheme of template_XXX, so I’m naming my database as template_postgis.

For the next few statements, you can either switch to the postgres user, so you don’t have to enter the password everytime. I normally use the super user I create to do this.

createdb -U dbsuperuser -h 127.0.0.1 -W -E UNICODE template_postgis
createlang -U dbsuperuser -h 127.0.0.1 -W -d template_postgis plpgsql
psql -U dbsuperuser -h 127.0.0.1 -W template_postgis < /usr/share/postgresql/8.4/contrib/postgis.sql
psql -U dbsuperuser -h 127.0.0.1 -W template_postgis < /usr/share/postgresql/8.4/contrib/spatial_ref_sys.sql

Check your PostGIS installation with the following command:

psql -U dbsuperuser -h 127.0.0.1 -W -c "SELECT postgis_lib_version();" template_postgis

Should give you the version of your PostGIS.

Installing pgRouting 1.0.3

You can follow the official guide here.

Now it gets complicated. Stable version 1.0.3 of pgRouting as of the moment isn’t compatible to compile with 8.4. You have to edit some code… not really. Just add a few include headers in the C files. =)

Let’s begin by installing dependencies. First up, libboost… this is a huge library.

sudo apt-get install libboost-graph-dev
sudo apt-get install cmake

Next, gaul. Check out the latest ones here. Right now, mine’s 0.1850-0.

wget http://sourceforge.net/projects/gaul/files/gaul-devel/0.1850-0/gaul-devel-0.1850-0.tar.gz/download
tar -zxvf gaul-devel-0.1850-0.tar.gz
cd gaul-devel-0.1850-0
./configure --disable-slang
make
sudo make install
sudo ldconfig

Get pgRouting here. Now, I don’t use DD so I skipped installing CGAL and DD.

wget http://files.postlbs.org/pgrouting/source/pgRouting-1.03.tgz
tar -zxvf pgRouting-1.03.tgz
cd pgrouting/
cmake -DWITH_TSP=on

At this point, if cmake spits out an error like this:

core/src/dijkstra.c: In function ‘fetch_edge_columns’:
core/src/dijkstra.c:98: error: ‘INT4OID’ undeclared (first use in this function)
core/src/dijkstra.c:98: error: (Each undeclared identifier is reported only once
core/src/dijkstra.c:98: error: for each function it appears in.)
core/src/dijkstra.c:100: error: ‘FLOAT8OID’ undeclared (first use in this function)

There’s an issue with PostgreSQL 8.4. v1.0.3 still doesn’t support 8.4 at the moment (pgRouting Ticket #160), so I have to edit the following files (Hat tip to thge on this one):

/core/src/dijkstra.c
/core/src/astar.c
/core/src/shooting_star.c

Just add the line:

#include "catalog/pg_type.h"

That’ll make pgRouting see PostgreSQL 8.4 data types.

cmake -DWITH_TSP=on
make
sudo make install

pgRouting should now be installed in /usr/share/postlbs. As I said before, I like my database naming schemes, so I’m creating another template for pgRouting called template_pgrouting. Create the database with template_postgis as your base template.

createdb -U dbsuperuser -h 127.0.0.1 -W -E UNICODE -T template_postgis template_routing
psql -U dbsuperuser -h 127.0.0.1 -W template_routing < /usr/share/postlbs/routing_core.sql
psql -U dbsuperuser -h 127.0.0.1 -W template_routing < /usr/share/postlbs/routing_core_wrappers.sql
psql -U dbsuperuser -h 127.0.0.1 -W template_routing < /usr/share/postlbs/routing_topology.sql
psql -U dbsuperuser -h 127.0.0.1 -W template_routing < /usr/share/postlbs/routing_tsp.sql
psql -U dbsuperuser -h 127.0.0.1 -W template_routing < /usr/share/postlbs/routing_tsp_wrappers.sql

We’re done!! Grab a coke and go pee!

Update: Fixed package name from build-essentials to build-essential; Added postgres to the psql command to connect to database; Thanks Thera

 
 

Tags: , , , , , ,

Leave a Reply

 

 
  1. Marsupilami

    2010/03/29 at 3:41 AM

    Great!
    I am new to ubuntu, to postgresql and postgis but i got everything going straight away thanks to your page!

     
  2. Ozi Maki

    2010/07/28 at 11:18 AM

    Damn!!. great article,.. many thanks to you. It work for me

     
  3. dbsuperuser

    2010/08/01 at 6:11 AM

    I encountered an error when I tried to log in as the dbsuperuser from the command line. However I ran the pgAdmin III interface and it connected no problem. . .

    The error I got trying to log in was as follows:

    psql: FATAL: password authentication failed for user “dbsuperuser”

     
  4. dbsuperuser

    2010/08/01 at 6:30 AM

    These two lines produce a permission denied error for me:

    psql -U dbsuperuser -h 127.0.0.1 -W template_postgis < /usr/share/postgresql/8.4/contrib/postgis.sql
    psql -U dbsuperuser -h 127.0.0.1 -W template_postgis < /usr/share/postgresql/8.4/contrib/spatial_ref_sys.sql

     
  5. dbsuperuser

    2010/08/01 at 6:42 AM

    I just realized that I had upgraded my ubuntu and that might be why i am running into these problems. I’m on 10.04.

     
  6. dbsuperuser

    2010/08/01 at 7:06 AM

    So the work around for my, Ubuntu 10.04, psql command line, permission denied problem was to manually submit the SQL files, postgis.sql and spatial_ref_sys.sql, using the pgAdmin III interface.

     
  7. dbsuperuser

    2010/08/01 at 7:08 AM

    Thank you very much for this helpful article!!!

     
  8. dukz

    2010/08/04 at 11:38 PM

    @dbsuperuser: it might be that your user isn’t a postgresql super user. :) Glad that you were able to work around it.

     
  9. ivan

    2010/08/20 at 12:27 AM

    Hi
    many thanks form your post..
    I have modified
    /core/src/dijkstra.c
    /core/src/astar.c
    /core/src/shooting_star.c
    adding
    #include “catalog/pg_type.h”
    just before other includes, as you suggested.
    but after
    __________________________
    cmake -DWITH_TSP=ON
    Boost headers were found here: /usr/include
    Output directory for libraries is set to /usr/lib/postgresql/8.4/lib
    Installation directory for libraries is set to /usr/lib/postgresql/8.4/lib and for SQL files is set to /usr/share/postlbs
    Installation directory for libraries is set to /usr/lib/postgresql/8.4/lib
    – Configuring done
    – Generating done
    – Build files have been written to: /home/ivan/pgrouting
    ___________________-
    that works fine,

    ___________________
    make
    [ 12%] Building C object extra/tsp/src/CMakeFiles/routing_tsp.dir/tsp.o
    [ 25%] Building CXX object extra/tsp/src/CMakeFiles/routing_tsp.dir/tsp_solver.o
    Linking CXX shared library ../../../lib/librouting_tsp.so
    [ 25%] Built target routing_tsp
    [ 37%] Building C object core/src/CMakeFiles/routing.dir/dijkstra.o
    /home/ivan/pgrouting/core/src/dijkstra.c: In function ‘fetch_edge_columns’:
    /home/ivan/pgrouting/core/src/dijkstra.c:98: error: ‘INT4OID’ undeclared (first use in this function)
    /home/ivan/pgrouting/core/src/dijkstra.c:98: error: (Each undeclared identifier is reported only once
    /home/ivan/pgrouting/core/src/dijkstra.c:98: error: for each function it appears in.)
    /home/ivan/pgrouting/core/src/dijkstra.c:100: error: ‘FLOAT8OID’ undeclared (first use in this function)
    make[2]: *** [core/src/CMakeFiles/routing.dir/dijkstra.o] Errore 1
    make[1]: *** [core/src/CMakeFiles/routing.dir/all] Errore 2
    make: *** [all] Errore 2
    _________________________

    I’m using postgresql 8.4.4 (from repositories) on karmic 9.10.

    thanks for your help

     
  10. Thera

    2011/01/06 at 11:20 PM

    Quick note: “psql -U dbsuperuser -W -h 127.0.0.1″ doesn’t work because there is no database named dbsuperuser, so you should add “-d posgres” in the command to be able to login.

     
  11. Thera

    2011/01/06 at 11:22 PM

    Also the package name is “build-essential”, not “build-essentials”

     
  12. dukz

    2011/01/07 at 8:51 PM

    Updated. Thanks Thera

     
  13. Richard W

    2011/01/19 at 1:16 AM

    Hi there,

    Great article, but unfortunately I’m getting stuck whilst trying to install PostGIS 1.5.2. I run the configure command but it kicks up a warning, so I run it again using the following syntax:

    ./configure –with-xml2config=/usr/bin/xml2

    ..and I get the following error:

    “configure: error: could not find headers include related to libxml2″.

    I ran sudo apt-get install libxml2 and that installed libxml2, but unfortunately the error still exists. Any thoughts?

     
  14. dukz

    2011/02/07 at 10:58 AM

    RIchard W: Try having the libxml2-dev package installed. :)

     
  15. PostGIS & pgRouting. Your best friends. « S3n3ca's Blog

    2011/02/23 at 11:58 PM

    [...] there a few hints : Obviously there is the pgRotuingHomepage with its tutorial. This guy has also ObsessiveCoderBlog a good description. Sadly those two did not really work out for me in the first place. Spend hours [...]

     
  16. Diego

    2011/03/25 at 5:12 AM

    Great!
    When I run the following snippet:
    “make pgRouting”
    shows the error below. Does anyone know please tell me?

    root@servidor:/usr/local/pgrouting# make
    Scanning dependencies of target routing_tsp
    [ 12%] Building CXX object extra/tsp/src/CMakeFiles/routing_tsp.dir/tsp_solver.o
    Linking CXX shared library ../../../lib/librouting_tsp.so
    [ 25%] Built target routing_tsp
    [ 37%] Building C object core/src/CMakeFiles/routing.dir/dijkstra.o
    In file included from /usr/local/pgsql/include/server/catalog/pg_type.h:22,
    from /usr/local/pgrouting/core/src/dijkstra.c:22:
    /usr/local/pgsql/include/server/nodes/nodes.h:390: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Node’
    /usr/local/pgsql/include/server/nodes/nodes.h:429: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘equal’
    In file included from /usr/local/pgrouting/core/src/dijkstra.c:22:
    /usr/local/pgsql/include/server/catalog/pg_type.h:43: error: expected ‘)’ before numeric constant

     
  17. nfsc

    2012/05/21 at 5:53 PM

    hi,
    error: ‘INT4OID’ undeclared (first use in this function) this is the error
    i go and add these line
    #include “catalog/pg_type.h”

    but still the error is there

    there is the complete error
    [ 16%] Built target routing_tsp
    [ 25%] Building C object extra/driving_distance/src/CMakeFiles/routing_dd.dir/alpha.o
    /home/geospat/pgrouting/extra/driving_distance/src/alpha.c: In function ‘fetch_vertices_columns’:
    /home/geospat/pgrouting/extra/driving_distance/src/alpha.c:137:67: error: ‘INT4OID’ undeclared (first use in this function)
    /home/geospat/pgrouting/extra/driving_distance/src/alpha.c:137:67: note: each undeclared identifier is reported only once for each function it appears in
    /home/geospat/pgrouting/extra/driving_distance/src/alpha.c:138:66: error: ‘FLOAT8OID’ undeclared (first use in this function)
    make[2]: *** [extra/driving_distance/src/CMakeFiles/routing_dd.dir/alpha.o] Error 1
    make[1]: *** [extra/driving_distance/src/CMakeFiles/routing_dd.dir/all] Error 2
    make: *** [all] Error 2

     
  18. nfsc

    2012/05/21 at 5:56 PM

    ivan i am getting the same error
    i am using ubuntu 12.04 lts

     
  19. shraddha

    2012/06/14 at 4:23 AM

    Hi,
    I am getting errors on following lines:

    psql -U dbsuperuser -h 127.0.0.1 -W template_routing < /usr/share/postlbs/routing_core_wrappers.sql
    psql -U dbsuperuser -h 127.0.0.1 -W template_routing < /usr/share/postlbs/routing_topology.sql
    psql -U dbsuperuser -h 127.0.0.1 -W template_routing < /usr/share/postlbs/routing_tsp.sql
    psql -U dbsuperuser -h 127.0.0.1 -W template_routing < /usr/share/postlbs/routing_tsp_wrappers.sql

    psql:routing_core_wrappers.sql:106: ERROR: type "geometry" does not exist
    psql:routing_core_wrappers.sql:149: ERROR: type "geoms" does not exist
    psql:routing_core_wrappers.sql:199: ERROR: type "geoms" does not exist

    Any suggestions?

     
  20. linux

    2013/04/15 at 7:37 AM

    You actually make it appear really easy along with your presentation but I find this matter to be actually something that I feel I might by no means understand. It seems too complex and extremely extensive for me. I’m taking a look ahead on your subsequent submit, I’ll try to get the grasp of it!

     
  21. Unlimited Reseller Account

    2013/05/02 at 9:43 AM

    Just want to say your article is as astonishing. The clarity to your publish is simply cool and that i could assume you’re a professional on this subject. Fine together with your permission let me to clutch your feed to keep up to date with drawing close post. Thank you a million and please continue the gratifying work.