跳转到主要内容

pg_accumulator

PostgreSQL 中用于余额与周转跟踪的累积寄存器

pg_accumulator · PostgreSQL 中用于余额与周转跟踪的累积寄存器

概览

ID扩展软件包版本类别许可证编程语言
4845pg_accumulatorpg_accumulator1.2.0FUNCPostgreSQLC
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d--否是否是否否
关联
模式accum
依赖plpgsql
相关扩展currency financial omni_ledger

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY1.2.019 18 17 16 15pg_accumulatorplpgsql
RPMPIGSTY1.2.019 18 17 16 15pg_accumulator_$v-
DEBPIGSTY1.2.019 18 17 16 15postgresql-$v-pg-accumulator-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
el8.aarch64N/APIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
el9.x86_64PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
el9.aarch64PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
el10.x86_64PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
el10.aarch64PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
d12.x86_64PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
d12.aarch64PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
d13.x86_64PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
d13.aarch64PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
u22.x86_64PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
u22.aarch64PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
u24.x86_64PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
u24.aarch64PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
u26.x86_64PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
u26.aarch64PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0PIGSTY 1.2.0
软件包版本平台仓库大小下载
pg_accumulator_191.2.0el9.x86_64pigsty72.9 KiBpg_accumulator_19-1.2.0-1PGSTY.el9.x86_64.rpm
pg_accumulator_191.2.0el9.aarch64pigsty72.5 KiBpg_accumulator_19-1.2.0-1PGSTY.el9.aarch64.rpm
pg_accumulator_191.2.0el10.x86_64pigsty73.2 KiBpg_accumulator_19-1.2.0-1PGSTY.el10.x86_64.rpm
pg_accumulator_191.2.0el10.aarch64pigsty72.9 KiBpg_accumulator_19-1.2.0-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-accumulator1.2.0d12.x86_64pigsty54.9 KiBpostgresql-19-pg-accumulator_1.2.0-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-accumulator1.2.0d12.aarch64pigsty54.8 KiBpostgresql-19-pg-accumulator_1.2.0-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-accumulator1.2.0d13.x86_64pigsty55.0 KiBpostgresql-19-pg-accumulator_1.2.0-1PGSTY~trixie_amd64.deb
postgresql-19-pg-accumulator1.2.0d13.aarch64pigsty54.8 KiBpostgresql-19-pg-accumulator_1.2.0-1PGSTY~trixie_arm64.deb
postgresql-19-pg-accumulator1.2.0u22.x86_64pigsty56.4 KiBpostgresql-19-pg-accumulator_1.2.0-1PGSTY~jammy_amd64.deb
postgresql-19-pg-accumulator1.2.0u22.aarch64pigsty56.3 KiBpostgresql-19-pg-accumulator_1.2.0-1PGSTY~jammy_arm64.deb
postgresql-19-pg-accumulator1.2.0u24.x86_64pigsty56.2 KiBpostgresql-19-pg-accumulator_1.2.0-1PGSTY~noble_amd64.deb
postgresql-19-pg-accumulator1.2.0u24.aarch64pigsty55.9 KiBpostgresql-19-pg-accumulator_1.2.0-1PGSTY~noble_arm64.deb
postgresql-19-pg-accumulator1.2.0u26.x86_64pigsty56.0 KiBpostgresql-19-pg-accumulator_1.2.0-1PGSTY~resolute_amd64.deb
postgresql-19-pg-accumulator1.2.0u26.aarch64pigsty55.8 KiBpostgresql-19-pg-accumulator_1.2.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_accumulator_181.2.0el8.x86_64pigsty75.1 KiBpg_accumulator_18-1.2.0-1PGSTY.el8.x86_64.rpm
pg_accumulator_181.2.0el8.aarch64pigsty74.8 KiBpg_accumulator_18-1.2.0-1PGSTY.el8.aarch64.rpm
pg_accumulator_181.2.0el9.x86_64pigsty73.2 KiBpg_accumulator_18-1.2.0-1PGSTY.el9.x86_64.rpm
pg_accumulator_181.2.0el9.aarch64pigsty72.4 KiBpg_accumulator_18-1.2.0-1PGSTY.el9.aarch64.rpm
pg_accumulator_181.2.0el10.x86_64pigsty73.3 KiBpg_accumulator_18-1.2.0-1PGSTY.el10.x86_64.rpm
pg_accumulator_181.2.0el10.aarch64pigsty72.9 KiBpg_accumulator_18-1.2.0-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-accumulator1.2.0d12.x86_64pigsty54.9 KiBpostgresql-18-pg-accumulator_1.2.0-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-accumulator1.2.0d12.aarch64pigsty54.6 KiBpostgresql-18-pg-accumulator_1.2.0-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-accumulator1.2.0d13.x86_64pigsty54.9 KiBpostgresql-18-pg-accumulator_1.2.0-1PGSTY~trixie_amd64.deb
postgresql-18-pg-accumulator1.2.0d13.aarch64pigsty54.7 KiBpostgresql-18-pg-accumulator_1.2.0-1PGSTY~trixie_arm64.deb
postgresql-18-pg-accumulator1.2.0u22.x86_64pigsty56.5 KiBpostgresql-18-pg-accumulator_1.2.0-1PGSTY~jammy_amd64.deb
postgresql-18-pg-accumulator1.2.0u22.aarch64pigsty56.3 KiBpostgresql-18-pg-accumulator_1.2.0-1PGSTY~jammy_arm64.deb
postgresql-18-pg-accumulator1.2.0u24.x86_64pigsty56.0 KiBpostgresql-18-pg-accumulator_1.2.0-1PGSTY~noble_amd64.deb
postgresql-18-pg-accumulator1.2.0u24.aarch64pigsty55.7 KiBpostgresql-18-pg-accumulator_1.2.0-1PGSTY~noble_arm64.deb
postgresql-18-pg-accumulator1.2.0u26.x86_64pigsty56.1 KiBpostgresql-18-pg-accumulator_1.2.0-1PGSTY~resolute_amd64.deb
postgresql-18-pg-accumulator1.2.0u26.aarch64pigsty55.8 KiBpostgresql-18-pg-accumulator_1.2.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_accumulator_171.2.0el8.x86_64pigsty75.1 KiBpg_accumulator_17-1.2.0-1PGSTY.el8.x86_64.rpm
pg_accumulator_171.2.0el8.aarch64pigsty74.8 KiBpg_accumulator_17-1.2.0-1PGSTY.el8.aarch64.rpm
pg_accumulator_171.2.0el9.x86_64pigsty73.2 KiBpg_accumulator_17-1.2.0-1PGSTY.el9.x86_64.rpm
pg_accumulator_171.2.0el9.aarch64pigsty72.3 KiBpg_accumulator_17-1.2.0-1PGSTY.el9.aarch64.rpm
pg_accumulator_171.2.0el10.x86_64pigsty73.3 KiBpg_accumulator_17-1.2.0-1PGSTY.el10.x86_64.rpm
pg_accumulator_171.2.0el10.aarch64pigsty72.8 KiBpg_accumulator_17-1.2.0-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-accumulator1.2.0d12.x86_64pigsty54.8 KiBpostgresql-17-pg-accumulator_1.2.0-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-accumulator1.2.0d12.aarch64pigsty54.6 KiBpostgresql-17-pg-accumulator_1.2.0-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-accumulator1.2.0d13.x86_64pigsty54.8 KiBpostgresql-17-pg-accumulator_1.2.0-1PGSTY~trixie_amd64.deb
postgresql-17-pg-accumulator1.2.0d13.aarch64pigsty54.7 KiBpostgresql-17-pg-accumulator_1.2.0-1PGSTY~trixie_arm64.deb
postgresql-17-pg-accumulator1.2.0u22.x86_64pigsty57.8 KiBpostgresql-17-pg-accumulator_1.2.0-1PGSTY~jammy_amd64.deb
postgresql-17-pg-accumulator1.2.0u22.aarch64pigsty57.5 KiBpostgresql-17-pg-accumulator_1.2.0-1PGSTY~jammy_arm64.deb
postgresql-17-pg-accumulator1.2.0u24.x86_64pigsty56.0 KiBpostgresql-17-pg-accumulator_1.2.0-1PGSTY~noble_amd64.deb
postgresql-17-pg-accumulator1.2.0u24.aarch64pigsty55.7 KiBpostgresql-17-pg-accumulator_1.2.0-1PGSTY~noble_arm64.deb
postgresql-17-pg-accumulator1.2.0u26.x86_64pigsty56.1 KiBpostgresql-17-pg-accumulator_1.2.0-1PGSTY~resolute_amd64.deb
postgresql-17-pg-accumulator1.2.0u26.aarch64pigsty55.8 KiBpostgresql-17-pg-accumulator_1.2.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_accumulator_161.2.0el8.x86_64pigsty75.1 KiBpg_accumulator_16-1.2.0-1PGSTY.el8.x86_64.rpm
pg_accumulator_161.2.0el8.aarch64pigsty74.7 KiBpg_accumulator_16-1.2.0-1PGSTY.el8.aarch64.rpm
pg_accumulator_161.2.0el9.x86_64pigsty73.2 KiBpg_accumulator_16-1.2.0-1PGSTY.el9.x86_64.rpm
pg_accumulator_161.2.0el9.aarch64pigsty72.3 KiBpg_accumulator_16-1.2.0-1PGSTY.el9.aarch64.rpm
pg_accumulator_161.2.0el10.x86_64pigsty73.3 KiBpg_accumulator_16-1.2.0-1PGSTY.el10.x86_64.rpm
pg_accumulator_161.2.0el10.aarch64pigsty72.8 KiBpg_accumulator_16-1.2.0-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-accumulator1.2.0d12.x86_64pigsty54.8 KiBpostgresql-16-pg-accumulator_1.2.0-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-accumulator1.2.0d12.aarch64pigsty54.6 KiBpostgresql-16-pg-accumulator_1.2.0-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-accumulator1.2.0d13.x86_64pigsty54.8 KiBpostgresql-16-pg-accumulator_1.2.0-1PGSTY~trixie_amd64.deb
postgresql-16-pg-accumulator1.2.0d13.aarch64pigsty54.7 KiBpostgresql-16-pg-accumulator_1.2.0-1PGSTY~trixie_arm64.deb
postgresql-16-pg-accumulator1.2.0u22.x86_64pigsty57.8 KiBpostgresql-16-pg-accumulator_1.2.0-1PGSTY~jammy_amd64.deb
postgresql-16-pg-accumulator1.2.0u22.aarch64pigsty57.5 KiBpostgresql-16-pg-accumulator_1.2.0-1PGSTY~jammy_arm64.deb
postgresql-16-pg-accumulator1.2.0u24.x86_64pigsty56.0 KiBpostgresql-16-pg-accumulator_1.2.0-1PGSTY~noble_amd64.deb
postgresql-16-pg-accumulator1.2.0u24.aarch64pigsty55.7 KiBpostgresql-16-pg-accumulator_1.2.0-1PGSTY~noble_arm64.deb
postgresql-16-pg-accumulator1.2.0u26.x86_64pigsty56.1 KiBpostgresql-16-pg-accumulator_1.2.0-1PGSTY~resolute_amd64.deb
postgresql-16-pg-accumulator1.2.0u26.aarch64pigsty55.8 KiBpostgresql-16-pg-accumulator_1.2.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_accumulator_151.2.0el8.x86_64pigsty75.2 KiBpg_accumulator_15-1.2.0-1PGSTY.el8.x86_64.rpm
pg_accumulator_151.2.0el8.aarch64pigsty74.8 KiBpg_accumulator_15-1.2.0-1PGSTY.el8.aarch64.rpm
pg_accumulator_151.2.0el9.x86_64pigsty73.2 KiBpg_accumulator_15-1.2.0-1PGSTY.el9.x86_64.rpm
pg_accumulator_151.2.0el9.aarch64pigsty72.5 KiBpg_accumulator_15-1.2.0-1PGSTY.el9.aarch64.rpm
pg_accumulator_151.2.0el10.x86_64pigsty73.4 KiBpg_accumulator_15-1.2.0-1PGSTY.el10.x86_64.rpm
pg_accumulator_151.2.0el10.aarch64pigsty73.0 KiBpg_accumulator_15-1.2.0-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-accumulator1.2.0d12.x86_64pigsty54.9 KiBpostgresql-15-pg-accumulator_1.2.0-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-accumulator1.2.0d12.aarch64pigsty54.6 KiBpostgresql-15-pg-accumulator_1.2.0-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-accumulator1.2.0d13.x86_64pigsty54.9 KiBpostgresql-15-pg-accumulator_1.2.0-1PGSTY~trixie_amd64.deb
postgresql-15-pg-accumulator1.2.0d13.aarch64pigsty54.7 KiBpostgresql-15-pg-accumulator_1.2.0-1PGSTY~trixie_arm64.deb
postgresql-15-pg-accumulator1.2.0u22.x86_64pigsty57.9 KiBpostgresql-15-pg-accumulator_1.2.0-1PGSTY~jammy_amd64.deb
postgresql-15-pg-accumulator1.2.0u22.aarch64pigsty57.7 KiBpostgresql-15-pg-accumulator_1.2.0-1PGSTY~jammy_arm64.deb
postgresql-15-pg-accumulator1.2.0u24.x86_64pigsty56.2 KiBpostgresql-15-pg-accumulator_1.2.0-1PGSTY~noble_amd64.deb
postgresql-15-pg-accumulator1.2.0u24.aarch64pigsty55.8 KiBpostgresql-15-pg-accumulator_1.2.0-1PGSTY~noble_arm64.deb
postgresql-15-pg-accumulator1.2.0u26.x86_64pigsty56.2 KiBpostgresql-15-pg-accumulator_1.2.0-1PGSTY~resolute_amd64.deb
postgresql-15-pg-accumulator1.2.0u26.aarch64pigsty56.0 KiBpostgresql-15-pg-accumulator_1.2.0-1PGSTY~resolute_arm64.deb

