跳转到主要内容

pg_warren

基于 PostgreSQL 表的版本化图遍历与图计算

pg_warren · 基于 PostgreSQL 表的版本化图遍历与图计算

概览

ID扩展软件包版本类别许可证编程语言
2645pg_warrenpg_warren0.8.0FEATApache-2.0Rust
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-dt-否是否是否是
关联
模式warren
Shared cache preload on PG15–16

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.8.019 18 17 16 15pg_warren-
RPMPIGSTY0.8.019 18 17 16 15pg_warren_$v-
DEBPIGSTY0.8.019 18 17 16 15postgresql-$v-pg-warren-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
el8.aarch64N/APIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
el9.x86_64PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
el9.aarch64PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
el10.x86_64PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
el10.aarch64PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
d12.x86_64PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
d12.aarch64PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
d13.x86_64PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
d13.aarch64PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
u22.x86_64PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
u22.aarch64PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
u24.x86_64PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
u24.aarch64PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
u26.x86_64PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
u26.aarch64PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0PIGSTY 0.8.0
软件包版本平台仓库大小下载
pg_warren_190.8.0el9.x86_64pigsty2.8 MiBpg_warren_19-0.8.0-2PGSTY.el9.x86_64.rpm
pg_warren_190.8.0el9.aarch64pigsty2.6 MiBpg_warren_19-0.8.0-2PGSTY.el9.aarch64.rpm
pg_warren_190.8.0el10.x86_64pigsty2.8 MiBpg_warren_19-0.8.0-2PGSTY.el10.x86_64.rpm
pg_warren_190.8.0el10.aarch64pigsty2.6 MiBpg_warren_19-0.8.0-2PGSTY.el10.aarch64.rpm
postgresql-19-pg-warren0.8.0d12.x86_64pigsty2.1 MiBpostgresql-19-pg-warren_0.8.0-2PGSTY~bookworm_amd64.deb
postgresql-19-pg-warren0.8.0d12.aarch64pigsty1.7 MiBpostgresql-19-pg-warren_0.8.0-2PGSTY~bookworm_arm64.deb
postgresql-19-pg-warren0.8.0d13.x86_64pigsty2.1 MiBpostgresql-19-pg-warren_0.8.0-2PGSTY~trixie_amd64.deb
postgresql-19-pg-warren0.8.0d13.aarch64pigsty1.7 MiBpostgresql-19-pg-warren_0.8.0-2PGSTY~trixie_arm64.deb
postgresql-19-pg-warren0.8.0u22.x86_64pigsty2.2 MiBpostgresql-19-pg-warren_0.8.0-2PGSTY~jammy_amd64.deb
postgresql-19-pg-warren0.8.0u22.aarch64pigsty2.0 MiBpostgresql-19-pg-warren_0.8.0-2PGSTY~jammy_arm64.deb
postgresql-19-pg-warren0.8.0u24.x86_64pigsty2.2 MiBpostgresql-19-pg-warren_0.8.0-2PGSTY~noble_amd64.deb
postgresql-19-pg-warren0.8.0u24.aarch64pigsty2.0 MiBpostgresql-19-pg-warren_0.8.0-2PGSTY~noble_arm64.deb
postgresql-19-pg-warren0.8.0u26.x86_64pigsty2.2 MiBpostgresql-19-pg-warren_0.8.0-2PGSTY~resolute_amd64.deb
postgresql-19-pg-warren0.8.0u26.aarch64pigsty2.0 MiBpostgresql-19-pg-warren_0.8.0-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_warren_180.8.0el8.x86_64pigsty3.0 MiBpg_warren_18-0.8.0-1PGSTY.el8.x86_64.rpm
pg_warren_180.8.0el8.aarch64pigsty2.4 MiBpg_warren_18-0.8.0-1PGSTY.el8.aarch64.rpm
pg_warren_180.8.0el9.x86_64pigsty2.8 MiBpg_warren_18-0.8.0-2PGSTY.el9.x86_64.rpm
pg_warren_180.8.0el9.aarch64pigsty2.6 MiBpg_warren_18-0.8.0-2PGSTY.el9.aarch64.rpm
pg_warren_180.8.0el10.x86_64pigsty2.8 MiBpg_warren_18-0.8.0-2PGSTY.el10.x86_64.rpm
pg_warren_180.8.0el10.aarch64pigsty2.6 MiBpg_warren_18-0.8.0-2PGSTY.el10.aarch64.rpm
postgresql-18-pg-warren0.8.0d12.x86_64pigsty2.1 MiBpostgresql-18-pg-warren_0.8.0-2PGSTY~bookworm_amd64.deb
postgresql-18-pg-warren0.8.0d12.aarch64pigsty1.7 MiBpostgresql-18-pg-warren_0.8.0-2PGSTY~bookworm_arm64.deb
postgresql-18-pg-warren0.8.0d13.x86_64pigsty2.1 MiBpostgresql-18-pg-warren_0.8.0-2PGSTY~trixie_amd64.deb
postgresql-18-pg-warren0.8.0d13.aarch64pigsty1.7 MiBpostgresql-18-pg-warren_0.8.0-2PGSTY~trixie_arm64.deb
postgresql-18-pg-warren0.8.0u22.x86_64pigsty2.2 MiBpostgresql-18-pg-warren_0.8.0-2PGSTY~jammy_amd64.deb
postgresql-18-pg-warren0.8.0u22.aarch64pigsty2.0 MiBpostgresql-18-pg-warren_0.8.0-2PGSTY~jammy_arm64.deb
postgresql-18-pg-warren0.8.0u24.x86_64pigsty2.2 MiBpostgresql-18-pg-warren_0.8.0-2PGSTY~noble_amd64.deb
postgresql-18-pg-warren0.8.0u24.aarch64pigsty2.0 MiBpostgresql-18-pg-warren_0.8.0-2PGSTY~noble_arm64.deb
postgresql-18-pg-warren0.8.0u26.x86_64pigsty2.2 MiBpostgresql-18-pg-warren_0.8.0-2PGSTY~resolute_amd64.deb
postgresql-18-pg-warren0.8.0u26.aarch64pigsty2.0 MiBpostgresql-18-pg-warren_0.8.0-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_warren_170.8.0el8.x86_64pigsty3.0 MiBpg_warren_17-0.8.0-1PGSTY.el8.x86_64.rpm
pg_warren_170.8.0el8.aarch64pigsty2.4 MiBpg_warren_17-0.8.0-1PGSTY.el8.aarch64.rpm
pg_warren_170.8.0el9.x86_64pigsty2.8 MiBpg_warren_17-0.8.0-2PGSTY.el9.x86_64.rpm
pg_warren_170.8.0el9.aarch64pigsty2.6 MiBpg_warren_17-0.8.0-2PGSTY.el9.aarch64.rpm
pg_warren_170.8.0el10.x86_64pigsty2.8 MiBpg_warren_17-0.8.0-2PGSTY.el10.x86_64.rpm
pg_warren_170.8.0el10.aarch64pigsty2.6 MiBpg_warren_17-0.8.0-2PGSTY.el10.aarch64.rpm
postgresql-17-pg-warren0.8.0d12.x86_64pigsty2.1 MiBpostgresql-17-pg-warren_0.8.0-2PGSTY~bookworm_amd64.deb
postgresql-17-pg-warren0.8.0d12.aarch64pigsty1.7 MiBpostgresql-17-pg-warren_0.8.0-2PGSTY~bookworm_arm64.deb
postgresql-17-pg-warren0.8.0d13.x86_64pigsty2.1 MiBpostgresql-17-pg-warren_0.8.0-2PGSTY~trixie_amd64.deb
postgresql-17-pg-warren0.8.0d13.aarch64pigsty1.7 MiBpostgresql-17-pg-warren_0.8.0-2PGSTY~trixie_arm64.deb
postgresql-17-pg-warren0.8.0u22.x86_64pigsty2.2 MiBpostgresql-17-pg-warren_0.8.0-2PGSTY~jammy_amd64.deb
postgresql-17-pg-warren0.8.0u22.aarch64pigsty2.0 MiBpostgresql-17-pg-warren_0.8.0-2PGSTY~jammy_arm64.deb
postgresql-17-pg-warren0.8.0u24.x86_64pigsty2.2 MiBpostgresql-17-pg-warren_0.8.0-2PGSTY~noble_amd64.deb
postgresql-17-pg-warren0.8.0u24.aarch64pigsty2.0 MiBpostgresql-17-pg-warren_0.8.0-2PGSTY~noble_arm64.deb
postgresql-17-pg-warren0.8.0u26.x86_64pigsty2.2 MiBpostgresql-17-pg-warren_0.8.0-2PGSTY~resolute_amd64.deb
postgresql-17-pg-warren0.8.0u26.aarch64pigsty2.0 MiBpostgresql-17-pg-warren_0.8.0-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_warren_160.8.0el8.x86_64pigsty3.0 MiBpg_warren_16-0.8.0-1PGSTY.el8.x86_64.rpm
pg_warren_160.8.0el8.aarch64pigsty2.4 MiBpg_warren_16-0.8.0-1PGSTY.el8.aarch64.rpm
pg_warren_160.8.0el9.x86_64pigsty2.8 MiBpg_warren_16-0.8.0-2PGSTY.el9.x86_64.rpm
pg_warren_160.8.0el9.aarch64pigsty2.6 MiBpg_warren_16-0.8.0-2PGSTY.el9.aarch64.rpm
pg_warren_160.8.0el10.x86_64pigsty2.8 MiBpg_warren_16-0.8.0-2PGSTY.el10.x86_64.rpm
pg_warren_160.8.0el10.aarch64pigsty2.6 MiBpg_warren_16-0.8.0-2PGSTY.el10.aarch64.rpm
postgresql-16-pg-warren0.8.0d12.x86_64pigsty2.1 MiBpostgresql-16-pg-warren_0.8.0-2PGSTY~bookworm_amd64.deb
postgresql-16-pg-warren0.8.0d12.aarch64pigsty1.7 MiBpostgresql-16-pg-warren_0.8.0-2PGSTY~bookworm_arm64.deb
postgresql-16-pg-warren0.8.0d13.x86_64pigsty2.1 MiBpostgresql-16-pg-warren_0.8.0-2PGSTY~trixie_amd64.deb
postgresql-16-pg-warren0.8.0d13.aarch64pigsty1.7 MiBpostgresql-16-pg-warren_0.8.0-2PGSTY~trixie_arm64.deb
postgresql-16-pg-warren0.8.0u22.x86_64pigsty2.2 MiBpostgresql-16-pg-warren_0.8.0-2PGSTY~jammy_amd64.deb
postgresql-16-pg-warren0.8.0u22.aarch64pigsty2.0 MiBpostgresql-16-pg-warren_0.8.0-2PGSTY~jammy_arm64.deb
postgresql-16-pg-warren0.8.0u24.x86_64pigsty2.2 MiBpostgresql-16-pg-warren_0.8.0-2PGSTY~noble_amd64.deb
postgresql-16-pg-warren0.8.0u24.aarch64pigsty2.0 MiBpostgresql-16-pg-warren_0.8.0-2PGSTY~noble_arm64.deb
postgresql-16-pg-warren0.8.0u26.x86_64pigsty2.2 MiBpostgresql-16-pg-warren_0.8.0-2PGSTY~resolute_amd64.deb
postgresql-16-pg-warren0.8.0u26.aarch64pigsty2.0 MiBpostgresql-16-pg-warren_0.8.0-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_warren_150.8.0el8.x86_64pigsty3.0 MiBpg_warren_15-0.8.0-1PGSTY.el8.x86_64.rpm
pg_warren_150.8.0el8.aarch64pigsty2.4 MiBpg_warren_15-0.8.0-1PGSTY.el8.aarch64.rpm
pg_warren_150.8.0el9.x86_64pigsty2.8 MiBpg_warren_15-0.8.0-2PGSTY.el9.x86_64.rpm
pg_warren_150.8.0el9.aarch64pigsty2.5 MiBpg_warren_15-0.8.0-2PGSTY.el9.aarch64.rpm
pg_warren_150.8.0el10.x86_64pigsty2.8 MiBpg_warren_15-0.8.0-2PGSTY.el10.x86_64.rpm
pg_warren_150.8.0el10.aarch64pigsty2.5 MiBpg_warren_15-0.8.0-2PGSTY.el10.aarch64.rpm
postgresql-15-pg-warren0.8.0d12.x86_64pigsty2.1 MiBpostgresql-15-pg-warren_0.8.0-2PGSTY~bookworm_amd64.deb
postgresql-15-pg-warren0.8.0d12.aarch64pigsty1.7 MiBpostgresql-15-pg-warren_0.8.0-2PGSTY~bookworm_arm64.deb
postgresql-15-pg-warren0.8.0d13.x86_64pigsty2.1 MiBpostgresql-15-pg-warren_0.8.0-2PGSTY~trixie_amd64.deb
postgresql-15-pg-warren0.8.0d13.aarch64pigsty1.7 MiBpostgresql-15-pg-warren_0.8.0-2PGSTY~trixie_arm64.deb
postgresql-15-pg-warren0.8.0u22.x86_64pigsty2.2 MiBpostgresql-15-pg-warren_0.8.0-2PGSTY~jammy_amd64.deb
postgresql-15-pg-warren0.8.0u22.aarch64pigsty2.0 MiBpostgresql-15-pg-warren_0.8.0-2PGSTY~jammy_arm64.deb
postgresql-15-pg-warren0.8.0u24.x86_64pigsty2.2 MiBpostgresql-15-pg-warren_0.8.0-2PGSTY~noble_amd64.deb
postgresql-15-pg-warren0.8.0u24.aarch64pigsty2.0 MiBpostgresql-15-pg-warren_0.8.0-2PGSTY~noble_arm64.deb
postgresql-15-pg-warren0.8.0u26.x86_64pigsty2.2 MiBpostgresql-15-pg-warren_0.8.0-2PGSTY~resolute_amd64.deb
postgresql-15-pg-warren0.8.0u26.aarch64pigsty2.0 MiBpostgresql-15-pg-warren_0.8.0-2PGSTY~resolute_arm64.deb

