flux
flux · Logs table data changes and reconstructs rows as they existed in the past.
Overview
| Relationships | |
|---|---|
| Requires | hstore |
Usage
Sources:
flux is a pure-SQL, trigger-based row-history extension. For each enabled table it records reverse changes for INSERT, UPDATE, and DELETE, allowing a row to be reconstructed at an earlier timestamp or its complete history to be returned. It requires hstore, a primary key, and the fixed _flux schema.
Enable and query history
_flux.enable_change_logging() also supports include or exclude column lists and an optional retention interval. _flux.get_row_from_history() reconstructs one row in the table’s current composite type. _flux.disable_change_logging() removes the triggers, while _flux.cleanup() later drops disabled log tables and applies retention.
Flux stores reverse diffs rather than an initial snapshot. Consequently, TRUNCATE loses the current state needed to reconstruct live rows. Primary-key value changes are rejected; renaming a tracked table breaks its metadata; changing primary keys or column types requires a carefully planned disable/cleanup/re-enable cycle; and dropped columns disappear from typed historical reconstruction. Disabling needs an exclusive table lock, while cleanup is destructive to the selected history tables. Version 0.3 is old and has no current compatibility matrix, so validate locking, storage growth, schema migration, and restore behavior before operational use.