pg_auditor

pg_auditor

pg_auditor : Audit data changes and provide flashback ability

Overview

ID Extension Package Version Category License Language
7130
pg_auditor
pg_auditor
0.2
SEC
BSD 3-Clause
SQL
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
----d--
No
No
No
Yes
no
no
Relationships
Schemas auditor
Requires
hstore
See Also
pg_drop_events
table_log
pgaudit
temporal_tables
emaj
pg_savior
pg_upless
pgauditlogtofile

pg15 rpm pkg name is pgaudit17_$v*

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
0.2
18
17
16
15
14
pg_auditor hstore
RPM
PIGSTY
0.2
18
17
16
15
14
pg_auditor_$v -
DEB
PIGSTY
0.2
18
17
16
15
14
postgresql-$v-pg-auditor -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
el8.aarch64
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
el9.x86_64
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
el9.aarch64
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
el10.x86_64
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
el10.aarch64
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
PIGSTY 0.2
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
Package Version OS ORG SIZE File URL
pg_auditor_18 0.2 el8.x86_64 pigsty 11.0 KiB pg_auditor_18-0.2-1PIGSTY.el8.x86_64.rpm
pg_auditor_18 0.2 el8.aarch64 pigsty 11.0 KiB pg_auditor_18-0.2-1PIGSTY.el8.aarch64.rpm
pg_auditor_18 0.2 el9.x86_64 pigsty 10.9 KiB pg_auditor_18-0.2-1PIGSTY.el9.x86_64.rpm
pg_auditor_18 0.2 el9.aarch64 pigsty 10.9 KiB pg_auditor_18-0.2-1PIGSTY.el9.aarch64.rpm
pg_auditor_18 0.2 el10.x86_64 pigsty 11.0 KiB pg_auditor_18-0.2-1PIGSTY.el10.x86_64.rpm
pg_auditor_18 0.2 el10.aarch64 pigsty 10.9 KiB pg_auditor_18-0.2-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-auditor 0.2 d12.x86_64 pigsty 8.1 KiB postgresql-18-pg-auditor_0.2-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-auditor 0.2 d12.aarch64 pigsty 8.1 KiB postgresql-18-pg-auditor_0.2-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-auditor 0.2 d13.x86_64 pigsty 8.1 KiB postgresql-18-pg-auditor_0.2-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-auditor 0.2 d13.aarch64 pigsty 8.1 KiB postgresql-18-pg-auditor_0.2-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-auditor 0.2 u22.x86_64 pigsty 8.0 KiB postgresql-18-pg-auditor_0.2-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-auditor 0.2 u22.aarch64 pigsty 8.0 KiB postgresql-18-pg-auditor_0.2-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-auditor 0.2 u24.x86_64 pigsty 8.0 KiB postgresql-18-pg-auditor_0.2-1PIGSTY~noble_amd64.deb
postgresql-18-pg-auditor 0.2 u24.aarch64 pigsty 8.0 KiB postgresql-18-pg-auditor_0.2-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_auditor_17 0.2 el8.x86_64 pigsty 11.0 KiB pg_auditor_17-0.2-1PIGSTY.el8.x86_64.rpm
pg_auditor_17 0.2 el8.aarch64 pigsty 11.0 KiB pg_auditor_17-0.2-1PIGSTY.el8.aarch64.rpm
pg_auditor_17 0.2 el9.x86_64 pigsty 10.9 KiB pg_auditor_17-0.2-1PIGSTY.el9.x86_64.rpm
pg_auditor_17 0.2 el9.aarch64 pigsty 10.9 KiB pg_auditor_17-0.2-1PIGSTY.el9.aarch64.rpm
pg_auditor_17 0.2 el10.x86_64 pigsty 11.0 KiB pg_auditor_17-0.2-1PIGSTY.el10.x86_64.rpm
pg_auditor_17 0.2 el10.aarch64 pigsty 10.9 KiB pg_auditor_17-0.2-1PIGSTY.el10.aarch64.rpm
postgresql-17-pg-auditor 0.2 d12.x86_64 pigsty 8.1 KiB postgresql-17-pg-auditor_0.2-1PIGSTY~bookworm_amd64.deb
postgresql-17-pg-auditor 0.2 d12.aarch64 pigsty 8.1 KiB postgresql-17-pg-auditor_0.2-1PIGSTY~bookworm_arm64.deb
postgresql-17-pg-auditor 0.2 d13.x86_64 pigsty 8.1 KiB postgresql-17-pg-auditor_0.2-1PIGSTY~trixie_amd64.deb
postgresql-17-pg-auditor 0.2 d13.aarch64 pigsty 8.1 KiB postgresql-17-pg-auditor_0.2-1PIGSTY~trixie_arm64.deb
postgresql-17-pg-auditor 0.2 u22.x86_64 pigsty 8.0 KiB postgresql-17-pg-auditor_0.2-1PIGSTY~jammy_amd64.deb
postgresql-17-pg-auditor 0.2 u22.aarch64 pigsty 8.0 KiB postgresql-17-pg-auditor_0.2-1PIGSTY~jammy_arm64.deb
postgresql-17-pg-auditor 0.2 u24.x86_64 pigsty 8.0 KiB postgresql-17-pg-auditor_0.2-1PIGSTY~noble_amd64.deb
postgresql-17-pg-auditor 0.2 u24.aarch64 pigsty 8.0 KiB postgresql-17-pg-auditor_0.2-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_auditor_16 0.2 el8.x86_64 pigsty 11.0 KiB pg_auditor_16-0.2-1PIGSTY.el8.x86_64.rpm
pg_auditor_16 0.2 el8.aarch64 pigsty 11.0 KiB pg_auditor_16-0.2-1PIGSTY.el8.aarch64.rpm
pg_auditor_16 0.2 el9.x86_64 pigsty 10.9 KiB pg_auditor_16-0.2-1PIGSTY.el9.x86_64.rpm
pg_auditor_16 0.2 el9.aarch64 pigsty 10.9 KiB pg_auditor_16-0.2-1PIGSTY.el9.aarch64.rpm
pg_auditor_16 0.2 el10.x86_64 pigsty 11.0 KiB pg_auditor_16-0.2-1PIGSTY.el10.x86_64.rpm
pg_auditor_16 0.2 el10.aarch64 pigsty 10.9 KiB pg_auditor_16-0.2-1PIGSTY.el10.aarch64.rpm
postgresql-16-pg-auditor 0.2 d12.x86_64 pigsty 8.1 KiB postgresql-16-pg-auditor_0.2-1PIGSTY~bookworm_amd64.deb
postgresql-16-pg-auditor 0.2 d12.aarch64 pigsty 8.1 KiB postgresql-16-pg-auditor_0.2-1PIGSTY~bookworm_arm64.deb
postgresql-16-pg-auditor 0.2 d13.x86_64 pigsty 8.1 KiB postgresql-16-pg-auditor_0.2-1PIGSTY~trixie_amd64.deb
postgresql-16-pg-auditor 0.2 d13.aarch64 pigsty 8.1 KiB postgresql-16-pg-auditor_0.2-1PIGSTY~trixie_arm64.deb
postgresql-16-pg-auditor 0.2 u22.x86_64 pigsty 8.0 KiB postgresql-16-pg-auditor_0.2-1PIGSTY~jammy_amd64.deb
postgresql-16-pg-auditor 0.2 u22.aarch64 pigsty 8.0 KiB postgresql-16-pg-auditor_0.2-1PIGSTY~jammy_arm64.deb
postgresql-16-pg-auditor 0.2 u24.x86_64 pigsty 8.0 KiB postgresql-16-pg-auditor_0.2-1PIGSTY~noble_amd64.deb
postgresql-16-pg-auditor 0.2 u24.aarch64 pigsty 8.0 KiB postgresql-16-pg-auditor_0.2-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_auditor_15 0.2 el8.x86_64 pigsty 11.0 KiB pg_auditor_15-0.2-1PIGSTY.el8.x86_64.rpm
pg_auditor_15 0.2 el8.aarch64 pigsty 11.0 KiB pg_auditor_15-0.2-1PIGSTY.el8.aarch64.rpm
pg_auditor_15 0.2 el9.x86_64 pigsty 10.9 KiB pg_auditor_15-0.2-1PIGSTY.el9.x86_64.rpm
pg_auditor_15 0.2 el9.aarch64 pigsty 10.9 KiB pg_auditor_15-0.2-1PIGSTY.el9.aarch64.rpm
pg_auditor_15 0.2 el10.x86_64 pigsty 11.0 KiB pg_auditor_15-0.2-1PIGSTY.el10.x86_64.rpm
pg_auditor_15 0.2 el10.aarch64 pigsty 10.9 KiB pg_auditor_15-0.2-1PIGSTY.el10.aarch64.rpm
postgresql-15-pg-auditor 0.2 d12.x86_64 pigsty 8.1 KiB postgresql-15-pg-auditor_0.2-1PIGSTY~bookworm_amd64.deb
postgresql-15-pg-auditor 0.2 d12.aarch64 pigsty 8.1 KiB postgresql-15-pg-auditor_0.2-1PIGSTY~bookworm_arm64.deb
postgresql-15-pg-auditor 0.2 d13.x86_64 pigsty 8.1 KiB postgresql-15-pg-auditor_0.2-1PIGSTY~trixie_amd64.deb
postgresql-15-pg-auditor 0.2 d13.aarch64 pigsty 8.1 KiB postgresql-15-pg-auditor_0.2-1PIGSTY~trixie_arm64.deb
postgresql-15-pg-auditor 0.2 u22.x86_64 pigsty 8.0 KiB postgresql-15-pg-auditor_0.2-1PIGSTY~jammy_amd64.deb
postgresql-15-pg-auditor 0.2 u22.aarch64 pigsty 8.0 KiB postgresql-15-pg-auditor_0.2-1PIGSTY~jammy_arm64.deb
postgresql-15-pg-auditor 0.2 u24.x86_64 pigsty 8.0 KiB postgresql-15-pg-auditor_0.2-1PIGSTY~noble_amd64.deb
postgresql-15-pg-auditor 0.2 u24.aarch64 pigsty 8.0 KiB postgresql-15-pg-auditor_0.2-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_auditor_14 0.2 el8.x86_64 pigsty 11.0 KiB pg_auditor_14-0.2-1PIGSTY.el8.x86_64.rpm
pg_auditor_14 0.2 el8.aarch64 pigsty 11.0 KiB pg_auditor_14-0.2-1PIGSTY.el8.aarch64.rpm
pg_auditor_14 0.2 el9.x86_64 pigsty 10.9 KiB pg_auditor_14-0.2-1PIGSTY.el9.x86_64.rpm
pg_auditor_14 0.2 el9.aarch64 pigsty 10.9 KiB pg_auditor_14-0.2-1PIGSTY.el9.aarch64.rpm
pg_auditor_14 0.2 el10.x86_64 pigsty 11.0 KiB pg_auditor_14-0.2-1PIGSTY.el10.x86_64.rpm
pg_auditor_14 0.2 el10.aarch64 pigsty 10.9 KiB pg_auditor_14-0.2-1PIGSTY.el10.aarch64.rpm
postgresql-14-pg-auditor 0.2 d12.x86_64 pigsty 8.1 KiB postgresql-14-pg-auditor_0.2-1PIGSTY~bookworm_amd64.deb
postgresql-14-pg-auditor 0.2 d12.aarch64 pigsty 8.1 KiB postgresql-14-pg-auditor_0.2-1PIGSTY~bookworm_arm64.deb
postgresql-14-pg-auditor 0.2 d13.x86_64 pigsty 8.1 KiB postgresql-14-pg-auditor_0.2-1PIGSTY~trixie_amd64.deb
postgresql-14-pg-auditor 0.2 d13.aarch64 pigsty 8.1 KiB postgresql-14-pg-auditor_0.2-1PIGSTY~trixie_arm64.deb
postgresql-14-pg-auditor 0.2 u22.x86_64 pigsty 8.0 KiB postgresql-14-pg-auditor_0.2-1PIGSTY~jammy_amd64.deb
postgresql-14-pg-auditor 0.2 u22.aarch64 pigsty 8.0 KiB postgresql-14-pg-auditor_0.2-1PIGSTY~jammy_arm64.deb
postgresql-14-pg-auditor 0.2 u24.x86_64 pigsty 8.0 KiB postgresql-14-pg-auditor_0.2-1PIGSTY~noble_amd64.deb
postgresql-14-pg-auditor 0.2 u24.aarch64 pigsty 8.0 KiB postgresql-14-pg-auditor_0.2-1PIGSTY~noble_arm64.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 via package name, for the active PG version

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
pig install pg_auditor -v 14;   # install for PG 14

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
Last updated on