After I got some experience with hosting OpenStreetMap tiles during the revival of Openptmap, I wanted to dig deeper into the topic in order to firstly migrate Openptmap to the new flex output so that it can receive incremental updates, and secondly to be able to host some additional overlays.
I found that the only widely used way to host tiles is overv/openstreetmap-tile-server. On the first look, it is really easy to use. It takes care of importing and updating the OSM database and of rendering and serving the tiles. On the second look however, there are some major challenges and problems with it:
- It has been unmaintained for several years. The version of osm2pgsql included (1.6.0) is so old that even the outdated osm2pgsql v1 documentation does not apply to it anymore. Using the current flex output approach works with it, but requires various workarounds and trial and error to find out which functions were supported in the old version that is not documented anymore.
- The approach of running the OSM database and the tile server in one container becomes really unpractical as soon as you want to run multiple tile servers. To enable incremental updates, osm2pgsql needs to persist around 300 GB of metadata, even if the extract of data that is actually needed (for example only the public transportation lines for Openptmap) is only a few GB. With this approach, these 300 GB would be consumed by each tile server. Instead, it makes much more sense to host the OSM database and the tile server separately, so that one OSM database can be shared by all the tile servers and the metadata needs to be stored only once.
- There are some additional smaller design problems with the docker image. For example, if something fails during the import or you want to change the rendering style, it generally requires deleting the whole data and doing a new import, which can take many hours for the whole planet. Also, it for example requires write access to the style directory because it wants to write the compiled
mapnik.xmlfile there. This is incompatible with my server setup, where configuration and data are strictly separated, and the style directory would be considered configuration, so it would be read-only.
Because of this I have decided to fork openstreetmap-tile-server. My image facilmap/openstreetmap-tile-server only hosts the tile server, and expects the OSM database to be hosted separately. Since there are already good docker images for PostGIS and osm2pgsql, I have decided to use those and write a detailed guide how to set up everything together. You can find the guide in the README of the openstreetmap-tile-server repository.
I am still a beginner in regards to all this software. Also, I have very little experience with Lua and relied heavily on AI to write the scripts. Feel free to suggest improvements if you have more experience with this.
Discussion