Pcornel
Browse topics
Options
Recent
Favorites
Databases · Technical reference

Database Auditing

Direct answer

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.

When to use this

Use it for security monitoring and compliance.

First 30 seconds

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.

Operational verification

action → audit rule → record → central log

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
MariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformMariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
Scope / prerequisiteUse it for security monitoring and compliance.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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.

Key points

Audit privileged actions and sensitive tables, not every SELECT. Ship audit logs off the server. Watch performance impact.

Key checks
  • sys.server_audits — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -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

DatabaseTool
PostgreSQLpgAudit extension, log_connections, log_statement = 'ddl'
MySQLEnterprise Audit, Percona Audit Log plugin
MariaDBserver_audit plugin
SQL ServerSQL 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

QuestionLog
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

EngineMechanism
MySQL EnterpriseAudit plugin with JSON filter rules
MySQL community / PerconaPercona Audit Log plugin
MariaDBserver_audit plugin (server_audit_events = CONNECT,QUERY_DDL,QUERY_DCL)
SQL ServerServer 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • Auditing everything and filling disks.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

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.

Aliases that resolve here
database auditingdatabase audit logpgaudit
Confirmation

Confirm action

Continue?