Skip to content


Subversion checkout URL

You can clone with
Download ZIP
OpenStreetMap data to PostgreSQL converter
C++ Python Lua Other
Failed to load latest commit information.
contrib replace pbf and xml parser with libosmium
docs Merge pull request #410 from pnorman/doxygen
geos-fallback/geos/noding Add a few header files for people compiling under Ubuntu. geos-dev
m4 Adjust autoconf files for g++ -Werror
tests Improve tempdb comments
.gitignore Add a test for tables existing in another schema
.travis.yml Check -pedantic with travis
900913.sql Add postgis definition for the 900913 spherical mercator projection w…
AUTHORS Hoffmann has two n's Add basic Doxygen framework and convert some comments
COPYING * improved configure setup (including automake and libtool)
ChangeLog Revert "Remove the old SVN Changelog" Fix deletion of tablespace test from makefile
README Trim down README and move more detailed information into docs directory add missing zlib dependency in readme
TODO remove outdated gazetteer V1 code, * improved configure setup (including automake and libtool) Prefer c++11 over gnu++11 was missing from cygwin package. Merge branch 'upstream/master' into nocolumn Merge branch 'upstream/master' into nocolumn
expire-tiles.cpp Replace boost::scoped_ptr with std::unique_ptr within osm2pgsql itself
expire-tiles.hpp clean up includes and remove unused rb.cpp
geometry-builder.cpp Use range-based loops in geometry-builder
geometry-builder.hpp Replace wkt_itr with foreach loops and auto
geometry-processor.cpp Replace boost::shared_ptr with std::shared_ptr
geometry-processor.hpp Replace boost::shared_ptr with std::shared_ptr
id-tracker.cpp remove pending tracking from the ram middle processing as now the mid…
id-tracker.hpp Replace boost::scoped_ptr with std::unique_ptr within osm2pgsql itself Fix syntax error in install script [osm2pgsql] Update debian package scripts to handle postgis-9.1
middle-pgsql.cpp Merge pull request #418 from pnorman/options_refactor_2
middle-pgsql.hpp Clean up middle --slim --drop logic
middle-ram.cpp Replace boost::shared_ptr with std::shared_ptr
middle-ram.hpp Replace boost::shared_ptr with std::shared_ptr
middle.cpp Replace boost::shared_ptr with std::shared_ptr
middle.hpp Improve Doxygen syntax
multi.lua Fix builing typo in example multi style Fix builing typo in example multi style
node-persistent-cache-reader.cpp Replace boost::shared_ptr with std::shared_ptr
node-persistent-cache.cpp Replace boost::shared_ptr with std::shared_ptr
node-persistent-cache.hpp Replace boost::shared_ptr with std::shared_ptr
node-ram-cache.cpp Move from NULL to nullptr
node-ram-cache.hpp Move from NULL to nullptr
options.cpp Default the number of processes to the hardware concurrency
options.hpp Move options checks into their own function
osm2pgsql.cpp Move db options into database_options_t * improved configure setup (including automake and libtool)
osmdata.cpp Replace boost::unordered_map with std::unordered_map
osmdata.hpp Replace boost::shared_ptr with std::shared_ptr
osmtypes.hpp Rename tag to tag_t
output-gazetteer.cpp Move db options into database_options_t
output-gazetteer.hpp Rename tag to tag_t
output-multi.cpp Move db options into database_options_t
output-multi.hpp Replace boost::scoped_ptr with std::unique_ptr within osm2pgsql itself
output-null.cpp Replace boost::shared_ptr with std::shared_ptr
output-null.hpp Replace boost::shared_ptr with std::shared_ptr
output-pgsql.cpp Move db options into database_options_t
output-pgsql.hpp Replace boost::scoped_ptr with std::unique_ptr within osm2pgsql itself
output.cpp Replace BOOST_FOREACH with new C++11 for loops
output.hpp Replace boost::shared_ptr with std::shared_ptr
parse-o5m.cpp Rename tag to tag_t
parse-o5m.hpp Replace boost::shared_ptr with std::shared_ptr
parse-osmium.cpp forward input-reader option to libosmium as format parameter
parse-osmium.hpp correctly parse change files
parse.cpp Replace boost::shared_ptr with std::shared_ptr
parse.hpp Replace boost::shared_ptr with std::shared_ptr
pgsql.cpp Replace BOOST_FOREACH with new C++11 for loops
pgsql.hpp Replace boost::shared_ptr with std::shared_ptr
processor-line.cpp clean up includes and remove unused rb.cpp
processor-line.hpp new types for keyval and for tag, member and node lists
processor-point.cpp remove scale everywhere but in ramNode
processor-point.hpp remove scale everywhere but in ramNode
processor-polygon.cpp clean up includes and remove unused rb.cpp
processor-polygon.hpp new types for keyval and for tag, member and node lists
reprojection.cpp Move from NULL to nullptr
reprojection.hpp replace pbf and xml parser with libosmium
sample.multi.json fix tab in sample multi config
sprompt.cpp Clean up whitespace errors
sprompt.hpp Renamed C files to C++ in preparation for destaticification.
style.lua Correct variable name
table.cpp Rename tag to tag_t
table.hpp Replace boost::scoped_ptr with std::unique_ptr within osm2pgsql itself
taginfo.cpp Move from NULL to nullptr
taginfo.hpp Removed a lot of static, global state variables from `output_pgsql_t`.
taginfo_impl.hpp Change proposed hstore flag to nocolumn
tagtransform.cpp Convert more for loops, now that tag_t is renamed
tagtransform.hpp Use foreach/auto loops in tagtransform
util.cpp replace printf with boost::format
util.hpp remove scale everywhere but in ramNode
wildcmp.cpp Clean up whitespace errors
wildcmp.hpp Wildcard matching should operate on const char arrays.
win_fsync.h fix headers and missing functions for MSVC/MinGW


