Skip to content

flux

Logs table data changes and reconstructs rows as they existed in the past.

flux · Logs table data changes and reconstructs rows as they existed in the past.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100220fluxflux0.3TIMEUnknownSQL
Relationships
Requireshstore

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

CREATE EXTENSION hstore;
CREATE EXTENSION flux;

CREATE TABLE public.accounts (
  id bigint PRIMARY KEY,
  status text NOT NULL
);

SELECT _flux.enable_change_logging(
  'public', 'accounts', '_accounts_history'
);

INSERT INTO public.accounts VALUES (1, 'new');
UPDATE public.accounts SET status = 'active' WHERE id = 1;

SELECT *
FROM _flux.get_row_history('public', 'accounts', '"id"=>"1"'::hstore);

_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.

Table reader