In order to perform some routing analysis, we need the data first. You may obtain the data from different sources, we will use two of them - OSM data delivered in SHP format and OpenStreetMap data.
We will store the data in a new schema - pgr.
Note
pgr is a prefix used by the pgRouting functions, so our schema fits perfectly in the naming convention.
In this example, we will use an example of a routable shapefile downloaded from GeoFabrik.de - https://www.geofabrik.de/data/shapefiles_routable_vienna.zip. A routable shapefile, as GeoFabrik describes it, is a standard shapefile that contains OSM data preprocessed with routing in mind. This means it contains only road data with lines split at intersections, with some speed limits information, road line lengths, and so on.
We have already addressed importing shapefiles to PostGIS, so you can use a tool of your choice; in this case, I am using osm2pgsql:
shp2pgsql -s 4326 roads pgr.shp_roads | psql -h localhost...