table_version
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
table_version | 1.11.1 | TIME | BSD-3-Clause | SQL |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 1060 | table_version | No | Yes | No | Yes | No | No | table_version |
| Related | plpgsql data_historization pgmemento table_log ddl_historization periods temporal_tables emaj pgaudit pg_drop_events pgauditlogtofile |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | MIXED | 1.11.1 | 1817161514 | table_version | plpgsql |
| RPM | PIGSTY | 1.11.1 | 1817161514 | table_version_$v | - |
| DEB | PIGSTY | 1.11.1 | 1817161514 | postgresql-$v-table-version | - |
Build
You can build the DEB packages for table_version using pig build:
Install
You can install table_version directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
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 |
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)