osm2pgsql导入duplicate key error in slim mode

This is a well known issue and one that is likely not going to be addressed any time soon.

While the rendering tables allow multiple geometries per osm feature / id and therefore don't have a unique constraint on osm_id, the slim tables are used for update processing and thus need to do lookups based on osm_id, for which it has to be unique.

For performance reasons osm2pgsql uses the COPY command, that batches up inserts into a single command. As such, if there is a unique constraint (or duplicate Key) violation, the whole batch fails. As osm2pgsql does stream based processing, it does not have the ability to go back and reprocess that batch of nodes / ways / relations to properly deal with the duplicate entry. Therefore, it cannot recover from such a duplicate key failure and terminates.

Osm2pgsql therefore doesn't support importing multiple files into one database in slim mode if there are duplicate osm features. Instead, I would recommend merging the two files prior to importing with osm2pgsql. For example with osmosis that supports de-duplication on merge.

参考: https://github.com/openstreetmap/osm2pgsql/issues/16#event-165848217

上一篇:iOS技术周报-第17期


下一篇:Android中Activity和task,活动亲和力,启动模式,活动状态以及生命周期,激活钝化