mobilitydb

mobilitydb

mobilitydb : MobilityDB geospatial trajectory data management & analysis platform

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
1650
mobilitydb
mobilitydb
1.3.0
GIS
GPL-3.0
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
Requires
postgis
Need By
mobilitydb_datagen
See Also
pgrouting
h3_postgis
timescaledb
postgis_topology
postgis_raster
postgis_sfcgal
postgis_tiger_geocoder
address_standardizer
Siblings
mobilitydb_datagen

need another schema

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PGDG
1.3.0
18
17
16
15
14
mobilitydbpostgis
DEB
PGDG
1.3.0
18
17
16
15
14
postgresql-$v-mobilitydb-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
MISS
MISS
MISS
MISS
MISS
el8.aarch64
MISS
MISS
MISS
MISS
MISS
el9.x86_64
MISS
MISS
MISS
MISS
MISS
el9.aarch64
MISS
MISS
MISS
MISS
MISS
el10.x86_64
MISS
MISS
MISS
MISS
MISS
el10.aarch64
MISS
MISS
MISS
MISS
MISS
d12.x86_64
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
d12.aarch64
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
d13.x86_64
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
d13.aarch64
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
u22.x86_64
MISS
PGDG 1.2.0
PGDG 1.2.0
PGDG 1.2.0
PGDG 1.2.0
u22.aarch64
MISS
PGDG 1.2.0
PGDG 1.2.0
PGDG 1.2.0
PGDG 1.2.0
u24.x86_64
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
u24.aarch64
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
PGDG 1.3.0
PackageVersionOSORGSIZEFile URL
postgresql-17-mobilitydb1.3.0d12.x86_64pgdg716.0 KiBpostgresql-17-mobilitydb_1.3.0~rc1-1.pgdg12+1_amd64.deb
postgresql-17-mobilitydb1.3.0d12.x86_64pgdg709.8 KiBpostgresql-17-mobilitydb_1.3.0~alpha-3.pgdg12+1_amd64.deb
postgresql-17-mobilitydb1.3.0d12.aarch64pgdg648.1 KiBpostgresql-17-mobilitydb_1.3.0~rc1-1.pgdg12+1_arm64.deb
postgresql-17-mobilitydb1.3.0d12.aarch64pgdg641.9 KiBpostgresql-17-mobilitydb_1.3.0~alpha-3.pgdg12+1_arm64.deb
postgresql-17-mobilitydb1.3.0d13.x86_64pgdg714.9 KiBpostgresql-17-mobilitydb_1.3.0~rc1-1.pgdg13+1_amd64.deb
postgresql-17-mobilitydb1.3.0d13.x86_64pgdg709.4 KiBpostgresql-17-mobilitydb_1.3.0~alpha-3.pgdg13+1_amd64.deb
postgresql-17-mobilitydb1.3.0d13.aarch64pgdg658.1 KiBpostgresql-17-mobilitydb_1.3.0~rc1-1.pgdg13+1_arm64.deb
postgresql-17-mobilitydb1.3.0d13.aarch64pgdg651.3 KiBpostgresql-17-mobilitydb_1.3.0~alpha-3.pgdg13+1_arm64.deb
postgresql-17-mobilitydb1.2.0u22.x86_64pgdg574.0 KiBpostgresql-17-mobilitydb_1.2.0-2.pgdg22.04+1_amd64.deb
postgresql-17-mobilitydb1.2.0u22.aarch64pgdg535.8 KiBpostgresql-17-mobilitydb_1.2.0-2.pgdg22.04+1_arm64.deb
postgresql-17-mobilitydb1.3.0u24.x86_64pgdg618.5 KiBpostgresql-17-mobilitydb_1.3.0~rc1-1.pgdg24.04+1_amd64.deb
postgresql-17-mobilitydb1.3.0u24.x86_64pgdg609.9 KiBpostgresql-17-mobilitydb_1.3.0~alpha-3.pgdg24.04+1_amd64.deb
postgresql-17-mobilitydb1.3.0u24.aarch64pgdg581.1 KiBpostgresql-17-mobilitydb_1.3.0~rc1-1.pgdg24.04+1_arm64.deb
postgresql-17-mobilitydb1.3.0u24.aarch64pgdg572.0 KiBpostgresql-17-mobilitydb_1.3.0~alpha-3.pgdg24.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
postgresql-16-mobilitydb1.3.0d12.x86_64pgdg715.2 KiBpostgresql-16-mobilitydb_1.3.0~rc1-1.pgdg12+1_amd64.deb
postgresql-16-mobilitydb1.3.0d12.x86_64pgdg708.5 KiBpostgresql-16-mobilitydb_1.3.0~alpha-3.pgdg12+1_amd64.deb
postgresql-16-mobilitydb1.3.0d12.aarch64pgdg647.9 KiBpostgresql-16-mobilitydb_1.3.0~rc1-1.pgdg12+1_arm64.deb
postgresql-16-mobilitydb1.3.0d12.aarch64pgdg642.8 KiBpostgresql-16-mobilitydb_1.3.0~alpha-3.pgdg12+1_arm64.deb
postgresql-16-mobilitydb1.3.0d13.x86_64pgdg717.0 KiBpostgresql-16-mobilitydb_1.3.0~rc1-1.pgdg13+1_amd64.deb
postgresql-16-mobilitydb1.3.0d13.x86_64pgdg709.7 KiBpostgresql-16-mobilitydb_1.3.0~alpha-3.pgdg13+1_amd64.deb
postgresql-16-mobilitydb1.3.0d13.aarch64pgdg658.4 KiBpostgresql-16-mobilitydb_1.3.0~rc1-1.pgdg13+1_arm64.deb
postgresql-16-mobilitydb1.3.0d13.aarch64pgdg653.0 KiBpostgresql-16-mobilitydb_1.3.0~alpha-3.pgdg13+1_arm64.deb
postgresql-16-mobilitydb1.2.0u22.x86_64pgdg574.2 KiBpostgresql-16-mobilitydb_1.2.0-2.pgdg22.04+1_amd64.deb
postgresql-16-mobilitydb1.2.0u22.aarch64pgdg535.7 KiBpostgresql-16-mobilitydb_1.2.0-2.pgdg22.04+1_arm64.deb
postgresql-16-mobilitydb1.3.0u24.x86_64pgdg618.7 KiBpostgresql-16-mobilitydb_1.3.0~rc1-1.pgdg24.04+1_amd64.deb
postgresql-16-mobilitydb1.3.0u24.x86_64pgdg609.6 KiBpostgresql-16-mobilitydb_1.3.0~alpha-3.pgdg24.04+1_amd64.deb
postgresql-16-mobilitydb1.3.0u24.aarch64pgdg580.4 KiBpostgresql-16-mobilitydb_1.3.0~rc1-1.pgdg24.04+1_arm64.deb
postgresql-16-mobilitydb1.3.0u24.aarch64pgdg572.2 KiBpostgresql-16-mobilitydb_1.3.0~alpha-3.pgdg24.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
postgresql-15-mobilitydb1.3.0d12.x86_64pgdg715.7 KiBpostgresql-15-mobilitydb_1.3.0~rc1-1.pgdg12+1_amd64.deb
postgresql-15-mobilitydb1.3.0d12.x86_64pgdg708.7 KiBpostgresql-15-mobilitydb_1.3.0~alpha-3.pgdg12+1_amd64.deb
postgresql-15-mobilitydb1.3.0d12.aarch64pgdg648.2 KiBpostgresql-15-mobilitydb_1.3.0~rc1-1.pgdg12+1_arm64.deb
postgresql-15-mobilitydb1.3.0d12.aarch64pgdg643.2 KiBpostgresql-15-mobilitydb_1.3.0~alpha-3.pgdg12+1_arm64.deb
postgresql-15-mobilitydb1.3.0d13.x86_64pgdg715.2 KiBpostgresql-15-mobilitydb_1.3.0~rc1-1.pgdg13+1_amd64.deb
postgresql-15-mobilitydb1.3.0d13.x86_64pgdg708.9 KiBpostgresql-15-mobilitydb_1.3.0~alpha-3.pgdg13+1_amd64.deb
postgresql-15-mobilitydb1.3.0d13.aarch64pgdg658.3 KiBpostgresql-15-mobilitydb_1.3.0~rc1-1.pgdg13+1_arm64.deb
postgresql-15-mobilitydb1.3.0d13.aarch64pgdg653.4 KiBpostgresql-15-mobilitydb_1.3.0~alpha-3.pgdg13+1_arm64.deb
postgresql-15-mobilitydb1.2.0u22.x86_64pgdg573.5 KiBpostgresql-15-mobilitydb_1.2.0-2.pgdg22.04+1_amd64.deb
postgresql-15-mobilitydb1.2.0u22.aarch64pgdg536.0 KiBpostgresql-15-mobilitydb_1.2.0-2.pgdg22.04+1_arm64.deb
postgresql-15-mobilitydb1.3.0u24.x86_64pgdg618.2 KiBpostgresql-15-mobilitydb_1.3.0~rc1-1.pgdg24.04+1_amd64.deb
postgresql-15-mobilitydb1.3.0u24.x86_64pgdg609.5 KiBpostgresql-15-mobilitydb_1.3.0~alpha-3.pgdg24.04+1_amd64.deb
postgresql-15-mobilitydb1.3.0u24.aarch64pgdg580.4 KiBpostgresql-15-mobilitydb_1.3.0~rc1-1.pgdg24.04+1_arm64.deb
postgresql-15-mobilitydb1.3.0u24.aarch64pgdg572.6 KiBpostgresql-15-mobilitydb_1.3.0~alpha-3.pgdg24.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
postgresql-14-mobilitydb1.3.0d12.x86_64pgdg716.4 KiBpostgresql-14-mobilitydb_1.3.0~rc1-1.pgdg12+1_amd64.deb
postgresql-14-mobilitydb1.3.0d12.x86_64pgdg708.7 KiBpostgresql-14-mobilitydb_1.3.0~alpha-3.pgdg12+1_amd64.deb
postgresql-14-mobilitydb1.3.0d12.aarch64pgdg648.3 KiBpostgresql-14-mobilitydb_1.3.0~rc1-1.pgdg12+1_arm64.deb
postgresql-14-mobilitydb1.3.0d12.aarch64pgdg641.6 KiBpostgresql-14-mobilitydb_1.3.0~alpha-3.pgdg12+1_arm64.deb
postgresql-14-mobilitydb1.3.0d13.x86_64pgdg716.6 KiBpostgresql-14-mobilitydb_1.3.0~rc1-1.pgdg13+1_amd64.deb
postgresql-14-mobilitydb1.3.0d13.x86_64pgdg709.9 KiBpostgresql-14-mobilitydb_1.3.0~alpha-3.pgdg13+1_amd64.deb
postgresql-14-mobilitydb1.3.0d13.aarch64pgdg657.1 KiBpostgresql-14-mobilitydb_1.3.0~rc1-1.pgdg13+1_arm64.deb
postgresql-14-mobilitydb1.3.0d13.aarch64pgdg652.5 KiBpostgresql-14-mobilitydb_1.3.0~alpha-3.pgdg13+1_arm64.deb
postgresql-14-mobilitydb1.2.0u22.x86_64pgdg573.2 KiBpostgresql-14-mobilitydb_1.2.0-2.pgdg22.04+1_amd64.deb
postgresql-14-mobilitydb1.2.0u22.aarch64pgdg535.6 KiBpostgresql-14-mobilitydb_1.2.0-2.pgdg22.04+1_arm64.deb
postgresql-14-mobilitydb1.3.0u24.x86_64pgdg618.2 KiBpostgresql-14-mobilitydb_1.3.0~rc1-1.pgdg24.04+1_amd64.deb
postgresql-14-mobilitydb1.3.0u24.x86_64pgdg609.3 KiBpostgresql-14-mobilitydb_1.3.0~alpha-3.pgdg24.04+1_amd64.deb
postgresql-14-mobilitydb1.3.0u24.aarch64pgdg580.0 KiBpostgresql-14-mobilitydb_1.3.0~rc1-1.pgdg24.04+1_arm64.deb
postgresql-14-mobilitydb1.3.0u24.aarch64pgdg572.0 KiBpostgresql-14-mobilitydb_1.3.0~alpha-3.pgdg24.04+1_arm64.deb

