Skip to content

Commit 91e41ea

Browse files
docs: add db audit logging blog (#951)
* add db audit logging * update
1 parent 0425364 commit 91e41ea

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
---
2+
title: Database Audit Logging - The Practical Guide for Modern Teams
3+
author: Adela
4+
updated_at: 2025/11/27 18:00:00
5+
feature_image: /content/blog/database-audit-logging/cover.webp
6+
tags: Industry
7+
description: A guide to audit logging in databases.
8+
---
9+
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**.
11+
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.
13+
14+
## Why Audit Logging Matters
15+
16+
Audit logging provides the answers to the most critical operational and security questions:
17+
18+
- **Who** accessed the data?
19+
- **What** did they query or modify?
20+
- **When** did it occur?
21+
- **From where** did the access originate?
22+
23+
This information is essential for:
24+
25+
- Detecting unauthorized access
26+
- Investigating security incidents
27+
- Meeting compliance requirements
28+
- Understanding schema and data evolution
29+
- Establishing accountability across engineering teams
30+
31+
Without reliable audit logs, organizations lack visibility at the exact moment it matters most.
32+
33+
## The Real-World Pain Today (Across All Major Databases)
34+
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.
36+
37+
Here are common issues teams encounter:
38+
39+
### MySQL (Community Edition) — Example
40+
41+
MySQL CE’s general and slow logs are **all-or-nothing and extremely noisy**.
42+
Selective auditing (especially for non-root users) requires additional plugins that introduce configuration complexity and variability across environments.
43+
44+
### PostgreSQL — Example
45+
46+
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.
48+
49+
### Cloud Databases (AWS RDS, Google Cloud SQL, Azure Database) — Example
50+
51+
Cloud platforms wrap underlying engine audit logs into provider-specific formats.
52+
Teams often struggle with:
53+
54+
- inconsistent event types
55+
- missing or partial SQL text
56+
- difficulty correlating logs across mixed engines or environments
57+
58+
**In short:**
59+
60+
> Audit information exists everywhere — but it’s fragmented, inconsistent, and often incomplete.
61+
62+
## What a Good Audit Log Should Capture
63+
64+
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**.
66+
67+
### A robust audit log includes:
68+
69+
- **Real human identity**
70+
No shared admin or application accounts. Every query must map to an actual person.
71+
72+
- **Full query text**, including:
73+
74+
- **DDL** (all schema changes)
75+
- **DML** (INSERT, UPDATE, DELETE)
76+
- **SELECT** (all read operations — because viewing sensitive data is a high-risk event)
77+
78+
- **Authentication events**
79+
Both successful logins and failed login attempts.
80+
81+
- **Permission changes**
82+
The audit log must record any permissions granted or revoked for specific users.
83+
84+
- **Execution outcome**
85+
Whether the operation succeeded, failed, or was rejected.
86+
87+
- **Optional contextual metadata**
88+
Such as ticket/issue ID, environment, deployment reference, or any policy configurations or changes.
89+
90+
A complete record of SELECT queries ensures you always know *exactly who viewed what data*, which is a mandatory capability under many security and privacy frameworks.
91+
92+
## Approaches to Audit Logging
93+
94+
Teams typically rely on one or more of the following auditing methods:
95+
96+
### 1. Engine-native auditing
97+
98+
Each database engine includes its own audit features.
99+
100+
**Pros:**
101+
102+
- High fidelity
103+
- Deeply integrated with database internals
104+
105+
**Cons:**
106+
107+
- Different for every engine
108+
- Easily becomes noisy without tuning
109+
- Harder to unify across environments
110+
111+
### 2. Cloud provider audit logs
112+
113+
Cloud platforms provide audit streams for their managed databases.
114+
115+
**Pros:**
116+
117+
- Easy to enable
118+
- Centralized in cloud logging services
119+
- Integrated with monitoring tools
120+
121+
**Cons:**
122+
123+
- Inconsistent formats and event coverage
124+
- SQL text may be missing
125+
- Hard to correlate across multi-cloud or multi-engine stacks
126+
127+
### 3. Proxy / workflow-based auditing
128+
129+
SQL is routed through a centralized gateway or workflow before executing.
130+
131+
**Pros:**
132+
133+
- Unified audit trail across all engines
134+
- Automatically tied to real human identity
135+
- Can embed metadata (ticket ID, environment)
136+
- Ensures DDL, DML, *and SELECT* are always captured
137+
138+
**Cons:**
139+
140+
- Requires routing SQL through a central component
141+
142+
*For example:*
143+
A workflow platform like **Bytebase** produces complete, contextual audit logs because all SQL flows through a single, identity-aware pipeline.
144+
145+
## Recommended Best Practices
146+
147+
Regardless of database engine or auditing method, strong audit practices share the same foundations:
148+
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).
153+
- **Integrate logs into a SIEM** for alerting and correlation (Datadog, Splunk, CloudWatch, Grafana).
154+
- **Treat default engine settings cautiously** — they often require substantial tuning.
155+
156+
A minimal-noise, high-fidelity audit log is better than a noisy one that nobody can use.
20.1 KB
Loading

0 commit comments

Comments
 (0)