I tried loading the OSMplanet.osm (or rather a subset that contains the city of Hamburg) into Postgres. The wiki tells me this can be done using osm2pgsql or osmosis. I set up postgres database called "osm_europe" with postgis to hold the data and started:
Omosis is a java application which for purely subjective reasons, I m not particularily fond of. So I only tried it after my first attempt with osm2pgsql failed.
The result:
$ osmosis --read-xml-0.6 file=hamburg.osm --write-apidb-0.6 host=localhost database=osm_europe user=osm populateCurentTables=yes validateSchemaversion=no
Jan 11, 2010 9:10:18 AM com.bretth.osmosis.core.Osmosis run
INFO: Osmosis Version 0.30
Jan 11, 2010 9:10:18 AM com.bretth.osmosis.core.Osmosis run
INFO: Preparing pipeline.
Jan 11, 2010 9:10:18 AM com.bretth.osmosis.core.Osmosis main
SEVERE: Execution aborted.
com.bretth.osmosis.core.OsmosisRuntimeException: Task type write-apidb-0.6 doesn't exist.
at com.bretth.osmosis.core.pipeline.common.TaskManagerFactoryRegister.getInstance(TaskManagerFactoryRegister.java:60)
at com.bretth.osmosis.core.pipeline.common.Pipeline.buildTasks(Pipeline.java:50)
at com.bretth.osmosis.core.pipeline.common.Pipeline.prepare(Pipeline.java:112)
at com.bretth.osmosis.core.Osmosis.run(Osmosis.java:79)
at com.bretth.osmosis.core.Osmosis.main(Osmosis.java:30)
so I went back to osm2pgsql.
I started with this command
$ osm2pgsql -d osm_europe --slim -U osm -H 127.0.0.1 ~/hamburg.osm
which started loading the file, but soon failed because it was violating the PRIMARY KEY constraint in the database.
The OSM file format seems to not be very well defined, which might be the underlying problem of this error and manifests itself like this:
]]>
(I cheated, this particular node is actually correct in the hamburg.osm file, however I am too lazy to look up a correctly wrong one, so i modified it to illustrate)
osm2pgsql seems to be using the "id" attribute of the node as it's PRIMARY KEY, which presents a problem when dealing with multiple versions of the same node. Or multiple versions of a node should have different Ids. Not sure which.
To fix this, I got myself the sourcecode of pgsql, and changed the file "middle-pgsql.c". It contains a static struct table_desc tables which sets up tables for "nodes", "ways", and "rels". These three all contain an int4 as their id which is specified to be the PRIMARY KEY. Since in postgres the PRIMARY KEY constraint is equivalent to UNIQUE NOT NULL, I just changed "PRIMARY KEY" to "NOT NULL" and compiled it (which just requires a "make" if your environment is set up right).
Running my modified version of osm2pgsql worked well. Now I have to find out if I managed to break anything by doing this.