osm2pgsql is a tool for loading OpenStreetMap data into a PostgreSQL / PostGIS database suitable for applications like rendering into a map, geocoding with Nominatim, or general analysis.


  • Converts OSM files to a PostgreSQL DB
  • Conversion of tags to columns is configurable in the style file
  • Able to read .gz, .bz2, .pbf and .o5m files directly
  • Can apply diffs to keep the database up to date
  • Support the choice of output projection
  • Configurable table names
  • Gazetteer back-end for Nominatim
  • Support for hstore field type to store the complete set of tags in one database field if desired


The latest source code is available in the OSM git repository on github and can be downloaded as follows:

$ git clone git://


Osm2pgsql uses the GNU Build System to configure and build itself and requires

It also requires access to a database server running PostgreSQL and PostGIS.

Make sure you have installed the development packages for the libraries mentioned in the requirements section and a C++ compiler which supports C++11. Both GCC 4.8 and Clang 3.4 meet this requirement.

To install on a Debian or Ubuntu system, first install the prerequisites:

sudo apt-get install autoconf automake libtool make g++ pkg-config libboost-dev \
  libboost-system-dev libboost-filesystem-dev libboost-thread-dev libexpat1-dev \
  libgeos-dev libgeos++-dev libpq-dev libbz2-dev libproj-dev zlib1g-dev \
  protobuf-compiler libprotobuf-dev lua5.2 liblua5.2-dev

To install on a Fedora system, use

sudo yum install gcc-c++ automake libtool pkgconfig boost-devel \
  expat-devel bzip2-devel postgresql-devel geos-devel proj-devel \
  lua-devel protobuf-devel protobuf-lite-devel

To install on a FreeBSD system, use

pkg install devel/git devel/autoconf devel/automake devel/gmake devel/libtool \
  textproc/expat2 graphics/geos graphics/proj databases/postgresql94-client \
  devel/boost-libs devel/protobuf lang/lua52 devel/pkgconf

Then you should be able to bootstrap the build system:


And then run the standard GNU build install:

./configure && make && make install

Please see ./configure --help for more options on how to control the build process.

On FreeBSD instead bootstrap and then run

LUA_LIB=`pkg-config --libs lua-5.2` ./configure && gmake && gmake install


Osm2pgsql has one program, the executable itself, which has 42 command line options.

Before loading into a database, the database must be created and the PostGIS and optionally hstore extensions must be loaded. A full guide to PostgreSQL setup is beyond the scope of this readme, but with reasonably recent versions of PostgreSQL and PostGIS this can be done with

createdb gis
psql -d gis -c 'CREATE EXTENSION postgis; CREATE EXTENSION hstore;'

A basic invocation to load the data into the database gis for rendering would be

osm2pgsql --create --database gis data.osm.pbf

This will load the data from data.osm.pbf into the planet_osm_point, planet_osm_line, planet_osm_roads, and planet_osm_polygon tables.

When importing a large amount of data such as the complete planet, a typical command line would be

osm2pgsql -c -d gis --slim -C <cache size> \
  --flat-nodes <flat nodes> planet-latest.osm.pbf


  • <cache size> is 24000 on machines with 32GiB or more RAM or about 75% of memory in MiB on machines with less
  • <flat nodes> is a location where a 24GiB file can be saved.

The databases from either of these commands can be used immediately by Mapnik for rendering maps with standard tools like renderd/mod_tile, TileMill, Nik4, among others. It can also be used for spatial analysis or shapefile exports.

Additional documentation is available on writing command lines.

Alternate backends

In addition to the standard pgsql backend designed for rendering there is also the gazetteer database for geocoding, principally with Nominatim, and the null backend for testing. For flexibility a new multi backend is also avialable which allows the configuration of custom postgres tables instead of those provided in the pgsql backend.

Any questions should be directed at the osm dev list


We welcome contributions to osm2pgsql. If you would like to report an issue, please use the issue tracker on GitHub.

More information can be found in

General queries can be sent to the tile-serving@ or dev@ mailing lists.

Something went wrong with that request. Please try again.