Import database with osm2pgsql

Hello! I am trying to import OSM data into my database for Spain using osm2pgsql. However, when I run the import, it creates intermediate tables with names starting with ‘Planet_osm_*’. Instead, I need to save the data into specific tables such as ‘ways’, ‘current_ways’, ‘nodes’, ‘current_nodes’, ‘current_way_nodes’, ‘way_nodes’, etc. I am not sure what the next steps are to achieve this. Can you guide me on how to proceed?

The database created by osm2pgsql can be varied in several ways. For creating rendering databases you can use the “pgsql” or “flex” backends (see the osm2pgsql documentation for more information) and there’s also the concept of an “apidb” (not used for rendering) which from reading Recreate osmosis --write-apidb using flex backend · Issue #1174 · openstreetmap/osm2pgsql · GitHub I suspect you might’ve been trying to do.

What sort of database are you trying to create and why do you want the tables that you have described?

What do you want to be able to do with it afterwards?


Two things come to mind:

  1. Use of the --prefix option during data import. With this you can set the table name prefix to something else than “planet_osm”, For example, -- prefix spain should result in table names such as “spain_ways” etc. I don’t know, however, if it is possible to set the prefix to an empty string (i.e. -- prefix '') in order to not get any prefix at all, although I would suspect that you would still get an underscore at the beginning of table names. You might want to try this out to see what you get.
  2. Simply rename tables upon completion of the data import (ALTER TABLE planet_osm_ways RENAME TO ways, and likewise for the other tables).

Robert, thank you for trying to be helpful but what you are suggesting is almost certainly not what the poster wants. The table names mentioned by the poster point to wanting to use an APIDB schema database, which doesn’t just have differently named tables - the tables also have differing content, and osm2pgsql is the wrong tool. SomeoneElse is right with his suggestion to use osmosis.

1 Like