OSM2PGSQL(1)
π OSM2PGSQL(1) π
okay bestie, welcome to osm2pgsql(1), the manual page for the little program that takes OpenStreetMap data and yeets it into PostgreSQL. she's iconic, she's essential, and she's about to become your whole personality. let's go π¦
β¨ NAME β¨
osm2pgsql β OpenStreetMap data to PostgreSQL converter. literally what it says on the tin, no cap.
π SYNOPSIS π
osm2pgsql [OPTIONS] OSM-FILE...
π DESCRIPTION π
okay so osm2pgsql imports OpenStreetMap data into a PostgreSQL/PostGIS database. and likeβ¦ she is not a side character. she's an essential part of so many rendering toolchains, the Nominatim geocoder, and a whole bunch of other applications out here processing OSM data. main character energy, fr fr. π
osm2pgsql can run in either βcreateβ mode (the default) or in βappendβ mode (that's the -a, --append option, remember her).
In βcreateβ mode, osm2pgsql will create the database tables required by the configuration and import the OSM file(s) you specified on the command line into those tables. > heads up bestie: you also have to use the -s, --slim option if you want your database to be updatable. no slim, no updates, that's the rule. π
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 for more information. (yes, there's more. she's got layers. π)
π 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. equality. no favorites. β¨
π₯ MAIN OPTIONS π₯
-a,--appendβ Run in append mode. Adds the OSM change file into the database without removing existing data. she's adding, not deleting, we love a non-destructive queen. π«Ά-c,--createβ Run in create mode. This is the default if-a,--appendis not specified. > Removes existing data from the database tables! β οΈ like, GONE gone. be so careful bestie, this one does not play. π
β HELP/VERSION OPTIONS β
-h,--helpβ Print help. she's telling you how to use her, take notes. π-V,--versionβ Printosm2pgsqlversion. identification era. π
πΈ LOGGING OPTIONS πΈ
--log-level=LEVELβ Set log level (debug,info(default),warn, orerror). pick your chatter level. π€«--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. cute AND smart. π§--log-sqlβ Enable logging of SQL commands for debugging. nosy in a helpful way. π--log-sql-dataβ Enable logging of all data added to the database. > This will write out a huge amount of data! For debugging. like, your disk will feel it. proceed with intention. π-v,--verboseβ Same as--log-level=debug. short and loud. π
π DATABASE 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. versatile icon.-U,--username=NAME,--user=NAMEβ Postgresql user name. that's who you are now. π-W,--passwordβ Force password prompt. no sneaky autofill, she's asking you directly. π-H,--host=HOSTNAMEβ Database server hostname or unix domain socket location. where she lives. π-P,--port=PORTβ Database server port. the door number. πͺ--schema=SCHEMAβ Default for various schema settings throughoutosm2pgsql(default:public). The schema must exist in the database and be writable by the database user. no schema, no service. π
π¦ INPUT OPTIONS π¦
-r,--input-reader=FORMATβ Select format of the input file. Available choices areauto(default) for autodetecting the format,xmlfor OSM XML format files,o5mfor o5m formatted files andpbffor OSM PBF binary format. she can read the room AND the file. β-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. cropping era, we love a rectangle. π²
π MIDDLE OPTIONS π
-i,--tablespace-index=TABLESPCβ Store all indexes in the PostgreSQL tablespaceTABLESPC. This option also affects the tables created by thepgsqloutput. > This option is deprecated. Use the--tablespace-slim-indexand/or--tablespace-main-indexoptions instead. she's retired but still showing up to the party, yk? β οΈ--tablespace-slim-data=TABLESPCβ Store the slim mode tables in the given tablespace. putting things in their designated spot. π¦--tablespace-slim-index=TABLESPCβ Store the indexes of the slim mode tables in the given tablespace. and the indexes get their own spot too. organized queen. π-p,--prefix=PREFIXβ Prefix for table names (default:planet_osm). everything gets a little name tag. π·οΈ-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. tl;dr: slim mode is the low-RAM bestie but she takes her time. π’--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. so basically: drop = smaller and faster, but no more updates. choose your fighter. π-C,--cache=NUMβ Only for slim mode: Use up toNUMMB of RAM for caching nodes. Givingosm2pgsqlsufficient 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 ofshared_buffersgiven in its configuration. Defaults to800. math girlie mathing. π’-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. the whole backstory, not just the plot. π-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--dropto remove it (but you canβt do updates then). efficiency queen but she leaves her stuff everywhere. ποΈ--middle-schema=SCHEMAβ Use PostgreSQL schemaSCHEMAfor 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. she'll take the hand-me-down schema, it's fine. π«Ά--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. exceptions get made for the tagged ones. β¨
π OUTPUT OPTIONS π
-O,--output=OUTPUTβ Specifies the output to use. Currentlyosm2pgsqlsupportspgsql,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.flexis the glow-up,pgsqlis the nostalgic one,nullis doing absolutely nothing and that's her job. π-S,--style=FILEβ The style file. This specifies how the data is imported into the database, its format depends on the output. (For thepgsqloutput, the default is/usr/share/osm2pgsql/default.style, for other outputs there is no default.) the vibe guide for your import. π
okay that's part one of the girlies' guide to osm2pgsql(1)β¦ πΈ
π₯ PGSQL OUTPUT OPTIONS π₯
okay bestie this is the BIG one, the section where the actual database tables get their lil personalities π
--tablespace-main-data=TABLESPCβ drop the data tables into the PostgreSQL tablespace you name in TABLESPC. that's it, that's the whole job.--tablespace-main-index=TABLESPCβ same energy but for the indexes, parked in the PostgreSQL tablespace TABLESPC.--latlongβ store coordinates in degrees of latitude & longitude. simple, classic, retro π¦-m,--mercβ store coordinates in Spherical Mercator (Web Mercator,EPSG:3857). and bestie, this one is the default β¨ so if you do nothing at all, this is what you get.-E,--proj=SRIDβ use projectionEPSG:SRID. you pick the SRID, it obeys π-p,--prefix=PREFIXβ sets the prefix for table names (default:planet_osm). and heads up, this is a double-dipper: it affects the middle tables and the pgsql output table names. one prefix, two jobs, iconic.--tag-transform-script=SCRIPTβ hand it a Lua SCRIPT and it'll do your tag filtering and normalisation for you π§ the script holds callback functions for nodes, ways and relations; each one takes a set of tags and gives you back a transformed, filtered set of tags which then get written to the database. glow up for your tags fr fr.-x,--extra-attributesβ include the attributes: user name, user id, changeset id, timestamp and version. β οΈ this ALSO needs extra entries in your style file, so don't forget that part or you'll be sad.-k,--hstoreβ adds tags that don't have their own column into an extra hstore (key/value) column in the database tables.-j,--hstore-allβ adds ALL the tags to an extra hstore (key/value) column in the database tables. every single one. no crumbs left behind π-z,--hstore-column=PREFIXβ adds an extra hstore (key/value) column namedPREFIXthat holds every tag whose key starts with that prefix. for example,--hstore-column "name:"will produce an extra hstore column containing all thename:xxtags. the way that little trick worksβ¦ obsessed.--hstore-match-onlyβ only keep objects that have a value in at least one of the non-hstore columns. picky? yes. useful? also yes.--hstore-add-indexβ builds indexes for all hstore columns after the import. post-import glow-up πΈ-G,--multi-geometryβ so normally osm2pgsql splits multi-part geometries into separate database rows per part, which means a single OSM object can end up using several rows in the output tables. with this option it instead generates multi-geometry features right in the PostgreSQL tables. one object, one feature, main character energy π-K,--keep-coastlinesβ keep the coastline data instead of filtering it out. by default, objects taggednatural=coastlineget discarded, based on the assumption that the Shapefiles generated by OSMCoastline (https://osmdata.openstreetmap.de/) will be used for coastline data. so likeβ¦ if you're not using those shapefiles, flip this on, bestie π«Ά--reproject-areaβ compute the area column using spherical mercator coordinates even if you're using a different projection for the geometries. yes, you can mix, no, it's not a typo.--output-pgsql-schema=SCHEMAβ use PostgreSQL schema SCHEMA for all the tables, indexes, and functions in the pgsql output. π¨ the schema has to already exist in the database and be writable by the database user. by default it uses whatever you set with--schema, orpublicif you never set that. so if you get an error about a missing schemaβ¦ that's why π
β° EXPIRE OPTIONS β°
the "tell the renderers what to redraw" corner of the party π
-e,--expire-tiles=[MIN_ZOOM-]MAX-ZOOMβ create a tile expiry list. note the shape of the value: the MIN_ZOOM part is optional and the dash is only there if you use it.-o,--expire-output=FILENAMEβ the output file name for the expired tiles list. name your file, bestie π--expire-bbox-size=SIZEβ max size for a polygon to expire the whole polygon rather than just the boundary. big shapes get the full treatment instead of an outline.
π§ ADVANCED OPTIONS π§
for when you're feeling brave. no cap.
-I,--disable-parallel-indexingβ disables parallel clustering and index building on all tables, so it builds one index after the other. slower, but one at a time, like a polite little queue π’--number-processes=THREADSβ specifies the number of parallel THREADS used for certain operations. turn it up if your machine can handle the drama π₯
π SEE ALSO π
- π osm2pgsql website
- π osm2pgsql manual
- π
postgres(1) - π
osmcoastline(1)
and that's the whole page, bestie!! π this was osm2pgsql version 2.3.1, and you were reading OSM2PGSQL(1) β go build some tiles, you absolute icon π
β¨π
π¦ where this page comes from
- arch rolling: osm2pgsql 2.3.1-1 Β· GPL-2.0-only
- nixpkgs unstable: osm2pgsql 2.3.1
- ubuntu stonking: osm2pgsql 2.3.1+ds-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms