pgaudit
pgaudit : provides auditing functionality
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 7100 | pgaudit | pgaudit | 18.0 | SEC | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--sLd-r | No | Yes | Yes | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | pgauditlogtofile set_user pg_permissions pg_auth_mon pg_auditor safeupdate pg_drop_events table_log |
pg15=pgaudit17, pg14=pgaudit16
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG | 18.0 | 18 17 16 15 14 | pgaudit | - |
| RPM | PGDG | 18.0 | 18 17 16 15 14 | pgaudit_$v | - |
| DEB | PGDG | 18.0 | 18 17 16 15 14 | postgresql-$v-pgaudit | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PGDG 18.0 | PGDG 17.1 | PGDG 16.1 | PGDG 1.7.1 | PGDG 1.6.3 |
el8.aarch64 | PGDG 18.0 | PGDG 17.1 | PGDG 16.1 | PGDG 1.7.1 | PGDG 1.6.3 |
el9.x86_64 | PGDG 18.0 | PGDG 17.1 | PGDG 16.1 | PGDG 1.7.1 | PGDG 1.6.3 |
el9.aarch64 | PGDG 18.0 | PGDG 17.1 | PGDG 16.1 | PGDG 1.7.1 | PGDG 1.6.3 |
el10.x86_64 | PGDG 18.0 | PGDG 17.1 | PGDG 16.1 | PGDG 1.7.1 | PGDG 1.6.3 |
el10.aarch64 | PGDG 18.0 | PGDG 17.1 | PGDG 16.1 | PGDG 1.7.1 | PGDG 1.6.3 |
d12.x86_64 | PGDG 18.0 | PGDG 17.1 | PGDG 16.1 | PGDG 1.7.1 | PGDG 1.6.3 |
d12.aarch64 | PGDG 18.0 | PGDG 17.1 | PGDG 16.1 | PGDG 1.7.1 | PGDG 1.6.3 |
d13.x86_64 | PGDG 18.0 | PGDG 17.1 | PGDG 16.1 | PGDG 1.7.1 | PGDG 1.6.3 |
d13.aarch64 | PGDG 18.0 | PGDG 17.1 | PGDG 16.1 | PGDG 1.7.1 | PGDG 1.6.3 |
u22.x86_64 | PGDG 18.0 | PGDG 17.1 | PGDG 16.1 | PGDG 1.7.1 | PGDG 1.6.3 |
u22.aarch64 | PGDG 18.0 | PGDG 17.1 | PGDG 16.1 | PGDG 1.7.1 | PGDG 1.6.3 |
u24.x86_64 | PGDG 18.0 | PGDG 17.1 | PGDG 16.1 | PGDG 1.7.1 | PGDG 1.6.3 |
u24.aarch64 | PGDG 18.0 | PGDG 17.1 | PGDG 16.1 | PGDG 1.7.1 | PGDG 1.6.3 |
Source
Install
Make sure PGDG repo available:
pig repo add pgdg -u # add pgdg repo and update cacheInstall this extension with pig:
pig install pgaudit; # install via package name, for the active PG version
pig install pgaudit -v 18; # install for PG 18
pig install pgaudit -v 17; # install for PG 17
pig install pgaudit -v 16; # install for PG 16
pig install pgaudit -v 15; # install for PG 15
pig install pgaudit -v 14; # install for PG 14Config this extension to shared_preload_libraries:
shared_preload_libraries = 'pgaudit';Create this extension with:
CREATE EXTENSION pgaudit;Usage
pgAudit provides detailed session and/or object audit logging via the standard PostgreSQL logging facility, producing audit trails required for government, financial, or ISO certifications.
CREATE EXTENSION pgaudit;Configuration Parameters
| Parameter | Default | Description |
|---|---|---|
pgaudit.log | none | Statement classes to log: READ, WRITE, FUNCTION, ROLE, DDL, MISC, MISC_SET, ALL |
pgaudit.log_catalog | on | Log statements when all relations are in pg_catalog |
pgaudit.log_client | off | Show audit log messages to client |
pgaudit.log_level | log | Log level for audit entries |
pgaudit.log_parameter | off | Include statement parameters in log |
pgaudit.log_parameter_max_size | 0 | Max parameter size in bytes (0=unlimited) |
pgaudit.log_relation | off | Separate log entry per relation in SELECT/DML |
pgaudit.log_rows | off | Include row count in log |
pgaudit.log_statement | on | Include statement text in log |
pgaudit.log_statement_once | off | Log statement text only with first entry |
pgaudit.role | (none) | Master role for object audit logging |
Session Audit Logging
Log all DML and DDL with per-relation detail:
SET pgaudit.log = 'write, ddl';
SET pgaudit.log_relation = on;Log everything except miscellaneous commands:
SET pgaudit.log = 'all, -misc';Example output:
AUDIT: SESSION,1,1,DDL,CREATE TABLE,TABLE,public.account,create table account(...)
AUDIT: SESSION,2,1,READ,SELECT,,,select * from accountObject Audit Logging
Grant permissions to an audit role to control which relations are logged:
SET pgaudit.role = 'auditor';
GRANT SELECT, DELETE
ON public.account
TO auditor;Now any SELECT or DELETE on the account table will be audit logged.
Log Format
Entries are CSV with fields: AUDIT_TYPE, STATEMENT_ID, SUBSTATEMENT_ID, CLASS, COMMAND, OBJECT_TYPE, OBJECT_NAME, STATEMENT, PARAMETER.