Records user logins and SQL actions for security and compliance.
Access auditing captures login events and SQL statements, letting you answer who touched what and when. With the pgAudit
extension you gain fine-grained, SQL-level logs that satisfy SOC, HIPAA, and PCI requirements.
log_statement
records every query, creating noise. pgAudit
filters by action class (READ, WRITE, ROLE, DDL) and object, producing audit-ready logs while controlling volume.
1. Install the package: CREATE EXTENSION pgaudit;
2. Add shared_preload_libraries = 'pgaudit'
in postgresql.conf
and restart.
3. Reload config after setting parameters shown in the syntax block.
Set pgaudit.log_relation = 'Customers,Orders,OrderItems'
. PostgreSQL now emits audit rows only when those tables are accessed.
Entries flow into the regular PostgreSQL logs with the prefix AUDIT:
. Forward them to a centralized system (CloudWatch, Splunk, ELK) for retention and alerting.
Query your log aggregator for connection authorized: user=<>
and FATAL: password authentication failed
. Combine with pgAudit records to see if a compromised user executed SQL.
Keep pgaudit.log_parameter = on
to capture bind values.
Use log rotation and compression to control disk usage.
Periodically test that required statements are captured by replaying sample queries.
Restart required: editing shared_preload_libraries
without restart leaves pgAudit inactive. Bounce the server and verify with SHOW shared_preload_libraries;
.
Excessive volume: logging READ
against high-traffic tables can flood storage. Limit tables or switch to WRITE,DDL,ROLE
only.
Enable pgAudit, scope tables, forward logs, and periodically review them. You now have traceability for every critical row in your ecommerce database.
Overhead is ~520% for logged statements. Limit scope to critical tables to keep impact negligible.
Yes. Set pgaudit.log = 'read'
and optionally list tables in pgaudit.log_relation
.
Amazon RDS and Google Cloud SQL offer pgAudit. Enable it in the instance parameters, then follow the same configuration steps shown above.