源码

pig build pkg pg_warren;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

pig repo add pgsql -u   # add both repo and update cache

使用 pig 安装扩展。

pig install pg_warren;		# install by package name

pig install pg_warren -v 19;   # install for PG 19
pig install pg_warren -v 18;   # install for PG 18
pig install pg_warren -v 17;   # install for PG 17
pig install pg_warren -v 16;   # install for PG 16
pig install pg_warren -v 15;   # install for PG 15

在数据库中创建扩展。

CREATE EXTENSION pg_warren;

用法

来源:

pg_warren 0.8.0 从普通 PostgreSQL 表构建版本化邻接快照,用于图遍历与图计算。它支持 PostgreSQL 15–18,图版本、向量及其变更都参与 PostgreSQL 事务。遍历读取已构建的快照;源表发生变化后需要显式刷新。

核心流程

这是可信扩展,在数据库上拥有 CREATE 权限的角色可以安装。基本图由节点查询与边查询定义:

CREATE EXTENSION pg_warren;
CREATE TABLE people (id bigint PRIMARY KEY, name text);
CREATE TABLE follows (src bigint, dst bigint);
INSERT INTO people VALUES (1, 'Ada'), (2, 'Bob'), (3, 'Cy');
INSERT INTO follows VALUES (1, 2), (2, 3);
SELECT warren.create_graph('social',
  'SELECT id FROM public.people', 'SELECT src, dst FROM public.follows');
