pg_accumulator
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_accumulator | 1.1.3 | FUNC | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4845 | pg_accumulator | No | Yes | No | Yes | No | No | accum |
| Related | plpgsql financial topn quantile first_last_agg |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.1.3 | 1817161514 | pg_accumulator | plpgsql |
| RPM | PIGSTY | 1.1.3 | 1817161514 | pg_accumulator_$v | - |
| DEB | PIGSTY | 1.1.3 | 1817161514 | postgresql-$v-pg-accumulator | - |
Build
You can build the RPM / DEB packages for pg_accumulator using pig build:
pig build pkg pg_accumulator # build RPM / DEB packages
Install
You can install pg_accumulator directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pg_accumulator; # Install for current active PG version
pig ext install -y pg_accumulator -v 18 # PG 18
pig ext install -y pg_accumulator -v 17 # PG 17
pig ext install -y pg_accumulator -v 16 # PG 16
pig ext install -y pg_accumulator -v 15 # PG 15
pig ext install -y pg_accumulator -v 14 # PG 14
dnf install -y pg_accumulator_18 # PG 18
dnf install -y pg_accumulator_17 # PG 17
dnf install -y pg_accumulator_16 # PG 16
dnf install -y pg_accumulator_15 # PG 15
dnf install -y pg_accumulator_14 # PG 14
apt install -y postgresql-18-pg-accumulator # PG 18
apt install -y postgresql-17-pg-accumulator # PG 17
apt install -y postgresql-16-pg-accumulator # PG 16
apt install -y postgresql-15-pg-accumulator # PG 15
apt install -y postgresql-14-pg-accumulator # PG 14
Create Extension:
CREATE EXTENSION pg_accumulator CASCADE; -- requires: plpgsql
Usage
Sources: README, documentation, control file
pg_accumulator implements declarative accumulation registers for PostgreSQL. A register records movements across arbitrary dimensions and resources, then exposes generated functions for balances, turnovers, movement history, verification, and rebuild operations.
Enable
CREATE EXTENSION pg_accumulator;
For high-write workloads that use the delta buffer and background worker, preload the library and restart PostgreSQL:
shared_preload_libraries = 'pg_accumulator'
Create A Register
SELECT accum.register_create(
name := 'inventory',
dimensions := '{"warehouse": "int", "product": "int"}',
resources := '{"quantity": "numeric", "amount": "numeric"}',
kind := 'balance'
);
The call creates the register metadata, movement table, total tables, balance cache, triggers, generated query functions, and supporting indexes.
Post And Query Movements
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"]'
);
Corrections And Maintenance
Use register_unpost and register_repost for retroactive corrections. Use register_verify, register_rebuild_totals, and register_rebuild_cache to check and repair derived state when needed.
SELECT accum.register_unpost('inventory', 'receipt:1');
SELECT accum.register_verify('inventory');
Configuration
The documented GUCs include pg_accumulator.background_workers, pg_accumulator.delta_merge_interval, pg_accumulator.delta_merge_delay, pg_accumulator.delta_merge_batch_size, pg_accumulator.partitions_ahead, and pg_accumulator.maintenance_interval.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.