table_version
table_version : PostgreSQL table versioning extension
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 1060 | table_version | table_version | 1.11.1 |
TIME | BSD-3-Clause | SQL |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-- | No | Yes | No | Yes | no | no |
| Relationships | |
|---|---|
| Schemas | table_version |
| Requires | plpgsql |
| See Also | data_historization pgmemento table_log ddl_historization periods temporal_tables emaj pgaudit pg_drop_events pgauditlogtofile |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED | 1.11.1 |
18 17 16 15 14 | table_version |
plpgsql |
| RPM | PIGSTY | 1.11.1 |
18 17 16 15 14 | table_version_$v |
- |
| DEB | PIGSTY | 1.11.1 |
18 17 16 15 14 | postgresql-$v-table-version |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PGDG 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 |
| el8.aarch64 | PGDG 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 |
| el9.x86_64 | PGDG 1.11.1 | PGDG 1.11.1 | PGDG 1.11.1 | PGDG 1.11.1 | PGDG 1.11.1 |
| el9.aarch64 | PGDG 1.11.1 | PGDG 1.11.1 | PGDG 1.11.1 | PGDG 1.11.1 | PGDG 1.11.1 |
| el10.x86_64 | PGDG 1.11.1 | PGDG 1.11.1 | PGDG 1.11.1 | PGDG 1.11.1 | PGDG 1.11.1 |
| el10.aarch64 | PGDG 1.11.1 | PGDG 1.11.1 | PGDG 1.11.1 | PGDG 1.11.1 | PGDG 1.11.1 |
| d12.x86_64 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 |
| d12.aarch64 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 |
| d13.x86_64 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 |
| d13.aarch64 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 |
| u22.x86_64 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 |
| u22.aarch64 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 |
| u24.x86_64 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 |
| u24.aarch64 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 |
| u26.x86_64 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 |
| u26.aarch64 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 | PIGSTY 1.11.1 |
Source
github.com/linz/postgresql-tableversion
postgresql-tableversion-1.11.1.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
PostgreSQL table versioning extension, recording row modifications and its history. The extension provides APIs for accessing snapshots of a table at certain revisions and the difference generated between any two given revisions. It uses a PL/PgSQL trigger based system to record and provide access to row revisions.
Quick Start
How It Works
When a table is versioned, the original table data is left untouched and a new revision table is created with all the same fields plus _revision_created and _revision_expired fields. A row-level trigger is set up on the original table to record every insert, update and delete in the revision data table. A statement-level trigger is set up to forbid TRUNCATE.
Table Prerequisites
- The table must have a unique non-composite integer, bigint, text or varchar column
- The table must not be temporary
Auto Revisions
If you don’t want to call ver_create_revision and ver_complete_revision explicitly, auto-revision mode groups edits by transactions:
The revision message will be automatically created based on the transaction ID.
Replicate Data Using Table Differences
To maintain a copy of table data on a remote system:
Security Model
- Anyone can create revisions
- Revisions can only be completed by their creators
- Only those who have ownership privileges on a table can enable/disable versioning
- Only empty revisions can be deleted
- Only the creator of a revision can delete it
Note: Disabling versioning on a table results in all history for that table being deleted.
Key Functions
| Function | Description |
|---|---|
ver_enable_versioning(schema, table) |
Enable versioning on a table |
ver_disable_versioning(schema, table) |
Disable versioning and remove history |
ver_create_revision(comment) |
Create a new revision |
ver_complete_revision() |
Mark current revision as complete |
ver_get_<schema>_<table>_diff(rev1, rev2) |
Get differences between two revisions |
ver_get_<schema>_<table>_revision(rev) |
Get snapshot at a specific revision |
ver_get_versioned_tables() |
List all versioned tables |
ver_get_last_revision() |
Get the last revision number |