SELECT warren.refresh('social');
SELECT * FROM warren.bfs('social', ARRAY[1::bigint], 3);
SELECT warren.pagerank('social', 'rank');
SELECT * FROM warren.vector_topk('social', 'rank', 3, NULL::bigint);

图会保存源查询。修改源表后执行 warren.refresh,使用 warren.info 查看版本,使用 warren.diff 比较差异。版本构建与切换会随外层事务一起回滚。

遍历与计算

接口用途
warren.bfs、warren.shortest_path广度优先遍历与最短路径
warren.pagerank、warren.components节点排名与连通分量
warren.leiden社区发现
warren.spmv、warren.gather将图计算组合到 SQL 中
warren.vector_topk读取已存向量中最大的值
warren.shared_cache、warren.backends检查共享条目与后端缓存使用情况

标识符类型必须与图一致。没有节点标识符参数的函数可能需要 NULL::bigint 这样的类型示例值。0.8.0 的 PageRank 与 Leiden 使用原生计算内核,将结果写入命名向量。

内存与预加载

PostgreSQL 17–18 会在首次使用时初始化共享缓存。PostgreSQL 15–16 要在后端间共享图数据,需要配置以下参数并重启服务器:

shared_preload_libraries = 'pg_warren'

PostgreSQL 15–16 未预加载时仍可执行图操作,但使用各后端的私有缓存。如果已有预加载列表,应将该库追加到列表中。

warren.shared_cache_memory 限制整个集群的共享缓存,重新加载配置后生效。warren.max_cache_memory、warren.max_compute_memory 与 warren.max_build_memory 分别限制私有缓存、计算与构建分配,不是同一个总内存预算。warren.threads 控制计算并行度。Linux 上的共享条目还需要足够的 /dev/shm 空间,放不下的条目会退回私有缓存。

访问、备份与升级

源查询以图所有者身份执行,并使用保存的 search_path。应显式限定源对象模式,并使用受控模式。公共函数检查图访问权限;安装扩展不会授予私有目录表的直接访问权。

应以超级用户转储,包含图目录、版本与向量,并在恢复前建立所需的所有者和读取者角色。从源表重建图不能保留历史图版本。安装新库文件后,在每个使用该扩展的数据库执行 ALTER EXTENSION pg_warren UPDATE。删除扩展会删除已存图。该项目尚未到 1.0,不会增量维护图快照。

表格阅读器