data_historization

PLPGSQL Script to historize data in partitionned table

Overview

PackageVersionCategoryLicenseLanguage
data_historization1.1.0UTILPostgreSQLSQL
IDExtensionBinLibLoadCreateTrustRelocSchema
4320data_historizationNoNoNoYesYesNo-
Relatedplpgsql ddl_historization temporal_tables table_version gzip bzip zstd http pg_net

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.1.01817161514data_historizationplpgsql
RPMPIGSTY1.1.01817161514data_historization_$v-
DEBPIGSTY1.1.01817161514postgresql-$v-data-historization-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
el8.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
el9.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
el9.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
el10.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
el10.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
d12.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
d12.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
d13.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
d13.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
u22.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
u22.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
u24.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
u24.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0

Build

You can build the RPM / DEB packages for data_historization using pig build:

pig build pkg data_historization         # build RPM / DEB packages

Install

You can install data_historization 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 data_historization;          # Install for current active PG version
pig ext install -y data_historization -v 18  # PG 18
pig ext install -y data_historization -v 17  # PG 17
pig ext install -y data_historization -v 16  # PG 16
pig ext install -y data_historization -v 15  # PG 15
pig ext install -y data_historization -v 14  # PG 14
dnf install -y data_historization_18       # PG 18
dnf install -y data_historization_17       # PG 17
dnf install -y data_historization_16       # PG 16
dnf install -y data_historization_15       # PG 15
dnf install -y data_historization_14       # PG 14
apt install -y postgresql-18-data-historization   # PG 18
apt install -y postgresql-17-data-historization   # PG 17
apt install -y postgresql-16-data-historization   # PG 16
apt install -y postgresql-15-data-historization   # PG 15
apt install -y postgresql-14-data-historization   # PG 14

Create Extension:

CREATE EXTENSION data_historization CASCADE;  -- requires: plpgsql

Usage

data_historization: Track data changes in partitioned log tables

PL/pgSQL scripts to historize data changes into partitioned tables.

Initialize Historization

Set up the necessary objects for a table (no data collected yet):

SELECT historize_table_init('public', 'my_table');

Start Historization

Install triggers to begin collecting changes into the _log table:

SELECT historize_table_start('public', 'my_table');

Stop Historization

Remove triggers and stop collecting changes:

SELECT historize_table_stop('public', 'my_table');

Reset Historization

Remove cron entries and columns created on the source table:

SELECT historize_table_reset('public', 'my_table');

Clean Historization

Remove the log table entirely:

SELECT historize_table_clean('public', 'my_table');

Partition Management

Create and drop partitions manually:

SELECT historize_create_partition('public', 'my_table_log', 0);
SELECT historize_drop_partition('public', 'my_table_log', 0);

Automate with pg_cron:

SELECT cron.schedule_in_database(
    'create-partitions', '00 08 * * *',
    $$SELECT historize_create_partition('my_table', generate_series(1, 4))$$,
    'my_database'
);

Last Modified 2026-03-12: add pg extension catalog (95749bf)