osm_fdw
osm_fdw · Foreign data wrapper for reading OpenStreetMap PBF files
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100102 | osm_fdw | osm_fdw | 4.1.2 | FDW | PostgreSQL | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
osm_fdw is a read-only foreign data wrapper for OpenStreetMap PBF files. It exposes OSM nodes, ways, and relations as rows so they can be transformed with SQL before being copied into ordinary PostgreSQL tables or materialized views.
Core Workflow
create_osm_table(table_name, server_name, filename) creates the required foreign-table layout. A manual definition must keep the documented column order and types:
Row Model
type is NODE, WAY, or RELATION. Coordinates are populated for nodes, refs contains node identifiers for ways, and members contains relation members. tags stores the OSM tag map as jsonb; the remaining columns expose version and contributor metadata.
Caveats
The PostgreSQL server process must be able to read the file path. The FDW rereads the PBF file for every query and does not provide indexes over the source, so upstream recommends materializing or copying data and then creating normal PostgreSQL indexes. Treat the file as an external snapshot: refresh derived tables explicitly when it changes. Preserve column position as well as type in manual foreign tables, and test large extracts because scans decode the source file again. No preload or restart is required.