pg_ledger
pg_extensions · Provides a double-entry accounting engine with immutable journals, fiscal periods, currencies and posting rules inside PostgreSQL.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 101067 | pg_ledger | pg_extensions | 0.3.0 | FEAT | Matroid-SAL-1.0 | Rust |
PostgreSQL · 14, 15, 16, 17
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
- CHANGELOG.md
- LICENSE
- Extension control file
- Ledger SQL API and transaction checks
- Account-rule implementation
pg_ledger version 0.3.0 is a double-entry accounting engine in the fixed pgledger schema. It records immutable journal headers and lines, checks transaction-level debit/credit balance, manages currencies and fiscal periods, and can generate entries from rules attached to application tables.
Core Workflow
Post balanced entries in one transaction and query the resulting account totals:
The central type is pgledger.ledgeramount, with arithmetic, comparisons, B-tree indexing, and sum, min, and max aggregates. Core entry functions are debit, credit, entry, reverse, and check_balance. Administration functions include create_rule, enable_rule, disable_rule, drop_rule, set_exchange_rate, convert, open_period, close_period, and period_status.
Operational Notes
The extension rejects unbalanced ledger activity before commit when pg_ledger.enabled is on. pg_ledger.strict_mode controls whether mutations of ledger-amount columns without rules raise an error; both are superuser-settable session GUCs. Journal tables are protected by immutability triggers, so corrections use reverse rather than UPDATE or DELETE. The control file is non-relocatable and superuser-only. Validate rule-generated accounts, rounding, savepoints, fiscal closing, backup/restore, and application authorization before treating the journal as an accounting control.
Version 0.3.0 Boundary
This is an unsupported proof of concept under Matroid Source Available License 1.0. APIs may change. Version 0.3.0 is the new upgrade baseline: earlier 0.2.0 installations require a rehearsed data migration/recreation, not ordinary ALTER EXTENSION UPDATE. Back up data and dependencies before following that destructive upstream path.