Source

Install

Make sure PGDG repo available:

pig repo add pgdg -u    # add pgdg repo and update cache

Install this extension with pig:

pig install mobilitydb;		# install via package name, for the active PG version

pig install mobilitydb -v 18;   # install for PG 18
pig install mobilitydb -v 17;   # install for PG 17
pig install mobilitydb -v 16;   # install for PG 16
pig install mobilitydb -v 15;   # install for PG 15
pig install mobilitydb -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION mobilitydb CASCADE; -- requires postgis

Usage

mobilitydb: Temporal and spatio-temporal data management for PostgreSQL

MobilityDB extends PostgreSQL and PostGIS with temporal and spatio-temporal data types, enabling efficient storage, indexing, and querying of moving object data such as vehicle trajectories, sensor readings, and time-varying attributes.

Key Documentation:

Getting Started

MobilityDB requires PostGIS. Enable both extensions:

CREATE EXTENSION PostGIS;
CREATE EXTENSION MobilityDB;

Temporal Types

MobilityDB provides temporal variants of base types:

Temporal TypeBase TypeDescription
tboolbooleanTime-varying boolean
tintintegerTime-varying integer
tfloatfloatTime-varying float
ttexttextTime-varying text
tgeompointgeometry(Point)Time-varying geometric point
tgeogpointgeography(Point)Time-varying geographic point

