Skip to content

pg_auditor

Audit data changes and provide flashback ability

pg_auditor · Audit data changes and provide flashback ability

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
7130pg_auditorpg_auditor0.3SECBSD-3-ClauseSQL
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
----d--NoNoNoYesnono

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY0.319 18 17 16 15pg_auditorhstore
RPMPIGSTY0.3.019 18 17 16 15pg_auditor_$v-
DEBPIGSTY0.3.019 18 17 16 15postgresql-$v-pg-auditor-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.3PIGSTY 0.3PIGSTY 0.3PIGSTY 0.3
el8.aarch64N/APIGSTY 0.3PIGSTY 0.3PIGSTY 0.3PIGSTY 0.3
el9.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
el9.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
el10.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
el10.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
d12.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
d12.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
d13.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
d13.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u22.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u22.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u24.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u24.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u26.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u26.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
PackageVersionOSORGSIZEFile URL
pg_auditor_190.3.0el9.x86_64pigsty14.7 KiBpg_auditor_19-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_190.3.0el9.aarch64pigsty14.7 KiBpg_auditor_19-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_190.3.0el10.x86_64pigsty14.8 KiBpg_auditor_19-0.3.0-1PGSTY.el10.noarch.rpm
pg_auditor_190.3.0el10.aarch64pigsty14.8 KiBpg_auditor_19-0.3.0-1PGSTY.el10.noarch.rpm
postgresql-19-pg-auditor0.3.0d12.x86_64pigsty8.7 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-19-pg-auditor0.3.0d12.aarch64pigsty8.7 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-19-pg-auditor0.3.0d13.x86_64pigsty8.7 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-19-pg-auditor0.3.0d13.aarch64pigsty8.7 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-19-pg-auditor0.3.0u22.x86_64pigsty8.5 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-19-pg-auditor0.3.0u22.aarch64pigsty8.5 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-19-pg-auditor0.3.0u24.x86_64pigsty8.5 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-19-pg-auditor0.3.0u24.aarch64pigsty8.5 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-19-pg-auditor0.3.0u26.x86_64pigsty8.5 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
postgresql-19-pg-auditor0.3.0u26.aarch64pigsty8.5 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
PackageVersionOSORGSIZEFile URL
pg_auditor_180.3el8.x86_64pigsty14.8 KiBpg_auditor_18-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_180.3el8.aarch64pigsty14.8 KiBpg_auditor_18-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_180.3.0el9.x86_64pigsty14.7 KiBpg_auditor_18-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_180.3.0el9.aarch64pigsty14.7 KiBpg_auditor_18-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_180.3.0el10.x86_64pigsty14.8 KiBpg_auditor_18-0.3.0-1PGSTY.el10.noarch.rpm
pg_auditor_180.3.0el10.aarch64pigsty14.8 KiBpg_auditor_18-0.3.0-1PGSTY.el10.noarch.rpm
postgresql-18-pg-auditor0.3.0d12.x86_64pigsty8.7 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-18-pg-auditor0.3.0d12.aarch64pigsty8.7 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-18-pg-auditor0.3.0d13.x86_64pigsty8.7 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-18-pg-auditor0.3.0d13.aarch64pigsty8.7 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-18-pg-auditor0.3.0u22.x86_64pigsty8.5 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-18-pg-auditor0.3.0u22.aarch64pigsty8.5 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-18-pg-auditor0.3.0u24.x86_64pigsty8.5 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-18-pg-auditor0.3.0u24.aarch64pigsty8.5 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-18-pg-auditor0.3.0u26.x86_64pigsty8.5 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
postgresql-18-pg-auditor0.3.0u26.aarch64pigsty8.5 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
PackageVersionOSORGSIZEFile URL
pg_auditor_170.3el8.x86_64pigsty14.8 KiBpg_auditor_17-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_170.3el8.aarch64pigsty14.8 KiBpg_auditor_17-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_170.3.0el9.x86_64pigsty14.7 KiBpg_auditor_17-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_170.3.0el9.aarch64pigsty14.7 KiBpg_auditor_17-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_170.3.0el10.x86_64pigsty14.8 KiBpg_auditor_17-0.3.0-1PGSTY.el10.noarch.rpm
pg_auditor_170.3.0el10.aarch64pigsty14.8 KiBpg_auditor_17-0.3.0-1PGSTY.el10.noarch.rpm
postgresql-17-pg-auditor0.3.0d12.x86_64pigsty8.7 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-17-pg-auditor0.3.0d12.aarch64pigsty8.7 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-17-pg-auditor0.3.0d13.x86_64pigsty8.7 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-17-pg-auditor0.3.0d13.aarch64pigsty8.7 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-17-pg-auditor0.3.0u22.x86_64pigsty8.5 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-17-pg-auditor0.3.0u22.aarch64pigsty8.5 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-17-pg-auditor0.3.0u24.x86_64pigsty8.5 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-17-pg-auditor0.3.0u24.aarch64pigsty8.5 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-17-pg-auditor0.3.0u26.x86_64pigsty8.5 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
postgresql-17-pg-auditor0.3.0u26.aarch64pigsty8.5 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
PackageVersionOSORGSIZEFile URL
pg_auditor_160.3el8.x86_64pigsty14.8 KiBpg_auditor_16-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_160.3el8.aarch64pigsty14.8 KiBpg_auditor_16-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_160.3.0el9.x86_64pigsty14.7 KiBpg_auditor_16-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_160.3.0el9.aarch64pigsty14.7 KiBpg_auditor_16-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_160.3.0el10.x86_64pigsty14.8 KiBpg_auditor_16-0.3.0-1PGSTY.el10.noarch.rpm
pg_auditor_160.3.0el10.aarch64pigsty14.8 KiBpg_auditor_16-0.3.0-1PGSTY.el10.noarch.rpm
postgresql-16-pg-auditor0.3.0d12.x86_64pigsty8.7 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-16-pg-auditor0.3.0d12.aarch64pigsty8.7 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-16-pg-auditor0.3.0d13.x86_64pigsty8.7 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-16-pg-auditor0.3.0d13.aarch64pigsty8.7 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-16-pg-auditor0.3.0u22.x86_64pigsty8.5 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-16-pg-auditor0.3.0u22.aarch64pigsty8.5 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-16-pg-auditor0.3.0u24.x86_64pigsty8.5 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-16-pg-auditor0.3.0u24.aarch64pigsty8.5 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-16-pg-auditor0.3.0u26.x86_64pigsty8.5 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
postgresql-16-pg-auditor0.3.0u26.aarch64pigsty8.5 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
PackageVersionOSORGSIZEFile URL
pg_auditor_150.3el8.x86_64pigsty14.8 KiBpg_auditor_15-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_150.3el8.aarch64pigsty14.8 KiBpg_auditor_15-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_150.3.0el9.x86_64pigsty14.7 KiBpg_auditor_15-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_150.3.0el9.aarch64pigsty14.7 KiBpg_auditor_15-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_150.3.0el10.x86_64pigsty14.8 KiBpg_auditor_15-0.3.0-1PGSTY.el10.noarch.rpm
pg_auditor_150.3.0el10.aarch64pigsty14.8 KiBpg_auditor_15-0.3.0-1PGSTY.el10.noarch.rpm
postgresql-15-pg-auditor0.3.0d12.x86_64pigsty8.7 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-15-pg-auditor0.3.0d12.aarch64pigsty8.7 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-15-pg-auditor0.3.0d13.x86_64pigsty8.7 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-15-pg-auditor0.3.0d13.aarch64pigsty8.7 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-15-pg-auditor0.3.0u22.x86_64pigsty8.5 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-15-pg-auditor0.3.0u22.aarch64pigsty8.5 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-15-pg-auditor0.3.0u24.x86_64pigsty8.5 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-15-pg-auditor0.3.0u24.aarch64pigsty8.5 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-15-pg-auditor0.3.0u26.x86_64pigsty8.5 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
postgresql-15-pg-auditor0.3.0u26.aarch64pigsty8.5 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~resolute_all.deb

