When teams implement pgRouting for network and route analysis on PostGIS
pgRouting adds routing algorithms to a PostgreSQL database that already holds PostGIS geometry, so shortest path, driving distance and traveling salesperson calculations run where the road, service and asset data lives. The extension extends PostGIS and PostgreSQL with Dijkstra, A*, bidirectional and K-shortest path searches, all-pairs shortest path, driving distance and traveling salesperson functions, according to the pgRouting project. Teams usually reach for it when they already run PostGIS and need route planning, service areas or network tracing without sending their coordinates and asset records to an external routing service. Typical cases include delivery sequencing for logistics fleets, technician dispatch and travel-time service areas for field service, and tracing upstream or downstream connectivity through road, pipe or electrical network models.
Teams keep the routing engine next to their geospatial data for three practical reasons. Routing results join directly with customer, asset and permit tables in the same SQL statements, so access control, auditing and backups stay under one database administrator. Network changes are also reflected immediately: pgRouting works against the graph tables in the database, so a closed road segment or a newly energized line affects the next query without a separate reload step. Finally, the data stays inside infrastructure the organization controls, which matters when the network describes critical infrastructure.
The work is a database and data project as much as a routing one. Before any algorithm is chosen, the team must decide how the network is modeled: which edge and node tables exist, how topology is built and validated, which cost columns represent travel time, distance or capacity, and who owns updates when the source data changes. Those decisions determine query speed, data quality and recovery after a failed import. Teams should confirm with their PostGIS version and their pgRouting release which functions and compatibility notes apply, because the extension is versioned alongside PostgreSQL and PostGIS.
What pgRouting does on top of PostGIS
pgRouting adds graph algorithms to PostGIS, so each routing question runs as SQL against tables you already own. The cards below cover the functions pgRouting documents and the one property that shapes how you design updates: changes to network data reach the routing engine immediately.
Shortest path with Dijkstra
Dijkstra's algorithm answers the question "what is the lowest-cost route between two nodes?" for a planner choosing a route through roads, pipes or cable runs. It needs a network table with a source and target node for each edge, a cost column, and a reverse cost column if the edges are one-way or cost differently in each direction. Check that every edge carries a valid cost before you trust the output, because a null or negative cost changes the result without raising an obvious error.
pgRouting docsFaster search with A*
A* answers the same point-to-point question as Dijkstra but uses a heuristic, usually straight-line distance from each node to the destination, to explore fewer nodes. It needs node coordinates in addition to the edge costs, so the network table must carry geometry that matches the cost units. Confirm that the heuristic never overestimates the true remaining cost, since an overestimate can return a route that is not the cheapest one.
Two-sided search with bidirectional
Bidirectional search runs the shortest-path search from both ends and meets in the middle, which suits long routes across a large network where a single-direction search would expand many nodes. An analyst uses it when the origin and destination are both known and the question is a single route. Test it against your one-directional results on a sample of routes, since the output should match and any difference points to a costing or topology problem.
Alternative routes with K-shortest path
K-shortest path returns the best several routes between two nodes, not only the single best one. Planners use it to compare a primary corridor with backup options, for example when assessing how a utility network can be rerouted after a fault. Results can overlap heavily on small networks, so review whether the alternatives are genuinely different corridors before you present them as options.
Every-to-every distances with all-pairs
All-pairs shortest path computes costs between every pair of nodes in a network, which analysts use to build distance matrices for depot placement or service area studies. The output grows with the square of the node count, so it can become very large on a full road or utility graph. Scope the input to the area or node set you need and confirm storage capacity before running it on the full network.
- Data change effect
- Immediate
Reach areas with driving distance
Driving distance answers "what can be reached from this node within a given cost?" for a planner defining a service area, a response zone or a catchment. It needs the same costed network as shortest path, plus a cost limit chosen for the use case. Verify edge costs against the units you report, such as minutes or meters, because a mismatch shifts the boundary of the reachable area without any error message.
Visit order with traveling salesperson
The traveling salesperson functions find an efficient order for visiting a set of locations and returning to the start, which suits route planning for field crews, inspection rounds or delivery stops. The problem is hard to solve exactly at scale, so the functions return good solutions rather than guaranteed optima on large sets. Limit the stop count you send in each run and compare the result against your operational constraints before dispatching work.
Configuration decisions to settle before loading a network
This table compares the decisions that shape a pgRouting build, with the options for each, when they fit and what changing them later costs. Read it before loading any road or utility data, because the network model and update path are the hardest choices to reverse once applications depend on them.
| Decision | Options | When each fits | What changing it later costs |
|---|---|---|---|
| Edge geometry and topology | Line geometries with a topology build step, or pre-split edges at intersections | Topology build suits road data from a single source; pre-split edges suit data that already marks every junction | Rebuilding the topology and re-deriving node IDs touches every route and cost column, so plan a full reload and regression tests |
| Node identifiers | Generated node IDs maintained by pgRouting, or stable source IDs carried through | Stable source IDs help when routes must match records in an asset system or GIS | Changing identifier scheme breaks saved routes, outage records and any external references |
| Cost and reverse cost columns | Single cost per direction, asymmetric costs from attributes, or time-dependent values kept outside the base table | Asymmetric costs fit one-way streets or valve direction; separate cost columns suit multiple vehicle or network profiles | Adding profiles means new columns, new indexes and recomputed results; reverse cost rules are hard to audit after data is loaded |
| Algorithm per use case | Dijkstra or A* for point-to-point, driving distance for reach areas, traveling salesperson for multi-stop sequencing | A* needs coordinates on every node; driving distance suits service areas; traveling salesperson suits dispatch of a small number of stops | Switching algorithms is usually cheap, but cost columns or heuristics designed for one may give poor results for another |
| Database placement | Routing tables in the same PostGIS database as source data, or a separate routing database fed by replication or export | Same database keeps data current automatically; a separate instance isolates query load and access rules | Moving later means a new connection path, new permissions and a sync job to build and monitor |
| Update path | Scheduled batch reload of the network, or incremental edits to edges and costs | Batch reload fits data that changes on a fixed cycle; incremental edits fit operational networks with frequent changes | Batch reload needs rebuild windows and cache refresh; incremental edits need change tracking and topology repair for each edit |
| Data scope | Full network, a bounding region, or a subset by class or voltage level | Subsets reduce size and exposure; full networks support cross-region routes | Expanding scope later means reloading and re-indexing, and may expose data outside the original access approval |
| Regulated utility data scope | Public road extract, or utility network data classified under the entity's own information protection rules | Public extracts can be shared freely; utility topology may fall under NERC CIP information protection or similar rules | Reclassifying a loaded network means reviewing copies, backups and replicas, and confirming with compliance staff which controls apply |
How the routing graph is built from line geometry
A routing engine does not read road or utility lines directly. It works on a graph, where each line segment becomes an edge, each point where segments meet becomes a node, and each edge carries cost attributes such as length, travel time or capacity. Building that graph is a separate step from loading the geometry, and most routing problems trace back to it. In pgRouting, the topology step scans the edge table, creates or matches nodes at shared endpoints, and writes the source and target identifiers that routing functions use. Edges that should connect but do not share an endpoint will be invisible to the router, so the topology step is where you find out whether your data forms a network at all.
Before building topology, check the source geometry for four problems. Gaps are lines that stop a few centimeters short of a junction, so they never touch the neighboring segment; a snapping tolerance can close them, but it must be chosen for your coordinate system and not copied from an example. Duplicates are the same centerline loaded twice, often from merged survey or import files, which produce parallel edges with conflicting costs. Disconnected segments are fragments that belong to no network component and usually signal a missing or split feature. One-way attributes need the same scrutiny: confirm that the field your data uses for direction maps correctly to the forward and reverse cost columns, because a flipped digitizing direction silently reverses traffic. Record the counts for each check before and after cleaning, so you can show what changed.
Confirm the exact function names, argument lists and cost column conventions against the pgRouting documentation for the version you install, since topology and graph-building functions have changed between releases. Start at the pgRouting project site to find the documentation for your version. For utility networks, the same logic applies, but the direction attribute often means energized or flow direction rather than traffic rules, and a disconnected segment may be a real isolation boundary rather than an error. Agree with the data owner which of these conditions are data defects and which are the network itself before you change anything.
How a pgRouting build runs from install to handover
The sequence moves from confirming the database versions to a handed-over network that routes correctly, updates on a defined schedule and can be operated by the client's own team. Each step ends with a named output the client keeps.
Confirm PostgreSQL and PostGIS versions
Before anything is installed, the team checks which PostgreSQL major version the server runs and when that version leaves support, using the PostgreSQL versioning policy. The PostGIS version is matched to that PostgreSQL major and the pgRouting release is matched to both. Ask the client whether a major upgrade is planned within the expected life of the routing service, because it changes which pgRouting build is needed. The output is a compatibility record listing PostgreSQL, PostGIS and pgRouting versions and their support end dates.
Install pgRouting beside PostGIS
The team installs the pgRouting extension on the existing PostGIS database in a staging environment first, then repeats the same install on production using the same package source and version. Extension creation is recorded in migration scripts so a rebuild produces the same result. The check is that the extension loads, its functions are listed in the target schema and a trivial test graph returns a path. The output is a tested install script and a short environment record.
Load and clean the network
Road, rail or utility network data is imported into staging tables and checked for duplicate segments, null geometries, disconnected islands, direction flags that contradict the source and coordinate system mismatches. The client's data owner signs off on which exceptions are accepted and which are corrected at source. The output is a cleaned network table and a log of every correction, with counts of what was removed or changed.
Build topology and cost columns
The team builds the routing topology so that segments share nodes where they meet, then derives cost and reverse-cost columns from attributes such as length, speed, restriction or capacity. Cost rules are written down as SQL so the client can read them. The check is that sampled nodes connect to their neighbors and that one-way rules produce the expected directions. The output is a topology build script and a documented cost model.
Validate costs against known routes
A set of routes whose answers are already known from the client's operators, field crews or trusted mapping results is run through the functions for shortest path and driving distance. Results are compared on distance, travel cost and the sequence of segments, and differences are traced to cost rules or topology gaps. Illustrative example: a depot-to-substation route that crews drive daily should appear among the results with a similar cost. The output is an accepted test route set with expected results and a list of resolved discrepancies.
Define the update and reload process
The team designs how source changes reach the routing tables, including who supplies changes, how often they are applied, how edited segments are re-noded and how cost columns are recalculated. pgRouting reflects data changes in the routing engine immediately, so the main design question is which edits are allowed into the live table and which go through staging first. The output is an update runbook with change intake, validation queries and rollback steps.
Run performance tests on realistic queries
The team runs the expected query mix against the full network, including long-distance paths, many-stop traveling salesperson requests and driving distance runs at the sizes the client will use. Execution times, memory use and index usage are recorded, and the functions and indexes are tuned where needed. Load results are compared with the service's expected concurrency. The output is a performance report with the query set, measured results and the tuning changes applied.
Secure access and hand over runbooks
Database roles are set so routing users can read network tables while only the update role can write them, and connections use the authentication method the client's policy requires. The team then walks the client's operators through the update runbook, the test route set and the restore procedure for the routing schema, and confirms that the client's staff can run one update end to end. The output is a secured database configuration, signed runbooks and a handover record naming who can operate the service.
What drives pgRouting effort and cost
This table lists the factors that move the effort and cost of a pgRouting build, and whether each one is paid once or recurs. Read it before requesting a quote, so the written scope states the network size, cost models, update cadence and upgrade plan that the price depends on.
| Driver | Why it changes effort or cost | One-time or recurring | What to ask for in a quote |
|---|---|---|---|
| Source network size and quality | Large or inconsistent road, pipe or cable graphs need more cleaning, topology building and node snapping before routing works correctly. | One-time, with recurring cleanup when sources change | Row counts, source formats, expected topology checks and who owns gap and error fixes |
| Number of cost models | Each cost model (travel time, distance, vehicle height or weight rules, asset capacity) needs its own attribute design, test cases and validation. | One-time per model, plus upkeep as rules change | List of cost models, their attributes, and the test routes that prove each one |
| Update frequency and automation | Frequent map or asset edits need scheduled loads, change detection and routing checks, which cost more to build than a yearly refresh. | Recurring when automation runs and needs monitoring | Update cadence, load method, rollback plan and who receives failed-job alerts |
| Data licensing | Commercial map data or utility records may limit redistribution, caching and use in derived outputs, which shapes the architecture and legal review. | One-time review, with recurring license fees if applicable | Named data sources, license terms reviewed, and who signs off on permitted use |
| Regulatory scope | If the network data falls under a regime such as NERC CIP or NIS2, access control, change records, vendor and supply chain evidence add work and retained documentation. | One-time design, recurring evidence collection | Which regulations apply, the evidence the assessor expects, and the controls the partner will deliver |
| High availability and backups | A routing service that dispatch or operations depend on needs replicas, tested point-in-time recovery and restore drills, each adding infrastructure and testing. | One-time build, recurring backup storage and restore testing | Replication design, recovery targets set by your team, and restore test frequency |
| Planned PostgreSQL major upgrades | PostGIS and pgRouting must be matched to the new PostgreSQL major before cutover, so each upgrade repeats compatibility and regression testing. | Recurring, once per major version in the support window | Target PostgreSQL version, matching PostGIS and pgRouting versions, and the regression routes to rerun |
| Graph size and query load | Large graphs and many concurrent route requests need memory, indexing and sizing tests, which can require more hardware. | One-time sizing, with recurring infrastructure cost | Expected graph size, peak request rate, and a load test plan before sign-off |
How source network data reaches the routing functions
The diagram starts with authoritative network sources, such as road or utility data exports, which pass through a staging and validation step before anything is loaded into PostGIS tables. Validated data is then loaded into the routing graph, where pgRouting functions read it and return results to a routing API or analysts. The update path (loading and rebuilding the network) is drawn separately from the query path (routing requests), so the team can see where write access exists. Check that the validation step rejects topology errors and that the trust boundary around the database and any regulated network data is enforced.
Update path loads and validates network data before routing queries read it.
When utility network data brings NERC CIP and NIS2 into scope
pgRouting carries no compliance certification of its own, so scope comes from the data it routes and the systems that consume the results. A routing database built on PostGIS is not regulated because of the extension. It becomes regulated when it holds or supports BES Cyber Systems, the grid assets that NERC CIP covers, or when the operator it serves falls under NIS2. Under NERC CIP-002-5.1a, each BES Cyber System is sorted into high, medium or low impact using bright-line criteria. High impact mainly covers qualifying control centers, and medium impact includes, for example, generation of 1500 MW or more at one plant or transmission facilities at 500 kV or higher. A utility network model that feeds switching, dispatch or restoration tools may therefore sit inside that classification even though the routing engine itself looks like ordinary analytics code.
Once a system is classified, the hosting design changes. CIP-005-7 requires routable-connected assets of high and medium impact BES Cyber Systems to sit inside an Electronic Security Perimeter, and it requires all Interactive Remote Access to pass through an Intermediate System with encryption and multi-factor authentication. CIP-013-2 adds supply chain risk management, which covers vendor incident notification, vulnerability disclosure, software integrity and authenticity verification, and coordination of vendor-initiated remote access. That plan must be reviewed at least every 15 calendar months, so a PostGIS and pgRouting stack deployed for an in-scope operator needs its software sourcing and patch process documented, including who verifies each extension build. NIS2 Annex I lists energy as a high-criticality sector, and it lists drinking water and waste water separately, so a utility in the EU may have obligations that do not depend on NERC.
Ask your compliance lead for a written classification decision before any hosting design starts. That decision should name the BES Cyber Systems, the impact level, the NIS2 sector and whether the routing database is in scope or only receives exported data. DeployOpen can prepare the system descriptions, network diagrams, access records and supply chain evidence that an assessment will request, but independent auditors and regulators issue the results, and DeployOpen does not issue audit reports or attestations. Confirm current enforcement dates on the NERC CIP standards page before planning, since several CIP revisions carry later effective dates.
How pgRouting connects to the rest of the platform
pgRouting runs inside the same PostgreSQL cluster as your spatial data, so its availability, recovery, access and monitoring depend on the surrounding platform. Each connection below needs a deliberate design decision before the routing functions go into production.
PostGIS geometry and spatial indexes
pgRouting works on geometry columns that PostGIS stores and indexes, so the network table, its geometry type and its spatial index all sit on the PostGIS layer. Confirm which PostGIS version your PostgreSQL major supports and that the topology build step (creating source and target node IDs from line geometry) runs after each load. Check that the spatial index on the edge geometry is present and rebuilt after bulk updates, since slow lookups usually trace back to a missing or stale index.
pgRouting docsPostgreSQL high availability
Routing requests read the same network tables that editors and loaders write, so a primary failure stops both. Hot standbys can serve read-only routing queries, but PostgreSQL does not detect failure or promote a standby on its own, so an external failover tool is required. Confirm which routing traffic may run on a standby, how replication lag affects freshly edited network data, and who approves promotion.
HA docsBackups and point-in-time recovery
A corrupted or mistakenly edited road or utility network is expensive to rebuild, so the network tables need the same recovery plan as any other production data. Point-in-time recovery combines a base backup with archived WAL files. Confirm the recovery point you need for network edits, how often restores are tested against a copy of the graph, and whether the network data is restored with the rest of the database or from a separate source.
Archiving docsPgBouncer for application access
Web services and APIs that call routing functions open many short connections, and PgBouncer can pool them so the server is not overwhelmed. Pooling mode affects which session features routing calls can use, so confirm the mode with your application team before deployment. Check the PgBouncer version against the current security advisories, since version 1.26.1 was released on October 14, 2026 with security fixes.
PgBouncer sitePrometheus and Grafana monitoring
Long routing queries on large graphs can exhaust memory or hold locks during network updates, and these show up as slow queries before they show up as outages. Export database metrics to Prometheus and build Grafana panels for query duration, active connections and replication lag. Confirm which thresholds trigger an alert, and that the team has a way to identify the slowest routing calls by function and graph size.
SSO for analyst access
Analysts who run routing studies or edit network data should sign in with the organization's identity provider, not with shared database accounts. PostgreSQL supports directory-based authentication methods such as GSSAPI, LDAP and certificates, so the chosen method must match your identity stack. Confirm which roles can edit network tables versus only run routing queries, and how access is removed when someone changes teams.
Auth methods docsApplication and API calling layer
Most users reach pgRouting through an application or API that builds the source and target node IDs and passes them to a routing function. That layer decides input validation, timeouts, result size and caching, and it must avoid passing unchecked user input into SQL. Confirm the maximum graph area each request can cover, the timeout behavior, and which team owns changes to the routing queries.
What buyers ask before bringing in a partner for pgRouting
How much does a pgRouting implementation cost and what drives it?
The cost depends mainly on how much graph preparation the network data needs, because routing results are only as good as the topology underneath them. Quotes usually separate four parts: discovery and data assessment, graph build and function configuration, testing against agreed routing cases, and handover. Most of that work is one-time. Recurring costs come from keeping data current, applying PostgreSQL and PostGIS updates, and any support retainer you choose. Costs rise with the number of networks, the condition of source data, the number of routing functions exposed to applications, and integration with existing GIS or dispatch systems. Ask for each part priced separately, a statement of who supplies source data and test cases, and a list of which costs recur. DeployOpen quotes follow from the written scope.
How long does a pgRouting project take from start to handover?
Duration is set by the state of the source data and by how many routing use cases must be tested, not by the extension install itself. Installing PostGIS and pgRouting on an existing PostgreSQL server is usually the smallest task. Longer phases include cleaning the network so that nodes and edges connect correctly, deciding how cost attributes such as travel time or capacity are derived, and proving results against known routes. Integration with applications and a change process for data updates add further time. Ask for a schedule with named milestones, the data each milestone needs from your team, and the acceptance tests that close each phase. Most engagements are fixed-scope, so the written scope should fix these items before work starts.
What does our team need to provide for a routing engagement?
Plan for four roles on your side: a data owner who can supply the road or utility network with its attributes and change history, a domain expert who can judge whether routes are correct, a database administrator who will host PostgreSQL and approve extension installs, and an application owner who will consume the routing functions. Without a domain expert, validation tends to stall, because results can look plausible while failing on real streets, valves or lines. If the network describes utility assets, confirm early whether the data falls under a regulatory regime such as the NERC CIP Reliability Standards, since that affects who must approve access and where the database may run. Agree access, test data and sign-off owners in the written scope.
Can an internal team build pgRouting without an outside partner?
Yes, a capable internal team can build it, provided it already has PostgreSQL and PostGIS administration skills and someone who understands graph topology. The work that often slows internal teams is finding disconnected segments, duplicated edges and wrong direction flags in source data, then agreeing how costs are derived and validated. Also weigh the ongoing load: an internal team owns every future upgrade, data refresh and performance investigation. A partner can help with a fixed-scope build and handover, after which your team operates the system. Whichever route you choose, require documented runbooks, test cases and a tested restore procedure before go-live.
How should a large routing graph be sized in PostgreSQL?
Size from the graph and the query pattern, then confirm with a benchmark on your own data. The main inputs are the number of nodes and edges, the number and width of cost attributes, which pgRouting functions run and how often, how many requests run at once, and how much of the graph each request touches. Driving distance and all-pairs functions can touch far more data than a single point-to-point query, so they need separate testing. Check that the edge table has spatial and topology indexes, and that PostgreSQL memory settings suit concurrent routing queries. Ask the partner to state the test graph size, query mix, hardware assumptions and measured results, and to explain how performance changes if the network grows.
How should road or utility network updates run without breaking routes?
Run updates as a controlled change, because pgRouting reflects data changes immediately, so a bad edit affects routing results as soon as it commits. A safe pattern stages changes in a copy or a separate schema, runs topology and connectivity checks, compares sample routes against the last approved version, and then promotes the change in a planned window. Keep a log of who changed what and when, and test a rollback path before production use. Decide how often feeds from GIS or asset systems arrive, which team approves each load, and which automated checks block a promotion. Ask the partner to deliver the update procedure as a runbook your team can execute.
How do PostgreSQL major upgrades affect a PostGIS and pgRouting stack?
A PostgreSQL major upgrade touches the routing stack because the extensions must match the new server, and the data must move with the database. PostgreSQL documents dump and restore, pg_upgrade and logical replication as the main methods, and it notes that logical replication works between different major versions with only several seconds of downtime. Confirm that the PostGIS and pgRouting versions you need support the target PostgreSQL major before you start. Version planning matters: PostgreSQL 14 is supported until November 12, 2026, and 17 until November 8, 2029. Minor updates replace executables and require a restart. Test routing results on the upgraded cluster before switching applications over. See the PostgreSQL upgrading documentation.
How DeployOpen scopes and delivers a pgRouting implementation
DeployOpen plans, builds, tests and documents pgRouting on your own PostGIS database, inside infrastructure you control. Work starts from a written scope that names the graph data, routing functions, update process and sizing targets, so your team knows what is delivered before the build begins.
How we scope
- We inventory your road or utility network sources, their owners and how often each one changes.
- We agree which routing functions you need, such as shortest path, driving distance or traveling salesperson, and the users who call them.
- The written scope fixes deliverables, the PostgreSQL and PostGIS versions in use, sizing assumptions and the test data set.
How we build
- We install pgRouting alongside your PostGIS version, then build the topology and routing tables from your source data.
- We check graph connectivity, cost attributes and one-way rules against known routes before any application uses the results.
- We benchmark representative queries on your graph size and tune indexes and connection settings to match the agreed targets.
How we hand over
- You receive installation notes, the data load and topology rebuild procedures, and the SQL function reference for your team.
- Runbooks cover the scheduled update of road or utility data, rollback steps and how to re-validate routes after a change.
- We walk your engineers through the test results and the open items, and confirm who owns each operational task after handover.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer after handover.
- Support can cover pgRouting and PostGIS version updates during PostgreSQL major upgrades, with tests rerun on your data.
- Before you rely on a new data feed or a larger graph, confirm the planned retest scope and turnaround with us in writing.

