I'm trying to generate a database with the osm2pgsql schema using the osm2pgsql application, with the command:

osm2pgsql -H host -U user -P 5433  -W -d db -k -l -c -s file.pbf

But when I'm running osm2pgsql, I get the following error:

Using built-in tag processing pipeline
Using projection SRS 4326 (Latlong)
Setting up table: planet_osm_point
Setting up table: planet_osm_line
Setting up table: planet_osm_polygon
Setting up table: planet_osm_roads
Allocating memory for dense node cache
Allocating dense node cache in one big chunk
Allocating memory for sparse node cache
Sharing dense sparse
Node-cache: cache=800MB, maxblocks=102400*8192, allocation method=11
Mid: pgsql, scale=10000000 cache=800
Setting up table: planet_osm_nodes
Setting up table: planet_osm_ways
Setting up table: planet_osm_rels
Reading in file: snapdb.pbf
Invalid blocksize 1010792557
Error occurred, cleaning up

I took a look on the osm2pgsql source code and the error Invalid blocksize %lu occurs when the osm2pgsql verifies the header size of the file, so I presumed that this error is with my .pbf file.

My problem was when I created my .pfb file using the osmosis application, I created a .osm file with the .pbf extension using this command:

osmosis --read-apidb host="host" database="db" user="user" password="pass" --write-xml file="test.pbf" 

I did this using the argument --write-xml instead of --write-pbf.

So, when I was running the osm2pgsql:

osm2pgsql -H host -U user -P 5433  -W -d db -k -l -c -s file.pbf

The tool was getting the extension by the file's name and trying to read the .osm file as a .pbf file. Is it a bug?

I solved this problem simply renaming my file to .osm using:

mv file.pbf file.osm

Or I could create the file again using the correct command:

osmosis --read-apidb host="host" database="db" user="user" password="pass" --write-pbf file="test.pbf" 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.