Skip to content

pg_temporal_tables

Temporal tables with transparent historical queries and user tracking

pg_temporal_tables · Temporal tables with transparent historical queries and user tracking

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102189pg_temporal_tablespg_temporal_tables0.1.1TIMEMITC

PostgreSQL · 18

Usage

Sources:

pg_temporal_tables records row history and rewrites queries for a selected historical time. The current implementation targets PostgreSQL 18 and requires preload and a server restart.

Core Workflow

shared_preload_libraries = 'pg_temporal_tables'
CREATE EXTENSION pg_temporal_tables;
CREATE TABLE users (id bigint PRIMARY KEY, name text);
SELECT temporal.enable('public.users');
SET temporal.user_id = 'operator';
INSERT INTO users VALUES (1, 'Alice');
UPDATE users SET name = 'Alicia' WHERE id = 1;

Operational Boundaries

A tracked table needs a primary key. temporal.enable() creates history tracking; temporal.disable() stops it. temporal.changes() and temporal.column_history() inspect changes; retention and compaction functions maintain history. Set temporal.user_id for attribution and reset temporal.as_of after historical reads. Track the root of a partitioned table; legacy inheritance and TimescaleDB hypertables are unsupported. Do not change or reuse primary keys without reviewing the lineage option. Installation requires a superuser. Back up the history together with the base data and review retention before deleting history.

Table reader