pgmemento
pgmemento : Transaction-based audit trail with schema versioning
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 7190 | pgmemento
|
pgmemento
|
0.7.4 |
SEC
|
LGPL-3.0
|
SQL
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
----d--
|
No
|
No
|
No
|
Yes
|
no
|
no
|
| Relationships | |
|---|---|
| Schemas | pgmemento |
| See Also | table_log
table_version
ddl_historization
|
Packages upgrade scripts from 0.7, 0.7.1, 0.7.2, and 0.7.3 to 0.7.4.
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY
|
0.7.4 |
18
17
16
15
14
|
pgmemento |
- |
| RPM | PIGSTY
|
0.7.4 |
18
17
16
15
14
|
pgmemento_$v |
- |
| DEB | PIGSTY
|
0.7.4 |
18
17
16
15
14
|
postgresql-$v-pgmemento |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
el8.aarch64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
el9.x86_64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
el9.aarch64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
el10.x86_64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
el10.aarch64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
d12.x86_64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
d12.aarch64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
d13.x86_64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
d13.aarch64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
u22.x86_64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
u22.aarch64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
u24.x86_64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
u24.aarch64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
u26.x86_64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
u26.aarch64
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
PIGSTY 0.7.4
|
Source
pig build pkg pgmemento; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pgmemento; # install via package name, for the active PG version
pig install pgmemento -v 18; # install for PG 18
pig install pgmemento -v 17; # install for PG 17
pig install pgmemento -v 16; # install for PG 16
pig install pgmemento -v 15; # install for PG 15
pig install pgmemento -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION pgmemento;Usage
Sources:
pgmemento is a trigger-based audit trail for PostgreSQL. It records DML changes as JSONB deltas, groups them by transaction and table event, tracks audited schema changes, and provides restore and revert helpers. Use it when row history and transaction context must be queried inside PostgreSQL.
Create and Initialize
CREATE EXTENSION pgmemento;
SELECT pgmemento.init('public');
init instruments eligible tables in the selected schema and adds the pgmemento_audit_id identity column used to track row history. Run it first on a staging copy: auditing changes table definitions and installs event and row triggers.
Use start and stop to control auditing for a schema, and use the documented drop function when intentionally removing pgMemento’s instrumentation. Do not manually delete extension triggers or audit identifiers.
Inspect the Audit Trail
The central data model includes:
- transaction_log: transaction metadata and optional application context.
- table_event_log: table-level events within a transaction.
- row_log: JSONB row deltas linked to a table event.
- audited_schema and audited_table metadata: tracked schemas, tables, columns, and versions.
A typical investigation joins a transaction to its table events and row deltas:
SELECT t.id,
t.txid_time,
e.table_operation,
r.audit_id,
r.old_data,
r.new_data
FROM pgmemento.transaction_log AS t
JOIN pgmemento.table_event_log AS e
ON e.transaction_id = t.id
JOIN pgmemento.row_log AS r
ON r.event_key = e.event_key
WHERE t.id = 12345;
Inspect the installed views and column names before embedding this query because audit schema details can differ across pgmemento versions.
Restore and Revert
pgmemento provides restore functions that reconstruct table state from the audit trail and revert_transaction or related helpers that apply compensating changes. Treat these as recovery operations:
- take and verify a backup;
- identify the exact transaction and dependent changes;
- preview reconstructed data where possible;
- run the operation in a controlled transaction;
- validate constraints, sequences, and application invariants.
Version 0.7.4
Version 0.7.4 changes row serialization to avoid PostgreSQL’s jsonb_build_object argument limit for very wide payloads and adds PostgreSQL 15 support. Upgrade using ALTER EXTENSION pgmemento UPDATE only after testing the version-specific upgrade script.
Operational Boundaries
- Audit triggers add latency and write volume to every tracked change. Monitor row_log growth and index maintenance.
- The audit trail resides in the same database and is not a substitute for backups, WAL archives, or tamper-resistant external audit storage.
- Schema initialization and DDL tracking alter application tables. Coordinate migrations with pgmemento rather than bypassing its event triggers.
- Limit direct writes to the pgmemento schema and protect any transaction metadata that can contain user or application information.