pg_auditor
Audit data changes and provide flashback ability
Repository
kouber/pg_auditor
https://github.com/kouber/pg_auditor
Source
pg_auditor-0.2.tar.gz
pg_auditor-0.2.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_auditor | 0.2 | SEC | BSD 3-Clause | SQL |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 7130 | pg_auditor | No | No | No | Yes | No | Yes | - |
| Related | pg_drop_events table_log pgaudit temporal_tables emaj pg_savior pg_upless pgauditlogtofile |
|---|
pg15 rpm pkg name is pgaudit17_$v*
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.2 | 1817161514 | pg_auditor | - |
| RPM | PIGSTY | 0.2 | 1817161514 | pg_auditor_$v | - |
| DEB | PIGSTY | 0.2 | 1817161514 | postgresql-$v-pg-auditor | - |
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 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
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.