You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PostgreSQL comes with a robust logging subsystem out of the box. It’s often the first step in building an audit trail.
16
+
PostgreSQL comes with a [logging subsystem](https://www.postgresql.org/docs/current/runtime-config-logging.html) out of the box. It’s often the first step in building an audit trail.
19
17
20
18
**Key settings**
21
19
@@ -44,12 +42,8 @@ This setup tells PostgreSQL to collect all executed SQL statements, include who
44
42
45
43
You can use tools like [pgBadger](https://github.com/darold/pgbadger) to analyze these logs and generate visual reports of who executed what queries and when.
46
44
47
-
➡️ *Takeaway:* Native logging is the minimum audit layer every PostgreSQL instance should have enabled.
If you need to record **row-level changes** — for example, before and after values on UPDATE — you can use triggers.
54
48
55
49
**Example**
@@ -96,15 +90,11 @@ This captures all DML operations (`INSERT`, `UPDATE`, `DELETE`) on the `users` t
96
90
- Must be defined per table.
97
91
- Can impact performance on write-heavy workloads.
98
92
99
-
For real-time change notifications, PostgreSQL offers the `tcn` module (Triggered Change Notification), which can be used to send `NOTIFY` events to listening clients when data changes.
100
-
101
-
➡️ *Takeaway:* Trigger-based auditing gives detailed change tracking for sensitive tables — best used selectively.
93
+
For real-time change notifications, PostgreSQL offers the [tcn](https://www.postgresql.org/docs/current/tcn.html) module (Triggered Change Notification), which can be used to send `NOTIFY` events to listening clients when data changes.
102
94
103
95
## 3. pgAudit Extension
104
96
105
-
[Visit the pgAudit GitHub repository](https://github.com/pgaudit/pgaudit)
106
-
107
-
For structured, compliance-grade audit logs, PostgreSQL’s **pgAudit** extension is the standard choice.
97
+
For structured, compliance-grade audit logs, PostgreSQL’s [pgAudit](https://github.com/pgaudit/pgaudit) extension is the standard choice.
108
98
It extends native logging to provide more context and granularity, especially around read/write operations.
109
99
110
100
**Installation**
@@ -125,7 +115,7 @@ pgaudit.log_catalog = off
125
115
126
116
After restarting PostgreSQL, you’ll start seeing audit logs like:
127
117
128
-
```
118
+
```plain
129
119
AUDIT: SESSION,1,READ,SELECT,,,,"SELECT * FROM customers WHERE id=42;",<none>
130
120
```
131
121
@@ -140,20 +130,15 @@ AUDIT: SESSION,1,READ,SELECT,,,,"SELECT * FROM customers WHERE id=42;",<none>
140
130
- Logs can be verbose — use `pgaudit.log_parameter = off` to reduce noise.
141
131
- Requires proper log rotation and analysis strategy.
142
132
143
-
➡️ *Takeaway:* pgAudit is the go-to choice for organizations that need **detailed, compliant** audit trails.
144
-
145
133
## 4. Bytebase
146
134
147
-
[See the Bytebase audit log documentation](https://docs.bytebase.com/security/audit-log)
148
-
149
-
Bytebase is a Database DevSecOps platform that provides a **centralized audit trail protected from unauthorized modification** across your PostgreSQL environments.
150
-
It records *who did what, when, and why* — linking SQL actions to their **context** (issues, approvals, and deployments) while keeping sensitive data secure.
135
+
Bytebase is a Database DevSecOps platform that provides a [centralized audit trail](https://docs.bytebase.com/security/audit-lo) across your PostgreSQL environments.
136
+
It records _who did what, when, and why_ — linking SQL actions to their context (issues, approvals, and deployments) while keeping sensitive data secure.
151
137
152
138
**What Bytebase Audits**
153
139
154
-
-**Query access:** logs *who queried which data* and *when* across SQL Editor, Admin Query, and Data Export.
155
-
Thanks to **dynamic data masking**, Bytebase only stores the **executed SQL statements** and metadata — **never the actual query results**.
156
-
-**Schema and data changes:** tracks *who made which changes*, *when they were approved*, and *through which workflow or Git commit*.
140
+
-**Query access:** logs _who queried which data_ and _when_ across SQL Editor, Admin Query, and Data Export.
141
+
-**Schema and data changes:** tracks _who made which changes_, _when they were approved_, and _through which workflow or Git commit_.
157
142
-**Governance controls:** built-in SQL review rules, approval flow, and role-based access help prevent unauthorized actions.
158
143
159
144
**Why It Matters**
@@ -162,17 +147,7 @@ It records *who did what, when, and why* — linking SQL actions to their **cont
162
147
-**Privacy-safe auditing** with no sensitive data exposure.
163
148
-**Compliance-ready** logs aligned with SOC 2, ISO 27001, and GDPR.
164
149
165
-
➡️ *Takeaway:* Unlike pgAudit, which records statements at the database level, Bytebase captures **who accessed or changed data, under which approval, without exposing sensitive information** — a privacy-first audit trail for modern teams.
166
-
167
-
## Best Practices
168
-
169
-
Audit logging can generate large volumes of data, so design it carefully.
170
-
171
-
-**Centralize and retain logs:** forward to ELK, Datadog, or S3.
172
-
-**Avoid sensitive data:** mask or omit personal identifiers.
173
-
-**Rotate regularly:** control log size and prevent disk exhaustion.
174
-
-**Test impact:** measure overhead before enabling full-statement logging.
175
-
-**Layer approaches:** combine pgAudit (low-level) with Bytebase (change workflow) for complete visibility.
150
+
Unlike other solutions, which records statements at the database level, Bytebase captures **who accessed or changed data, under which approval, without exposing sensitive information**. You can also call the [API](https://docs.bytebase.com/integrations/api/audit-log) to send the audit logs to a centralized log sink.
176
151
177
152
## Conclusion
178
153
@@ -186,4 +161,4 @@ PostgreSQL offers multiple layers of auditing — from basic text logs to comple
186
161
187
162
- Optionally, use **triggers** for fine-grained row-level auditing on critical tables.
188
163
189
-
By combining these layers, you gain both the visibility and control needed for secure, compliant, and well-governed database operations.
164
+
By combining these layers, you gain both the visibility and control needed for secure, compliant, and well-governed database operations.
0 commit comments