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
|
Source
pig build pkg pg_auditor; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Create this extension with:
CREATE EXTENSION pg_auditor CASCADE; -- requires hstoreUsage
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 hstoreAuditing 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 keyLast updated on