pgaudit
pgaudit : provides auditing functionality
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 7100 | pgaudit | pgaudit | 19.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 pg_auditor pg_roast pgmemento table_log pg_drop_events pgelog logerrors pg_stat_log pg_auth_mon data_historization table_version |
Packages
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PIGSTY 1.7.2 |
| el8.aarch64 | N/A | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PIGSTY 1.7.2 |
| el9.x86_64 | PGDG 19.0 | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PIGSTY 1.7.2 |
| el9.aarch64 | PGDG 19.0 | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PIGSTY 1.7.2 |
| el10.x86_64 | PGDG 19.0 | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PIGSTY 1.7.2 |
| el10.aarch64 | PGDG 19.0 | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PIGSTY 1.7.2 |
| d12.x86_64 | PGDG 19.0 | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PGDG 1.7.2 |
| d12.aarch64 | PGDG 19.0 | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PGDG 1.7.2 |
| d13.x86_64 | PGDG 19.0 | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PGDG 1.7.2 |
| d13.aarch64 | PGDG 19.0 | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PGDG 1.7.2 |
| u22.x86_64 | PGDG 19.0 | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PGDG 1.7.2 |
| u22.aarch64 | PGDG 19.0 | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PGDG 1.7.2 |
| u24.x86_64 | PGDG 19.0 | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PGDG 1.7.2 |
| u24.aarch64 | PGDG 19.0 | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PGDG 1.7.2 |
| u26.x86_64 | PGDG 19.0 | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PGDG 1.7.2 |
| u26.aarch64 | PGDG 19.0 | PGDG 18.1 | PGDG 17.2 | PGDG 16.2 | PGDG 1.7.2 |
Source
github.com/pgaudit/pgaudit
pgaudit-1.7.2.tar.gz
Install
Make sure PGDG repo available:
Install this extension with pig:
Config this extension to shared_preload_libraries:
Create this extension with:
Usage
Sources:
pgaudit records session and object events through PostgreSQL logging. Use the branch matching the server: 19.0 for PostgreSQL 19, 18.1 for 18, 17.2 for 17, 16.2 for 16, 1.7.2 for 15 and 1.6.4 for 14. The branches are separate server builds; upgrading PostgreSQL does not make an older library ABI-compatible.
Enable auditing
Add pgaudit to shared_preload_libraries and restart the server. As a superuser, create the extension before setting pgaudit.log:
Only a superuser can change audit settings. Size and protect the log volume: SQL text and parameters can contain sensitive information, and broad logging can consume substantial space. The extension provides audit records; it does not itself establish compliance.
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:
Log everything except miscellaneous commands:
Example output:
Object Audit Logging
Grant permissions to an audit role to control which relations are logged:
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.
Logging boundary
Audit output is best-effort PostgreSQL logging, outside transaction durability. A rolled-back statement can leave an audit record, and a committed transaction is not guaranteed to have a durable audit record. Protect and collect logs separately; do not treat them as a transactionally complete ledger.