Source

pig build pkg pg_auditor;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_auditor;		# install by package name

pig install pg_auditor -v 19;   # install for PG 19
pig install pg_auditor -v 18;   # install for PG 18
pig install pg_auditor -v 17;   # install for PG 17
pig install pg_auditor -v 16;   # install for PG 16
pig install pg_auditor -v 15;   # install for PG 15

Create this extension with:

CREATE EXTENSION pg_auditor CASCADE; -- requires hstore

Usage

pg_auditor: Audit data changes with flashback capability

pg_auditor records each data modification (INSERT, UPDATE, DELETE) on specified tables and allows partial or complete flashback of transactions.

CREATE EXTENSION pg_auditor CASCADE;  -- also installs hstore

Auditing Control

-- Start auditing a table (all DML by default)
SELECT auditor.attach('fruit');

-- Audit specific operations only
SELECT auditor.attach('fruit', ARRAY['INSERT', 'UPDATE']);

-- Audit specific columns only
SELECT auditor.attach('fruit', ARRAY['INSERT', 'UPDATE', 'DELETE'], ARRAY['name', 'weight']);

-- Stop auditing
SELECT auditor.detach('fruit');

-- Manage individual statements/columns
SELECT auditor.attach_statement('fruit', 'DELETE');
SELECT auditor.detach_statement('fruit', 'DELETE');
SELECT auditor.attach_column('fruit', 'weight');
SELECT auditor.detach_column('fruit', 'weight');

-- Protect against TRUNCATE
SELECT auditor.forbid_truncate('fruit');

Viewing Audit Log

SELECT transaction_id, operation, old_rec, new_rec FROM auditor.log;

Flashback Functions

-- Undo the last N transactions in current session
SELECT auditor.undo();          -- undo last 1
SELECT auditor.undo(3);         -- undo last 3
SELECT auditor.undo(1, true);   -- override other sessions

-- Cancel a specific transaction
SELECT auditor.cancel(5557);

-- Restore data to a specific transaction or timestamp
SELECT auditor.flashback(5556);
SELECT auditor.flashback('2021-02-08 14:40:00'::timestamp);

Column Evolution Tracking

SELECT * FROM auditor.evolution('fruit'::regclass, 'weight', 'orange'::text);
-- Shows complete history of a column value for a given primary key

Table reader