PgRouting (an official OSGeo community project extending PostGIS and PostgreSQL under the GPL-2.0-or-later license) adds high-speed geospatial routing, graph traversal, and network analysis directly inside your SQL database. Written in C++ on top of the Boost Graph Library, pgRouting lets GIS developers, logistics engineers, and web mapping backends calculate shortest paths, driving-distance isochrones, turn-restricted routes, and traveling salesperson solutions directly from road networks stored in PostGIS—eliminating the need to export data to separate desktop routing engines.
1. In-Depth Review: Why GIS & Backend Developers Use pgRouting
- Native SQL Routing Inside PostgreSQL & PostGIS: Runs shortest-path and network graph algorithms right where your spatial tables live, letting you filter roads dynamically with standard SQL `WHERE` clauses (such as speed limits, road classes, or live traffic weights).
- Comprehensive Graph & Routing Algorithm Suite: Includes Dijkstra, A*, Bidirectional Dijkstra/A*, Yen's K-Shortest Paths, Driving Distance (isochrones), Turn Restriction Shortest Path (TRSP), Traveling Salesperson (TSP), and all-pairs cost matrices.
- Seamless OpenStreetMap & QGIS Integration: Pairs cleanly with `osm2pgrouting` to import OpenStreetMap road networks and integrates with QGIS (`pgRoutingLayer`) and web GIS APIs (GeoServer, PostgREST, Node.js, Python).
2. Key Features & Capabilities
- Shortest Path & Alternative Routes: Compute one-to-one, one-to-many, many-to-one, and many-to-many routes using `pgr_dijkstra`, `pgr_aStar`, `pgr_bdDijkstra`, `pgr_bdAstar`, and `pgr_ksp`.
- Driving Distance & Service Area Isochrones: Calculate reachable road networks and catchment areas within time or distance thresholds using `pgr_drivingDistance` and `pgr_withPointsDD`.
- Turn Restrictions & Arbitrary Point Routing: Model real-world turn penalties/prohibitions (`pgr_trsp`) and route from exact mid-segment coordinates (`pgr_withPoints`) rather than snapping only to intersections.
- Traveling Salesperson & Logistics Optimization: Order multi-stop delivery or field-inspection waypoints efficiently with `pgr_TSP` and companion `vrprouting` extensions.
- Topology Building & Graph Analysis: Build network nodes/edges, detect connected components, calculate centrality, and analyze flow capacities directly in SQL.
- 100% Free & Open-Source (OSGeo / GPLv2+): Free for commercial, government, and academic spatial database backends across Linux, Windows, and macOS.

- Official Links: Free Trial, Free / Education & Pricing
Always download pgRouting packages, documentation, and companion import tools directly from official OSGeo and pgRouting portals:
- Official pgRouting Website: https://pgrouting.org/
- Official pgRouting Documentation & SQL Reference: https://docs.pgrouting.org/
- Official OSGeo pgRouting Project Page: https://www.osgeo.org/projects/pgrouting/
- Official pgRouting GitHub Repository & Releases: https://github.com/pgRouting/pgrouting
4. Step-by-Step Installation Guide
- Install PostgreSQL and PostGIS First: Ensure a supported version of PostgreSQL (v14+) and the PostGIS extension are installed and running on your Linux, Windows, or macOS server.
- Install the pgRouting Extension Package: On Ubuntu/Debian, run `sudo apt install postgresql-16-pgrouting` (matching your PostgreSQL major version); on Windows, install via Stack Builder / PostGIS bundle or OSGeo binaries; on macOS, install via Homebrew or Postgres.app.
- Enable PostGIS and pgRouting in Your Database: Connect to your spatial database with `psql` and run `CREATE EXTENSION postgis;` followed by `CREATE EXTENSION pgrouting;`.
- Verify Installation & Version: Run `SELECT pgr_version();` in SQL to confirm pgRouting (such as v4.0.x) is active and ready.
5. How to Use pgRouting: Beginner Workflow
- Prepare a Road Edge Table with Source & Target IDs: Load a road network table (via `osm2pgrouting` or `ogr2ogr`) containing `id`, `source`, `target`, `cost`, `reverse_cost`, and `geom` columns.
- Build Network Topology (If Needed): Ensure `source` and `target` vertex IDs are populated cleanly across connected road segments and indexed for fast graph assembly.
- Run a Shortest-Path SQL Query: Execute a query such as `SELECT * FROM pgr_dijkstra('SELECT id, source, target, cost, reverse_cost FROM ways', 101, 508, directed := true);` to return ordered route segments and cumulative costs.
- Join Route Results Back to Road Geometries: Join the `edge` column from `pgr_dijkstra` back to your `ways` table on `ways.id = route.edge` to retrieve `LineString` geometries.
- Visualize in QGIS or Serve via Web API: Load the SQL query result in QGIS (`DB Manager` or `pgRoutingLayer`) or expose it as GeoJSON through your web GIS backend.

6. Frequently Asked Questions (FAQ)
- Is pgRouting completely free to use in production?Yes. pgRouting is a free and open-source OSGeo project released primarily under the GPL-2.0-or-later license with no per-core or commercial licensing fees.
- Do I need PostGIS installed before enabling pgRouting?Yes. pgRouting is an extension built on top of PostgreSQL and PostGIS, so `CREATE EXTENSION postgis;` must be enabled in your database before creating the `pgrouting` extension.
- Can pgRouting calculate routes from exact GPS coordinates between road intersections?Yes. Functions in the `pgr_withPoints` family allow you to route from fractional positions along any road segment without splitting your base road geometry table.