Skip to content

Commit 373b75d

Browse files
update db-audit-logging (#1049)
1 parent 6355d8d commit 373b75d

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

content/blog/database-audit-logging.md

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
2-
title: Database Audit Logging - The Practical Guide
2+
title: 'Database Audit Logging Best Practices for Compliance'
33
author: Adela
4-
updated_at: 2025/11/27 18:00:00
4+
updated_at: 2026/03/19 09:00:00
55
feature_image: /content/blog/database-audit-logging/banner.webp
6-
tags: Industry
7-
description: A guide to audit logging in databases.
6+
tags: Explanation
7+
description: 'How to set up database audit logging for SOC 2, HIPAA, and ISO 27001 compliance across PostgreSQL, MySQL, SQL Server, and Oracle.'
88
---
99

10-
Database audit logging is now a core security expectation, with standards like SOC 2, ISO 27001, GDPR, HIPAA, and PCI DSS requiring a complete record of **who accessed what, when, and from where**.
10+
Database audit logging records every query, schema change, and login attempt in your database so you can answer the question: **who did what, when, and from where**. It is a requirement for [SOC 2](/blog/soc2-data-security-and-retention-requirements/), ISO 27001, [GDPR](/blog/database-compliance-for-gdpr/), [HIPAA](/blog/hipaa-data-security-and-retention-requirements/), and PCI DSS compliance.
1111

12-
Yet building a consistent audit trail across different database engines is still challenging. This article explains why, what "good" looks like, and how to design a reliable auditing strategy.
12+
Building a consistent audit trail across PostgreSQL, MySQL, SQL Server, and Oracle is still hard because each engine handles auditing differently. This guide covers what to log, how each engine works, common mistakes, and how to get a unified audit trail.
1313

1414
## Why Audit Logging Matters
1515

@@ -32,7 +32,7 @@ Without reliable audit logs, organizations lack visibility at the exact moment i
3232

3333
## The Real-World Pain Today (Across All Major Databases)
3434

35-
All major relational databases MySQL, PostgreSQL, SQL Server, Oracle and cloud-managed variants like AWS RDS, Google Cloud SQL, and Azure Database provide audit capabilities. However, *how* they provide these capabilities varies dramatically, and implementing them correctly requires deep expertise.
35+
All major relational databases (MySQL, PostgreSQL, SQL Server, Oracle, and cloud-managed variants like AWS RDS, Google Cloud SQL, and Azure Database) provide audit capabilities. However, *how* they provide these capabilities varies dramatically, and implementing them correctly requires deep expertise.
3636

3737
Here are common issues teams encounter:
3838

@@ -44,9 +44,17 @@ Selective auditing (especially for non-root users) requires additional plugins t
4444
### PostgreSQL — Example
4545

4646
PostgreSQL relies on extensions such as `pgaudit` for structured auditing.
47-
While powerful, these extensions require **careful tuning** to avoid overwhelming log volume while still capturing all critical operations including SELECTs.
47+
While powerful, these extensions require **careful tuning** to avoid overwhelming log volume while still capturing all critical operations, including SELECTs.
4848

49-
### Cloud Databases (AWS RDS, Google Cloud SQL, Azure Database) — Example
49+
### SQL Server
50+
51+
SQL Server has built-in [SQL Server Audit](https://learn.microsoft.com/en-us/sql/relational-databases/security/auditing/sql-server-audit-database-engine) that writes to Windows Event Log or file targets. It supports fine-grained audit specifications at both server and database level. The main difficulty is managing audit file rotation and shipping logs to a central system, since SQL Server Audit writes binary files that need parsing.
52+
53+
### Oracle
54+
55+
Oracle provides [Unified Auditing](https://docs.oracle.com/en/database/oracle/oracle-database/19/dbseg/introduction-to-auditing.html) (available since 12c), which consolidates all audit records into a single `UNIFIED_AUDIT_TRAIL` view. It replaces the older `AUDIT` command. Oracle's auditing is the most granular of any major engine, but the volume of audit data in high-throughput systems requires careful management of the `AUDSYS` tablespace.
56+
57+
### Cloud databases (AWS RDS, Google Cloud SQL, Azure Database)
5058

5159
Cloud platforms wrap underlying engine audit logs into provider-specific formats.
5260
Teams often struggle with:
@@ -57,12 +65,12 @@ Teams often struggle with:
5765

5866
**In short:**
5967

60-
> Audit information exists everywhere but it’s fragmented, inconsistent, and often incomplete.
68+
> Audit information exists everywhere, but it’s fragmented, inconsistent, and often incomplete.
6169
6270
## What a Good Audit Log Should Capture
6371

6472
A reliable audit log must capture **every database action**, not just modifications.
65-
In modern security models, **access is just as important and often more important — than change**.
73+
In modern security models, **access is just as important as change, and often more so**.
6674

6775
### A robust audit log includes:
6876

@@ -73,7 +81,7 @@ In modern security models, **access is just as important — and often more impo
7381

7482
- **DDL** (all schema changes)
7583
- **DML** (INSERT, UPDATE, DELETE)
76-
- **SELECT** (all read operations because viewing sensitive data is a high-risk event)
84+
- **SELECT** (all read operations, because viewing sensitive data is a high-risk event)
7785

7886
- **Authentication events**
7987
Both successful logins and failed login attempts.
@@ -146,11 +154,35 @@ A workflow platform like **Bytebase** produces complete, contextual audit logs b
146154

147155
Regardless of database engine or auditing method, strong audit practices share the same foundations:
148156

149-
- **Use individual identities** — never share DB accounts.
150-
- **Record all DDL, DML, and SELECT** — access visibility is non-negotiable.
151-
- **Store logs off-host** prevents tampering or accidental deletion.
152-
- **Apply retention policies** (90, 180, or 365+ days).
157+
- **Use individual identities.** Never share DB accounts.
158+
- **Record all DDL, DML, and SELECT.** Access visibility is non-negotiable.
159+
- **Store logs off-host.** This prevents tampering or accidental deletion.
160+
- **Apply retention policies** (90, 180, or 365+ days depending on framework).
153161
- **Integrate logs into a SIEM** for alerting and correlation (Datadog, Splunk, CloudWatch, Grafana).
154-
- **Treat default engine settings cautiously** — they often require substantial tuning.
162+
- **Treat default engine settings cautiously.** They often require substantial tuning.
155163

156164
A minimal-noise, high-fidelity audit log is better than a noisy one that nobody can use.
165+
166+
## Common mistakes
167+
168+
| Mistake | What goes wrong | Fix |
169+
|---------|----------------|-----|
170+
| Logging everything at max verbosity | Log volume explodes, storage costs spike, nobody reads the logs | Start with DDL + DML + failed logins, add SELECTs only for sensitive tables |
171+
| Shared database accounts | Audit log says "admin" did it, but you have 15 people using that account | Map every query to an individual user identity |
172+
| Storing logs on the same host | An attacker or accidental `DROP DATABASE` also wipes the audit trail | Ship logs to a separate system (SIEM, S3, or centralized logging) |
173+
| No retention policy | Logs either fill the disk or get rotated away before the next audit | Set explicit retention (SOC 2 typically requires 90-365 days) |
174+
| Ignoring SELECT queries | You can prove data was changed but not that it was *read* | Audit SELECTs on tables containing PII, credentials, or financial data |
175+
176+
## FAQ
177+
178+
**What is database audit logging?**
179+
180+
Database audit logging is the process of recording all database activity, including queries, schema changes, logins, and permission changes, into a tamper-resistant log. It answers who accessed what data, when, and from where.
181+
182+
**Which compliance frameworks require database audit logging?**
183+
184+
SOC 2, ISO 27001, HIPAA, PCI DSS, and GDPR all require some form of database audit trail. SOC 2 and ISO 27001 are the most explicit about logging requirements. See [SOC 2 data security requirements](/blog/soc2-data-security-and-retention-requirements/) and [HIPAA database requirements](/blog/hipaa-data-security-and-retention-requirements/) for specifics.
185+
186+
**How do I export database audit logs to Datadog or Splunk?**
187+
188+
Most engines write audit logs to files or system tables. For PostgreSQL, configure `pgaudit` to write to `csvlog` and use a Datadog or Splunk agent to ingest the files. For MySQL, enable the audit plugin and point the log file at your SIEM collector. For SQL Server, parse the `.sqlaudit` files with `fn_get_audit_file()` and forward via a log shipper. Bytebase provides a built-in [audit log API](/docs/security/audit-log/) that exports structured JSON, ready for any SIEM.
19.6 KB
Loading

0 commit comments

Comments
 (0)