osm2pgsql1
Openstreetmap data to postgresql converter
Usage
osm2pgsql [OPTIONS]
OSM-FILE ...
Overview
osm2pgsql imports OpenStreetMap data into a PostgreSQL/PostGIS database. It is an essential part of many rendering toolchains, the Nominatim geocoder and other applications processing OSM data.
osm2pgsql can run in either “create” mode (the default) or in “append” mode (option -a, --append).
In “create” mode osm2pgsql will create the database tables required by the configuration and import the OSM file(s) specified on the command line into those tables. Note that you also have to use the -s, --slim option if you want your database to be updatable.
In “append” mode osm2pgsql will update the database tables with the data from OSM change files specified on the command line.
This man page can only cover some of the basics and describe the command line options. See the Osm2pgsql Manual ⟨https://osm2pgsql.org/doc/manual.html⟩\c for more information.
Options
This program follows the usual GNU command line syntax, with long options starting with two dashes (--). Mandatory arguments to long options are mandatory for short options too.
Options
-
-a, --append -
Run in append mode. Adds the OSM change file into the database without removing existing data.
-
-c, --create -
Run in create mode. This is the default if -a, --append is not specified. Removes existing data from the database tables!
Options
-
-h, --help -
Print help.
-
-V, --version -
Print osm2pgsql version.
Options
-
--log-level=LEVEL -
Set log level (`debug', `info' (default), `warn', or `error').
-
--log-progress=VALUE -
Enable (
true) or disable (false) progress logging. Setting this toautowill enable progress logging on the console and disable it if the output is redirected to a file. Default: true.
-
--log-sql -
Enable logging of SQL commands for debugging.
-
--log-sql-data -
Enable logging of all data added to the database. This will write out a huge amount of data! For debugging.
-
-v, --verbose -
Same as
--log-level=debug.
Options
-
-d, --database=NAME -
The name of the PostgreSQL database to connect to. If this parameter contains an
=sign or starts with a valid URI prefix (postgresql://orpostgres://), it is treated as a conninfo string. See the PostgreSQL manual for details.
-
-U, --username=NAME, --user=NAME -
Postgresql user name.
-
-W, --password -
Force password prompt.
-
-H, --host=HOSTNAME -
Database server hostname or unix domain socket location.
-
-P, --port=PORT -
Database server port.
-
--schema=SCHEMA -
Default for various schema settings throughout osm2pgsql (default:
public). The schema must exist in the database and be writable by the database user.
Options
-
-r, --input-reader=FORMAT -
Select format of the input file. Available choices are
auto(default) for autodetecting the format,xmlfor OSM XML format files,o5mfor o5m formatted files andpbffor OSM PBF binary format.
-
-b, --bbox=MINLON,MINLAT,MAXLON,MAXLAT -
Apply a bounding box filter on the imported data. Example:
--bbox-0.5,51.25,0.5,51.75
Options
-
-i, --tablespace-index=TABLESPC -
Store all indexes in the PostgreSQL tablespace
TABLESPC. This option also affects the tables created by the pgsql output. This option is deprecated. Use the --tablespace-slim-index and/or --tablespace-main-index options instead.
-
--tablespace-slim-data=TABLESPC -
Store the slim mode tables in the given tablespace.
-
--tablespace-slim-index=TABLESPC -
Store the indexes of the slim mode tables in the given tablespace.
-
-p, --prefix=PREFIX -
Prefix for table names (default:
planet_osm).
-
-s, --slim -
Store temporary data in the database. Without this mode, all temporary data is stored in RAM and if you do not have enough the import will not work successfully. With slim mode, you should be able to import the data even on a system with limited RAM, although if you do not have enough RAM to cache at least all of the nodes, the time to import the data will likely be greatly increased.
-
--drop -
Drop the slim mode tables from the database and the flat node file once the import is complete. This can greatly reduce the size of the database, as the slim mode tables typically are the same size, if not slightly bigger than the main tables. It does not, however, reduce the maximum spike of disk usage during import. It can furthermore increase the import speed, as no indexes need to be created for the slim mode tables, which (depending on hardware) can nearly halve import time. Slim mode tables however have to be persistent if you want to be able to update your database, as these tables are needed for diff processing.
-
-C, --cache=NUM -
Only for slim mode: Use up to NUM MB of RAM for caching nodes. Giving osm2pgsql sufficient cache to store all imported nodes typically greatly increases the speed of the import. Each cached node requires 8 bytes of cache, plus about 10% - 30% overhead. As a rule of thumb, give a bit more than the size of the import file in PBF format. If the RAM is not big enough, use about 75% of memory. Make sure to leave enough RAM for PostgreSQL. It needs at least the amount of
shared_buffersgiven in its configuration. Defaults to 800.
-
-x, --extra-attributes -
Include attributes of each object in the middle tables and make them available to the outputs. Attributes are: user name, user id, changeset id, timestamp and version.
-
-F, --flat-nodes=FILENAME -
Use a file on disk to store node locations instead of storing them in memory (in non-slim mode) or in the database (in slim mode). This is much more efficient than storing the data in the database. Storing the node information for the full planet requires more than 500GB in PostgreSQL, the same data is stored in “only” 90GB using the flat-nodes mode. This can also increase the speed of applying diff files. This option activates the flat-nodes mode and specifies the location of the database file. It is a single large file. This mode is only recommended for full planet imports as it doesn’t work well with small imports. The default is disabled. The file will stay on disk after import, use --drop to remove it (but you can’t do updates then).
-
--middle-schema=SCHEMA -
Use PostgreSQL schema SCHEMA for all tables, indexes, and functions in the middle. The schema must exist in the database and be writable by the database user. By default the schema set with
--schemais used, orpublicif that is not set.
-
--middle-with-nodes -
When a flat nodes file is used, nodes are not stored in the database. Use this option to force storing nodes with tags in the database, too.
Options
-
-O, --output=OUTPUT -
Specifies the output to use. Currently osm2pgsql supports
pgsql,flex, andnull.pgsqlis the default output still available for backwards compatibility. New setups should use theflexoutput which allows for a much more flexible configuration. Thenulloutput does not write anything and is only useful for testing or with--slimfor creating slim tables.
-
-S, --style=FILE -
The style file. This specifies how the data is imported into the database, its format depends on the output. (For the
pgsqloutput, the default is/usr/share/osm2pgsql/default.style, for other outputs there is no default.)
Options
-
--tablespace-main-data=TABLESPC -
Store the data tables in the PostgreSQL tablespace
TABLESPC.
-
--tablespace-main-index=TABLESPC -
Store the indexes in the PostgreSQL tablespace
TABLESPC.
-
--latlong -
Store coordinates in degrees of latitude & longitude.
-
-m, --merc -
Store coordinates in Spherical Mercator (Web Mercator, EPSG:3857) (the default).
-
-E, --proj=SRID -
Use projection EPSG:SRID.
-
-p, --prefix=PREFIX -
Prefix for table names (default:
planet_osm). This option affects the middle as well as the pgsql output table names.
-
--tag-transform-script=SCRIPT -
Specify a Lua script to handle tag filtering and normalisation. The script contains callback functions for nodes, ways and relations, which each take a set of tags and returns a transformed, filtered set of tags which are then written to the database.
-
-x, --extra-attributes -
Include attributes (user name, user id, changeset id, timestamp and version). This also requires additional entries in your style file.
-
-k, --hstore -
Add tags without column to an additional hstore (key/value) column in the database tables.
-
-j, --hstore-all -
Add all tags to an additional hstore (key/value) column in the database tables.
-
-z, --hstore-column=PREFIX -
Add an additional hstore (key/value) column named
PREFIXcontaining all tags that have a key starting withPREFIX, eg\--hstore-column "name:"will produce an extra hstore column that contains allname:xxtags.
-
--hstore-match-only -
Only keep objects that have a value in at least one of the non-hstore columns.
-
--hstore-add-index -
Create indexes for all hstore columns after import.
-
-G, --multi-geometry -
Normally osm2pgsql splits multi-part geometries into separate database rows per part. A single OSM object can therefore use several rows in the output tables. With this option, osm2pgsql instead generates multi-geometry features in the PostgreSQL tables.
-
-K, --keep-coastlines -
Keep coastline data rather than filtering it out. By default objects tagged
natural=coastlinewill be discarded based on the assumption that Shapefiles generated by OSMCoastline (https://osmdata.openstreetmap.de/) will be used for the coastline data.
-
--reproject-area -
Compute area column using spherical mercator coordinates even if a different projection is used for the geometries.
-
--output-pgsql-schema=SCHEMA -
Use PostgreSQL schema SCHEMA for all tables, indexes, and functions in the pgsql output. The schema must exist in the database and be writable by the database user. By default the schema set with
--schemais used, orpublicif that is not set.
Options
-
-e, --expire-tiles=[MIN_ZOOM-]MAX-ZOOM -
Create a tile expiry list.
-
-o, --expire-output=FILENAME -
Output file name for expired tiles list.
-
--expire-bbox-size=SIZE -
Max size for a polygon to expire the whole polygon, not just the boundary.
Options
-
-I, --disable-parallel-indexing -
Disable parallel clustering and index building on all tables, build one index after the other.
-
--number-processes=THREADS -
Specifies the number of parallel threads used for certain operations.
Releases
10 releases since Debian 5.0 (Lenny); the text changed 9 times.
--append since Debian 11 (Bullseye);
--bbox since Debian 11 (Bullseye);
--cache since Debian 11 (Bullseye);
--create since Debian 11 (Bullseye);
--database since Debian 11 (Bullseye);
--disable-parallel-indexing since Debian 11 (Bullseye);
--drop since Debian 8 (Jessie);
--expire-bbox-size since Debian 11 (Bullseye);
--expire-output since Debian 11 (Bullseye);
--expire-tiles since Debian 11 (Bullseye);
--extra-attributes since Debian 11 (Bullseye);
--flat-nodes since Debian 8 (Jessie);
--help since Debian 11 (Bullseye);
--host since Debian 11 (Bullseye);
--hstore since Debian 11 (Bullseye);
--hstore-add-index since Debian 8 (Jessie);
--hstore-all since Debian 11 (Bullseye);
--hstore-column since Debian 11 (Bullseye);
--hstore-match-only since Debian 8 (Jessie);
--input-reader since Debian 11 (Bullseye);
--keep-coastlines since Debian 11 (Bullseye);
--latlong since Debian 11 (Bullseye);
--log-level since Debian 11 (Bullseye);
--log-progress since Debian 11 (Bullseye);
--log-sql since Debian 11 (Bullseye);
--log-sql-data since Debian 11 (Bullseye);
--merc since Debian 11 (Bullseye);
--middle-schema since Debian 11 (Bullseye);
--middle-with-nodes since Debian 13 (Trixie);
--multi-geometry since Debian 11 (Bullseye);
--number-processes since Debian 8 (Jessie);
--output since Debian 11 (Bullseye);
--output-pgsql-schema since Debian 11 (Bullseye);
--password since Debian 11 (Bullseye);
--port since Debian 11 (Bullseye);
--prefix since Debian 11 (Bullseye);
--proj since Debian 11 (Bullseye);
--reproject-area since Debian 11 (Bullseye);
--schema since Debian 13 (Trixie);
--slim since Debian 11 (Bullseye);
--style since Debian 11 (Bullseye);
--tablespace-index since Debian 11 (Bullseye);
--tablespace-main-data since Debian 8 (Jessie);
--tablespace-main-index since Debian 8 (Jessie);
--tablespace-slim-data since Debian 8 (Jessie);
--tablespace-slim-index since Debian 8 (Jessie);
--tag-transform-script since Debian 11 (Bullseye);
--user since Arch Linux 2026-11-01;
--username since Debian 11 (Bullseye);
--verbose since Debian 11 (Bullseye);
--version since Debian 11 (Bullseye);
-C since Debian 11 (Bullseye);
-E since Debian 11 (Bullseye);
-F since Debian 13 (Trixie);
-G since Debian 11 (Bullseye);
-H since Debian 11 (Bullseye);
-I since Debian 11 (Bullseye);
-K since Debian 11 (Bullseye);
-O since Debian 11 (Bullseye);
-P since Debian 11 (Bullseye);
-S since Debian 11 (Bullseye);
-U since Debian 11 (Bullseye);
-V since Debian 11 (Bullseye);
-W since Debian 11 (Bullseye);
-a since Debian 11 (Bullseye);
-b since Debian 11 (Bullseye);
-c since Debian 11 (Bullseye);
-d since Debian 11 (Bullseye);
-e since Debian 11 (Bullseye);
-h since Debian 11 (Bullseye);
-i since Debian 11 (Bullseye);
-j since Debian 11 (Bullseye);
-k since Debian 11 (Bullseye);
-m since Debian 11 (Bullseye);
-o since Debian 11 (Bullseye);
-p since Debian 11 (Bullseye);
-r since Debian 11 (Bullseye);
-s since Debian 11 (Bullseye);
-v since Debian 11 (Bullseye);
-x since Debian 11 (Bullseye);
-z since Debian 11 (Bullseye).
--cache-strategy until Debian 12 (Bookworm);
--exclude-invalid-polygon until Debian 10 (Buster);
--middle-way-node-index-id-shift until Debian 12 (Bookworm);
--oldmerc until Debian 7 (Wheezy);
--unlogged until Debian 10 (Buster);
--utf8-sanitize until Debian 7 (Wheezy);
--with-forward-dependencies until Debian 12 (Bookworm);
-M until Debian 7 (Wheezy);
-l until Debian 7 (Wheezy);
-u until Debian 7 (Wheezy).