table_log
table_log
table_log : record table modification logs and PITR for table/row
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 5860 | table_log | table_log | 0.6.4 | ADMIN | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-- | No | Yes | No | Yes | no | no |
| Relationships | |
|---|---|
| See Also | temporal_tables emaj pg_drop_events pg_auditor pg_upless pg_savior pgaudit pgauditlogtofile |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED | 0.6.4 | 18 17 16 15 14 | table_log | - |
| RPM | PIGSTY | 0.6.4 | 18 17 16 15 14 | table_log_$v | - |
| DEB | PGDG | 0.6.4 | 18 17 16 15 14 | postgresql-$v-tablelog | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 |
el8.aarch64 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 |
el9.x86_64 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 |
el9.aarch64 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 |
el10.x86_64 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 |
el10.aarch64 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 | PIGSTY 0.6.4 |
d12.x86_64 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 |
d12.aarch64 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 |
d13.x86_64 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 |
d13.aarch64 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 |
u22.x86_64 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 |
u22.aarch64 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 |
u24.x86_64 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 |
u24.aarch64 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 | PGDG 0.6.4 |
Source
pig build pkg table_log; # build rpmInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install table_log; # install via package name, for the active PG version
pig install table_log -v 18; # install for PG 18
pig install table_log -v 17; # install for PG 17
pig install table_log -v 16; # install for PG 16
pig install table_log -v 15; # install for PG 15
pig install table_log -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION table_log;Usage
table_log: record table modification logs and PITR for table/row
The table_log extension records INSERT, UPDATE, and DELETE operations on a table into a separate log table, enabling point-in-time recovery at the table or row level.
Initialize Logging
CREATE EXTENSION table_log;
-- Basic setup: creates a log table and trigger for 'my_table'
-- Level 5 = log trigger_id + trigger_user + trigger columns
SELECT table_log_init(5, 'my_table');
-- With explicit log schema
SELECT table_log_init(5, 'my_table', 'log_schema');
-- Full form with all options
SELECT table_log_init(
5, -- level: 3=minimal, 4=+user, 5=+id+user
'public', -- source schema
'my_table', -- source table
'log_schema', -- log table schema
'my_table_log', -- log table name (default: {table}_log)
'SINGLE', -- partition mode: 'SINGLE' or 'PARTITION'
false, -- basic_mode (simpler trigger)
'{INSERT, UPDATE, DELETE}'::text[] -- actions to log
);Log Table Structure
The log table mirrors the original table columns plus metadata:
| Column | Description |
|---|---|
trigger_mode | Operation type: INSERT, UPDATE, DELETE |
trigger_tuple | Tuple version: ‘old’ or ’new’ |
trigger_changed | Timestamp of the change |
trigger_id | Sequential ID (level 4+) |
trigger_user | User who made the change (level 5) |
Point-in-Time Restore
-- Restore table to a specific point in time
SELECT table_log_restore_table(
'my_table', -- original table name
'my_table_log', -- log table name
'id', -- primary key column
'trigger_changed', -- timestamp column in log
'trigger_tuple', -- tuple type column in log
'2024-01-15 10:30:00' -- restore to this timestamp
);Trigger Functions
| Function | Description |
|---|---|
table_log() | Full trigger function logging all columns |
table_log_basic() | Basic trigger function with simpler logging |
table_log_restore_table(...) | Restore table state to a given timestamp |
Last updated on