Go to the bathroom before we start this one! hehe
I’m breaking this into the following 3 sections:
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.
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.
createuser -E -P -s dbsuperuser
Now, try to login to the database with the super user you just created.
You should come out with the following prompt:
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 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.
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.
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:
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 cmake
Next, gaul. Check out the latest ones here. Right now, mine’s 0.1850-0.
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.
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: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/astar.c
/core/src/shooting_star.c
Just add the line:
That’ll make pgRouting see PostgreSQL 8.4 data types.
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.
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
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!
Ozi Maki
2010/07/28 at 11:18 AM
Damn!!. great article,.. many thanks to you. It work for me
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”
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
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.
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.
dbsuperuser
2010/08/01 at 7:08 AM
Thank you very much for this helpful article!!!
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.
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
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.
Thera
2011/01/06 at 11:22 PM
Also the package name is “build-essential”, not “build-essentials”
dukz
2011/01/07 at 8:51 PM
Updated. Thanks Thera
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?
dukz
2011/02/07 at 10:58 AM
RIchard W: Try having the libxml2-dev package installed.
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 [...]
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