源码

pig build pkg pg_accumulator;		# build rpm/deb

安装

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

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

使用 pig 安装扩展。

pig install pg_accumulator;		# install by package name

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

在数据库中创建扩展。

CREATE EXTENSION pg_accumulator CASCADE; -- requires plpgsql

用法

来源:README,documentation,control file

pg_accumulator 为 PostgreSQL 提供声明式累积寄存器。寄存器按任意维度和资源记录业务流水,并生成余额、发生额、流水历史、校验和重建等查询与维护函数。

启用

CREATE EXTENSION pg_accumulator;

如果高写入场景需要 delta buffer 和后台 worker,需要预加载共享库并重启 PostgreSQL:

shared_preload_libraries = 'pg_accumulator'

创建寄存器

SELECT accum.register_create(
  name := 'inventory',
  dimensions := '{"warehouse": "int", "product": "int"}',
  resources := '{"quantity": "numeric", "amount": "numeric"}',
  kind := 'balance'
);

一次调用会创建寄存器元数据、流水表、汇总表、余额缓存、触发器、生成查询函数和配套索引。

记账与查询

SELECT accum.register_post('inventory', '{
  "period": "2026-04-01",
  "document": "receipt:1",
  "dimensions": {"warehouse": 1, "product": 42},
  "resources": {"quantity": 10, "amount": 250}
}');

SELECT * FROM accum.inventory_balance(
  dimensions := '{"warehouse": 1, "product": 42}'
);

SELECT * FROM accum.inventory_turnover(
  from_date := '2026-04-01',
  to_date := '2026-04-30',
  dimensions := '{"warehouse": 1}',
  group_by := '["product"]'
);

更正与维护

使用 register_unpost 和 register_repost 处理追溯更正。必要时使用 register_verify、register_rebuild_totals、register_rebuild_cache 校验和修复派生状态。

SELECT accum.register_unpost('inventory', 'receipt:1');
SELECT accum.register_verify('inventory');

配置

文档中的 GUC 包括 pg_accumulator.background_workers、pg_accumulator.delta_merge_interval、pg_accumulator.delta_merge_delay、pg_accumulator.delta_merge_batch_size、pg_accumulator.partitions_ahead、pg_accumulator.maintenance_interval。

表格阅读器