1OSM2PGSQL(1) OSM2PGSQL(1)
2
3
4
6 osm2pgsql - Openstreetmap data to PostgreSQL converter
7
9 osm2pgsql [OPTIONS] OSM-FILE...
10
12 osm2pgsql imports OpenStreetMap data into a PostgreSQL/PostGIS data‐
13 base. It is an essential part of many rendering toolchains, the Nomi‐
14 natim geocoder and other applications processing OSM data.
15
16 osm2pgsql can run in either “create” mode (the default) or in “append”
17 mode (option -a, --append).
18
19 In “create” mode osm2pgsql will create the database tables required by
20 the configuration and import the OSM file(s) specified on the command
21 line into those tables. Note that you also have to use the -s, --slim
22 option if you want your database to be updateable.
23
24 In “append” mode osm2pgsql will update the database tables with the
25 data from OSM change files specified on the command line.
26
27 This man page can only cover some of the basics and describe the com‐
28 mand line options. See the Osm2pgsql Manual
29 (https://osm2pgsql.org/doc/manual.html) for more information.
30
32 This program follows the usual GNU command line syntax, with long op‐
33 tions starting with two dashes (--). Mandatory arguments to long op‐
34 tions are mandatory for short options too.
35
37 -a, --append
38 Run in append mode. Adds the OSM change file into the database
39 without removing existing data.
40
41 -c, --create
42 Run in create mode. This is the default if -a, --append is not
43 specified. Removes existing data from the database tables!
44
46 -h, --help
47 Print help. Add -v, --verbose to display more verbose help.
48
49 -V, --version
50 Print osm2pgsql version.
51
53 --log-level=LEVEL
54 Set log level (`debug', `info' (default), `warn', or `error').
55
56 --log-progress=VALUE
57 Enable (true) or disable (false) progress logging. Setting this
58 to auto will enable progress logging on the console and disable
59 it if the output is redirected to a file. Default: true.
60
61 --log-sql
62 Enable logging of SQL commands for debugging.
63
64 --log-sql-data
65 Enable logging of all data added to the database. This will
66 write out a huge amount of data! For debugging.
67
68 -v, --verbose
69 Same as --log-level=debug.
70
72 -d, --database=NAME
73 The name of the PostgreSQL database to connect to. If this pa‐
74 rameter contains an = sign or starts with a valid URI prefix
75 (postgresql:// or postgres://), it is treated as a conninfo
76 string. See the PostgreSQL manual for details.
77
78 -U, --username=NAME
79 Postgresql user name.
80
81 -W, --password
82 Force password prompt.
83
84 -H, --host=HOSTNAME
85 Database server hostname or unix domain socket location.
86
87 -P, --port=PORT
88 Database server port.
89
91 -r, --input-reader=FORMAT
92 Select format of the input file. Available choices are auto
93 (default) for autodetecting the format, xml for OSM XML format
94 files, o5m for o5m formatted files and pbf for OSM PBF binary
95 format.
96
97 -b, --bbox=MINLON,MINLAT,MAXLON,MAXLAT
98 Apply a bounding box filter on the imported data. Example:
99 --bbox -0.5,51.25,0.5,51.75
100
102 -i, --tablespace-index=TABLESPC
103 Store all indexes in the PostgreSQL tablespace TABLESPC. This
104 option also affects the tables created by the pgsql output.
105
106 --tablespace-slim-data=TABLESPC
107 Store the slim mode tables in the given tablespace.
108
109 --tablespace-slim-index=TABLESPC
110 Store the indexes of the slim mode tables in the given ta‐
111 blespace.
112
113 -p, --prefix=PREFIX
114 Prefix for table names (default: planet_osm).
115
116 -s, --slim
117 Store temporary data in the database. Without this mode, all
118 temporary data is stored in RAM and if you do not have enough
119 the import will not work successfully. With slim mode, you
120 should be able to import the data even on a system with limited
121 RAM, although if you do not have enough RAM to cache at least
122 all of the nodes, the time to import the data will likely be
123 greatly increased.
124
125 --drop Drop the slim mode tables from the database and the flat node
126 file once the import is complete. This can greatly reduce the
127 size of the database, as the slim mode tables typically are the
128 same size, if not slightly bigger than the main tables. It does
129 not, however, reduce the maximum spike of disk usage during im‐
130 port. It can furthermore increase the import speed, as no in‐
131 dexes need to be created for the slim mode tables, which (de‐
132 pending on hardware) can nearly halve import time. Slim mode
133 tables however have to be persistent if you want to be able to
134 update your database, as these tables are needed for diff pro‐
135 cessing.
136
137 -C, --cache=NUM
138 Only for slim mode: Use up to NUM MB of RAM for caching nodes.
139 Giving osm2pgsql sufficient cache to store all imported nodes
140 typically greatly increases the speed of the import. Each
141 cached node requires 8 bytes of cache, plus about 10% - 30%
142 overhead. As a rule of thumb, give a bit more than the size of
143 the import file in PBF format. If the RAM is not big enough,
144 use about 75% of memory. Make sure to leave enough RAM for
145 PostgreSQL. It needs at least the amount of shared_buffers
146 given in its configuration. Defaults to 800.
147
148 --cache-strategy=STRATEGY
149 There are a number of different modes in which osm2pgsql can or‐
150 ganize its node cache in RAM. These are optimized for different
151 assumptions of the data and the hardware resources available.
152 Currently available strategies are dense, chunked, sparse and
153 optimized. dense assumes that the node id numbers are densely
154 packed, i.e. only a few IDs in the range are missing / deleted.
155 For planet extracts this is usually not the case, making the
156 cache very inefficient and wasteful of RAM. sparse assumes node
157 IDs in the data are not densely packed, greatly increasing
158 caching efficiency in these cases. If node IDs are densely
159 packed, like in the full planet, this strategy has a higher
160 overhead for indexing the cache. optimized uses both dense and
161 sparse strategies for different ranges of the ID space. On a
162 block by block basis it tries to determine if it is more effec‐
163 tive to store the block of IDs in sparse or dense mode. This is
164 the default and should be typically used.
165
166 -x, --extra-attributes
167 Include attributes of each object in the middle tables and make
168 them available to the outputs. Attributes are: user name, user
169 id, changeset id, timestamp and version.
170
171 --flat-nodes=FILENAME
172 The flat-nodes mode is a separate method to store slim mode node
173 information on disk. Instead of storing this information in the
174 main PostgreSQL database, this mode creates its own separate
175 custom database to store the information. As this custom data‐
176 base has application level knowledge about the data to store and
177 is not general purpose, it can store the data much more effi‐
178 ciently. Storing the node information for the full planet re‐
179 quires more than 300GB in PostgreSQL, the same data is stored in
180 “only” 50GB using the flat-nodes mode. This can also increase
181 the speed of applying diff files. This option activates the
182 flat-nodes mode and specifies the location of the database file.
183 It is a single large file. This mode is only recommended for
184 full planet imports as it doesn't work well with small imports.
185 The default is disabled.
186
187 --middle-schema=SCHEMA
188 Use PostgreSQL schema SCHEMA for all tables, indexes, and func‐
189 tions in the middle (default is no schema, i.e. the public
190 schema is used).
191
192 --middle-way-node-index-id-shift=SHIFT
193 Set ID shift for way node bucket index in middle. Experts only.
194 See documentation for details.
195
197 -O, --output=OUTPUT
198 Specifies the output back-end to use. Currently osm2pgsql sup‐
199 ports pgsql, flex, gazetteer and null. pgsql is the default
200 output back-end and is optimized for rendering with Mapnik.
201 gazetteer is intended for geocoding with Nominatim. The experi‐
202 mental flex backend allows more flexible configuration. null
203 does not write any output and is only useful for testing or with
204 --slim for creating slim tables. There is also a multi backend.
205 This is now deprecated and will be removed in future versions of
206 osm2pgsql.
207
208 -S, --style=FILE
209 The style file. This specifies how the data is imported into
210 the database, its format depends on the output. (For the pgsql
211 output, the default is /usr/share/osm2pgsql/default.style, for
212 other outputs there is no default.)
213
215 -i, --tablespace-index=TABLESPC
216 Store all indexes in the PostgreSQL tablespace TABLESPC. This
217 option also affects the middle tables.
218
219 --tablespace-main-data=TABLESPC
220 Store the data tables in the PostgreSQL tablespace TABLESPC.
221
222 --tablespace-main-index=TABLESPC
223 Store the indexes in the PostgreSQL tablespace TABLESPC.
224
225 --latlong
226 Store coordinates in degrees of latitude & longitude.
227
228 -m, --merc
229 Store coordinates in Spherical Mercator (Web Mercator,
230 EPSG:3857) (the default).
231
232 -E, --proj=SRID
233 Use projection EPSG:SRID.
234
235 -p, --prefix=PREFIX
236 Prefix for table names (default: planet_osm). This option af‐
237 fects the middle as well as the pgsql output table names.
238
239 --tag-transform-script=SCRIPT
240 Specify a Lua script to handle tag filtering and normalisation.
241 The script contains callback functions for nodes, ways and rela‐
242 tions, which each take a set of tags and returns a transformed,
243 filtered set of tags which are then written to the database.
244
245 -x, --extra-attributes
246 Include attributes (user name, user id, changeset id, timestamp
247 and version). This also requires additional entries in your
248 style file.
249
250 -k, --hstore
251 Add tags without column to an additional hstore (key/value) col‐
252 umn in the database tables.
253
254 -j, --hstore-all
255 Add all tags to an additional hstore (key/value) column in the
256 database tables.
257
258 -z, --hstore-column=PREFIX
259 Add an additional hstore (key/value) column named PREFIX con‐
260 taining all tags that have a key starting with PREFIX, eg
261 \--hstore-column "name:" will produce an extra hstore column
262 that contains all name:xx tags.
263
264 --hstore-match-only
265 Only keep objects that have a value in at least one of the
266 non-hstore columns.
267
268 --hstore-add-index
269 Create indexes for all hstore columns after import.
270
271 -G, --multi-geometry
272 Normally osm2pgsql splits multi-part geometries into separate
273 database rows per part. A single OSM object can therefore use
274 several rows in the output tables. With this option, osm2pgsql
275 instead generates multi-geometry features in the PostgreSQL ta‐
276 bles.
277
278 -K, --keep-coastlines
279 Keep coastline data rather than filtering it out. By default
280 objects tagged natural=coastline will be discarded based on the
281 assumption that Shapefiles generated by OSMCoastline
282 (https://osmdata.openstreetmap.de/) will be used for the coast‐
283 line data.
284
285 --reproject-area
286 Compute area column using spherical mercator coordinates even if
287 a different projection is used for the geometries.
288
289 --output-pgsql-schema=SCHEMA
290 Use PostgreSQL schema SCHEMA for all tables, indexes, and func‐
291 tions in the pgsql and multi outputs (default is no schema,
292 i.e. the public schema is used).
293
295 -e, --expire-tiles=[MIN_ZOOM-]MAX-ZOOM
296 Create a tile expiry list.
297
298 -o, --expire-output=FILENAME
299 Output file name for expired tiles list.
300
301 --expire-bbox-size=SIZE
302 Max size for a polygon to expire the whole polygon, not just the
303 boundary.
304
306 -I, --disable-parallel-indexing
307 Disable parallel clustering and index building on all tables,
308 build one index after the other.
309
310 --number-processes=THREADS
311 Specifies the number of parallel threads used for certain opera‐
312 tions.
313
314 --with-forward-dependencies=BOOL
315 Propagate changes from nodes to ways and node/way members to re‐
316 lations (Default: true).
317
319 • osm2pgsql website (https://osm2pgsql.org)
320
321 • osm2pgsql manual (https://osm2pgsql.org/doc/manual.html)
322
323 • postgres(1)
324
325 • osmcoastline(1)
326
327
328
329 1.4.1 OSM2PGSQL(1)