Temporal Subtypes

Each temporal type can be represented in different subtypes depending on how values change over time:

SubtypeDescriptionExample
InstantSingle value at a single timestamp'25.5@2025-01-01 08:00'
SequenceContinuous values over a time interval'[25.5@08:00, 28.1@09:00, 30.0@10:00]'
SequenceSetSet of non-overlapping sequences'{[25.5@08:00, 28.1@09:00], [30.0@11:00, 31.2@12:00]}'

Sequences use brackets to indicate inclusive [ or exclusive ( bounds, just like PostgreSQL range types.

Creating Temporal Values

Instant values:

SELECT tfloat '25.5@2025-06-01 08:00:00+00';
SELECT tgeompoint 'SRID=4326;Point(2.3522 48.8566)@2025-06-01 08:00:00+00';

Sequence values (continuous interpolation):

SELECT tfloat '[20.0@2025-06-01 08:00, 25.5@2025-06-01 09:00, 22.0@2025-06-01 10:00]';

Discrete sequences (stepwise interpolation):

SELECT tint 'Interp=Step;[10@2025-06-01 08:00, 20@2025-06-01 09:00, 15@2025-06-01 10:00]';

SequenceSet values:

SELECT tfloat '{[20.0@08:00, 25.5@09:00], [22.0@11:00, 28.0@12:00]}';

Constructing from components:

SELECT tgeompoint_inst(ST_Point(2.3522, 48.8566, 4326), '2025-06-01 08:00+00');
SELECT tgeompoint_seq(ARRAY[
    tgeompoint_inst(ST_Point(2.3522, 48.8566, 4326), '2025-06-01 08:00+00'),
    tgeompoint_inst(ST_Point(2.2945, 48.8584, 4326), '2025-06-01 08:30+00'),
    tgeompoint_inst(ST_Point(2.3364, 48.8606, 4326), '2025-06-01 09:00+00')
]);

Temporal Operations

Extracting values at a specific time:

SELECT valueAtTimestamp(temp, '2025-06-01 08:30:00+00')
FROM (SELECT tfloat '[20.0@08:00, 30.0@09:00]' AS temp) t;
-- Returns 25.0 (linear interpolation)

Restricting to a time period:

SELECT atTime(trip, tstzspan '[2025-06-01 08:00, 2025-06-01 09:00]')
FROM trips;

Getting the time span of a temporal value:

SELECT duration(trip), startTimestamp(trip), endTimestamp(trip)
FROM trips;

Temporal comparisons:

-- Time periods when temperature exceeded 30 degrees
SELECT atValue(temperature, true)
FROM (SELECT tfloat '[20@08:00, 35@09:00, 25@10:00]' #> 30.0 AS temperature) t;

Spatial-Temporal Operations

Trajectory: extract the spatial path as a geometry:

SELECT ST_AsText(trajectory(trip))
FROM trips
WHERE vehicle_id = 42;

Speed calculation:

-- Speed in units per second (m/s for geographic points)
SELECT speed(trip)
FROM trips
WHERE vehicle_id = 42;

Length of trajectory:

SELECT length(trip)
FROM trips
WHERE vehicle_id = 42;

Space-time bounding box (stbox):

-- Get the space-time bounding box
SELECT stbox(trip)
FROM trips;

-- Construct an stbox for querying
SELECT stbox(
    ST_MakeEnvelope(2.2, 48.8, 2.4, 48.9, 4326),
    tstzspan '[2025-06-01, 2025-06-02]'
);

Spatial restriction: values within an area:

-- Portions of a trip within a polygon
SELECT atGeometry(trip, ST_Buffer(ST_Point(2.35, 48.86, 4326), 0.01))
FROM trips;

Distance between two temporal points:

SELECT distance(t1.trip, t2.trip)
FROM trips t1, trips t2
WHERE t1.vehicle_id = 1 AND t2.vehicle_id = 2;

Nearest approach distance and time:

SELECT nearestApproachDistance(t1.trip, t2.trip),
       nearestApproachInstant(t1.trip, t2.trip)
FROM trips t1, trips t2
WHERE t1.vehicle_id = 1 AND t2.vehicle_id = 2;

Indexing

MobilityDB supports GiST and SP-GiST indexes for efficient temporal and spatio-temporal queries.

SP-GiST index for temporal types (time dimension):

CREATE INDEX ON measurements USING spgist(temperature);

GiST index for spatio-temporal types (space + time):

CREATE INDEX ON trips USING gist(trip);

These indexes accelerate bounding box queries, temporal overlap checks, and spatial-temporal intersection:

-- Uses GiST index for space-time filtering
SELECT vehicle_id
FROM trips
WHERE trip && stbox(
    ST_MakeEnvelope(2.2, 48.8, 2.4, 48.9, 4326),
    tstzspan '[2025-06-01, 2025-06-02]'
);

Example: Vehicle Tracking

A complete example storing and querying vehicle GPS trajectories:

CREATE TABLE vehicles (
    vehicle_id  INT PRIMARY KEY,
    plate       TEXT,
    type        TEXT
);

CREATE TABLE trips (
    trip_id     BIGSERIAL PRIMARY KEY,
    vehicle_id  INT REFERENCES vehicles(vehicle_id),
    trip        tgeompoint,
    trip_date   DATE
);

CREATE INDEX ON trips USING gist(trip);

-- Insert a trip as a sequence of GPS points
INSERT INTO trips (vehicle_id, trip, trip_date) VALUES (
    1,
    tgeompoint_seq(ARRAY[
        tgeompoint_inst(ST_Point(2.3522, 48.8566, 4326), '2025-06-01 08:00+00'),
        tgeompoint_inst(ST_Point(2.2945, 48.8584, 4326), '2025-06-01 08:15+00'),
        tgeompoint_inst(ST_Point(2.3364, 48.8606, 4326), '2025-06-01 08:30+00'),
        tgeompoint_inst(ST_Point(2.3488, 48.8534, 4326), '2025-06-01 08:45+00')
    ]),
    '2025-06-01'
);

-- Where was vehicle 1 at 08:20?
SELECT valueAtTimestamp(trip, '2025-06-01 08:20+00')
FROM trips WHERE vehicle_id = 1 AND trip_date = '2025-06-01';

-- What was the average speed?
SELECT twAvg(speed(trip))
FROM trips WHERE vehicle_id = 1 AND trip_date = '2025-06-01';

-- Total distance traveled
SELECT length(trip)
FROM trips WHERE vehicle_id = 1 AND trip_date = '2025-06-01';

-- Get the full trajectory as a LineString
SELECT ST_AsGeoJSON(trajectory(trip))
FROM trips WHERE vehicle_id = 1 AND trip_date = '2025-06-01';

Example: Spatio-Temporal Intersection Query

Find all trips that passed through a specific area during a given time window:

-- Define area of interest: a circle around the Eiffel Tower
WITH area AS (
    SELECT ST_Buffer(ST_Point(2.2945, 48.8584, 4326)::geography, 500)::geometry AS geom
)
SELECT t.vehicle_id,
       t.trip_date,
       atGeometry(t.trip, a.geom) AS trip_in_area,
       length(atGeometry(t.trip, a.geom)) AS distance_in_area
FROM trips t, area a
WHERE t.trip && stbox(
    a.geom,
    tstzspan '[2025-06-01 07:00+00, 2025-06-01 10:00+00]'
)
  AND eIntersects(t.trip, a.geom)
ORDER BY t.trip_date;

Aggregate Functions

MobilityDB provides temporal aggregates:

-- Time-weighted average of a temporal float
SELECT twAvg(temperature) FROM sensor_data WHERE sensor_id = 1;

-- Merge multiple temporal points into one
SELECT tUnion(trip) FROM trips WHERE vehicle_id = 1 AND trip_date = '2025-06-01';

-- Centroid of a set of temporal points at each timestamp
SELECT tCentroid(trip) FROM trips WHERE trip_date = '2025-06-01';
Last updated on