mobilitydb_datagen
MobilityDB随机数据生成函数
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
mobilitydb | 1.3.0 | GIS | GPL-3.0 | SQL |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 1650 | mobilitydb | 否 | 是 | 否 | 是 | 否 | 是 | - |
| 1651 | mobilitydb_datagen | 否 | 否 | 否 | 是 | 否 | 是 | - |
| 相关扩展 | mobilitydb mobilitydb postgis timescaledb pgrouting |
|---|
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PGDG | 1.3.0 | 1817161514 | mobilitydb | mobilitydb |
| DEB | PGDG | 1.3.0 | 1817161514 | postgresql-$v-mobilitydb | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| el8.aarch64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| el9.x86_64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| el9.aarch64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| el10.x86_64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS |
| el10.aarch64 | PGDG MISS | PGDG MISS | PGDG MISS | PGDG MISS | PGDG 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 | PGDG MISS | PGDG 1.2.0 | PGDG 1.2.0 | PGDG 1.2.0 | PGDG 1.2.0 |
| u22.aarch64 | PGDG 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 |
| u26.x86_64 | PGDG 1.3.0 | PGDG 1.3.0 | PGDG 1.3.0 | PGDG 1.3.0 | PGDG 1.3.0 |
| u26.aarch64 | PGDG 1.3.0 | PGDG 1.3.0 | PGDG 1.3.0 | PGDG 1.3.0 | PGDG 1.3.0 |
安装
您可以直接安装 mobilitydb 扩展包的预置二进制包,首先确保 PGDG 仓库已经添加并启用:
pig repo add pgdg -u # 添加 PGDG 仓库并更新缓存
使用 pig 或者是 apt/yum/dnf 安装扩展:
pig install mobilitydb; # 当前活跃 PG 版本安装
pig ext install -y mobilitydb -v 18 # PG 18
pig ext install -y mobilitydb -v 17 # PG 17
pig ext install -y mobilitydb -v 16 # PG 16
pig ext install -y mobilitydb -v 15 # PG 15
pig ext install -y mobilitydb -v 14 # PG 14
apt install -y postgresql-18-mobilitydb # PG 18
apt install -y postgresql-17-mobilitydb # PG 17
apt install -y postgresql-16-mobilitydb # PG 16
apt install -y postgresql-15-mobilitydb # PG 15
apt install -y postgresql-14-mobilitydb # PG 14
创建扩展:
CREATE EXTENSION mobilitydb_datagen CASCADE; -- 依赖: mobilitydb
用法
来源:repository, synthetic data generator docs, control file, temporal generators, temporal point generators
mobilitydb_datagen 提供 PL/pgSQL 函数,用来生成合成的 PostgreSQL、PostGIS 和 MobilityDB 值。它主要适用于需要随机 temporal value 或轨迹的回归数据、演示和基准测试 fixture。
-- After the main MobilityDB extension is loaded:
CREATE EXTENSION mobilitydb_datagen;
生成随机 Temporal 值
-- A random temporal float sequence.
SELECT random_tfloat_seq(
-100.0, 100.0, -- value bounds
'2025-06-01 00:00+00', '2025-06-02 00:00+00', -- time bounds
10.0, -- max value delta
10, -- max minutes between instants
5, 10 -- min/max instants
);
-- Step interpolation instead of the default linear interpolation.
SELECT random_tfloat_seq(
-100.0, 100.0,
'2025-06-01 00:00+00', '2025-06-02 00:00+00',
10.0, 10, 5, 10,
false
);
-- A random temporal geometry point sequence.
SELECT asEWKT(
random_tgeompoint_contseq(
2.20, 2.50, 48.80, 48.95, -- x/y bounds
'2025-06-01 08:00+00', '2025-06-01 18:00+00',
0.02, 5, 20, 40, -- max delta, max minutes, min/max instants
srid => 4326
)
);
其他已确认的生成器家族包括 random_bool、random_int、random_float、random_text、random_timestamptz 等标量辅助函数;数组、集合、span 和 range 辅助函数;random_tbool_inst、random_tint_discseq、random_tfloat_seq、random_tfloat_seqset 等 temporal 辅助函数;以及 random_geom_point、random_geom_linestring、random_tgeompoint_contseq、random_tgeompoint_seqset、random_tgeogpoint_contseq、random_tgeogpoint_seqset 等空间/temporal-point 辅助函数。
生成测试数据集
为 trip 查询基准测试创建批量测试数据:
CREATE TABLE trip_samples AS
SELECT
vehicle_id,
random_tgeompoint_contseq(
2.20, 2.50, 48.80, 48.95,
'2025-06-01 08:00+00', '2025-06-01 18:00+00',
0.02, 5, 20, 40,
srid => 4326
) AS trip
FROM generate_series(1, 1000) AS vehicle_id;
注意事项
- control file 要求主
mobilitydb扩展已存在;mobilitydb_datagen不是独立扩展。 db/extension.csv中的包行列出版本1.3.0、packagemobilitydb,并支持 PostgreSQL 14 到 18。- 上游文档有意省略许多生成器函数的详细参数列表,并让用户查看 SQL 源文件确认精确签名。