pg_auditor

Audit data changes and provide flashback ability

Overview

PackageVersionCategoryLicenseLanguage
pg_auditor0.2SECBSD 3-ClauseSQL
IDExtensionBinLibLoadCreateTrustRelocSchema
7130pg_auditorNoNoNoYesNoYes-
Relatedpg_drop_events table_log pgaudit temporal_tables emaj pg_savior pg_upless pgauditlogtofile

pg15 rpm pkg name is pgaudit17_$v*

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.21817161514pg_auditor-
RPMPIGSTY0.21817161514pg_auditor_$v-
DEBPIGSTY0.21817161514postgresql-$v-pg-auditor-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
d12.aarch64
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
d13.x86_64
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
d13.aarch64
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
u22.x86_64
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
u22.aarch64
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
u24.x86_64
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
u24.aarch64
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2

Build

You can build the RPM / DEB packages for pg_auditor using pig build:

pig build pkg pg_auditor         # build RPM / DEB packages

Install

You can install pg_auditor directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

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

Install the extension using pig or apt/yum/dnf:

pig install pg_auditor;          # Install for current active PG version
pig ext install -y pg_auditor -v 18  # PG 18
pig ext install -y pg_auditor -v 17  # PG 17
pig ext install -y pg_auditor -v 16  # PG 16
pig ext install -y pg_auditor -v 15  # PG 15
pig ext install -y pg_auditor -v 14  # PG 14
dnf install -y pg_auditor_18       # PG 18
dnf install -y pg_auditor_17       # PG 17
dnf install -y pg_auditor_16       # PG 16
dnf install -y pg_auditor_15       # PG 15
dnf install -y pg_auditor_14       # PG 14
apt install -y postgresql-18-pg-auditor   # PG 18
apt install -y postgresql-17-pg-auditor   # PG 17
apt install -y postgresql-16-pg-auditor   # PG 16
apt install -y postgresql-15-pg-auditor   # PG 15
apt install -y postgresql-14-pg-auditor   # PG 14

Create Extension:

CREATE EXTENSION pg_auditor;

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

Last Modified 2026-03-12: add pg extension catalog (95749bf)