Home / Learn Secure SQL / Log Retention and Privacy

Log Retention and Privacy

How long to keep logs, and what should never be in them.

The short versionHow long to keep logs, and what should never be in them.

Theory in plain words

Two retention needs, balancedKeep logs long enoughTo investigate issuesdiscovered laterTo meet audit/compliancerequirementsNot too longTo respect data-minimizationand privacy rulesTo control storage cost
Two retention needs, balanced

What it is

Log retention policy defines how long different kinds of logs are kept before being deleted or archived, balancing investigative usefulness against storage cost and privacy regulations that limit how long personal data may be retained.

Why it matters

Logs containing personal data are themselves subject to privacy regulations (covered more fully in the "Secure schema and data design" part); keeping logs forever, or logging more personal data than needed, can itself become a compliance and security liability.

Mechanically speaking

Define retention periods per log type (security/audit logs often kept longer than routine debug logs), and never log sensitive values (passwords, full card numbers, tokens) at all, redacting them before they ever reach a log line.

Shows up in

  • Web application code review
  • Backend development
  • Database administration
Careful:A password, full credit card number, or authentication token should never appear in a log line at all, under any log level — redact it before logging, not after.

Check yourself

1. A value that should never appear in a log line is...