audit
pg_audit · Audits insert, update, and delete operations on PostgreSQL tables.
Overview
Usage
Sources:
audit is a small SQL-only row-change audit prototype. It provides an audit table and a trigger function intended to capture the old or new row as jsonb after INSERT, UPDATE, and DELETE. Version 1.0.0 is an old, unfinished artifact; inspect and patch its SQL before relying on it.
Core Workflow
The intended workflow is to install the extension, then attach its audit() trigger function to every table that needs row-level history:
For inserts and updates the trigger is intended to store NEW; for deletes it stores OLD. The archived flag is application-managed and is not an automatic retention policy.
Objects
audit: audit-row table with ajsonbpayload, relation OID, operation enum, and archive flag.operation: enum withINSERT,UPDATE, andDELETEvalues.audit(): row-trigger function.audit_id(jsonb): extracts anidproperty asbigint.audit_oid(name, name): intended to resolve a schema and relation name to an OID.oid_metadata: view over relation and schema metadata.
Caveats
The published 1.0.0 SQL is internally inconsistent: the table column is named op, while the trigger inserts into operation; audit_oid also compares parameter names that shadow its selected columns. The script’s final \echo names a different extension. As published, the trigger example therefore requires an upstream SQL review and corrective patch before it can work reliably.
The trigger stores complete row images and has no pruning, tamper protection, actor/session metadata, or DDL auditing. Restrict access to the audit table, define retention explicitly, and test storage and write-amplification costs on a disposable database before considering real use.