Use it for security monitoring and compliance.
Database Auditing
Database auditing records who did what — logins, privilege changes, DDL and access to sensitive data — using pgAudit, MariaDB audit plugin, MySQL Enterprise Audit or SQL Server Audit.
1. Audit enabled? (pgaudit.log, server_audit_logging, sys.server_audits).
2. What is audited?
3. Logs shipped centrally.
4. Test with a privileged action.
5. Review volume.
action → audit rule → record → central log
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Run a test DDL and a test login failure and confirm both appear centrally. Review audit volume against storage.
Step 2 Common failures Narrow the fault
Auditing every SELECT on a busy system can hurt performance and fill disks. Logs stored only locally can be lost or altered. Shared accounts make audit records useless for knowing who acted.
Audit privileged actions and sensitive tables, not every SELECT. Ship audit logs off the server. Watch performance impact.
sys.server_audits— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
ReferenceWhat it is1 section · depth on demand
How it works
Audit components hook into the server and write records for matching events: connection, statement class, object access. Volume grows quickly when all reads are audited.
ReferenceImportant terms & boundaries3 sections · depth on demand
Auditing options
| Database | Tool |
|---|---|
| PostgreSQL | pgAudit extension, log_connections, log_statement = 'ddl' |
| MySQL | Enterprise Audit, Percona Audit Log plugin |
| MariaDB | server_audit plugin |
| SQL Server | SQL Server Audit (server and database audit specifications) |
Audit logins, privilege changes, DDL and access to sensitive tables; send logs to a SIEM where DBAs cannot change them. Logging every SELECT is usually too heavy.
In depth
Decide what the audit must answer first
| Question | Log |
|---|---|
| Who logged in, from where, and who failed? | Connections and authentication failures |
| Who changed the schema or permissions? | DDL and GRANT/REVOKE, role changes |
| Who changed sensitive data? | DML on selected tables |
| Who read sensitive data? | SELECT on selected tables only — expensive if broad |
Logging every statement on a busy system produces gigabytes per hour that nobody reads and can slow the server.
PostgreSQL with pgAudit
shared_preload_libraries = 'pgaudit'
pgaudit.log = 'ddl, role, write' # session audit classes
pgaudit.log_relation = on
log_connections = on
log_disconnections = on
Object auditing limits logging to chosen tables: create a role (for example auditor), set pgaudit.role = 'auditor', and grant that role SELECT on exactly the tables whose reads must be logged.
MySQL / MariaDB / SQL Server
| Engine | Mechanism |
|---|---|
| MySQL Enterprise | Audit plugin with JSON filter rules |
| MySQL community / Percona | Percona Audit Log plugin |
| MariaDB | server_audit plugin (server_audit_events = CONNECT,QUERY_DDL,QUERY_DCL) |
| SQL Server | Server and database audit specifications (CREATE SERVER AUDIT …) |
Making the audit trustworthy
Ship audit records off the database server immediately (syslog/agent to a central store the DBAs cannot modify), alert on gaps in delivery, keep clocks synchronised with NTP, and use personal accounts for humans — a shared dba login makes every record anonymous.
Common mistakes
- Auditing everything and filling disks.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.