Encryption at Rest
What disk and engine-level encryption actually protect against, and when application-level encryption is required instead.
Encryption at rest protects data on storage media. Being precise about what that means avoids a common and expensive misunderstanding.
Layers
Volume encryption (LUKS, cloud-managed volume encryption) — encrypts everything on the device, transparent to the database, effectively free on modern hardware. This is the baseline, and for many deployments it is sufficient.
Engine-level encryption — the database encrypts its own files:
- MySQL and MariaDB: InnoDB tablespace encryption, plus redo and binlog encryption.
- MongoDB Enterprise: encrypted storage engine.
- Cassandra: transparent data encryption in some distributions.
- PostgreSQL: no core support; provided by distributions and cloud services, or by volume encryption.
It offers finer granularity — per tablespace or per table — and requires key management the volume layer does not.
Application-level encryption — the application encrypts specific fields before writing them. This is the only layer that protects against a compromised database account, and it costs the ability to index, search or sort those columns.
-- Encrypted column: queryable only by exact match on a deterministic hash.
CREATE TABLE customers (
id bigint PRIMARY KEY,
email_hash bytea NOT NULL, -- deterministic, indexed, for lookup
email_cipher bytea NOT NULL, -- randomised encryption, not searchable
UNIQUE (email_hash)
);Note the trade this makes explicit: a deterministic hash allows lookup and reveals equality — two identical emails produce identical hashes. That is a deliberate, documented compromise, not a flaw to be overlooked.
Key management
- Use a KMS or HSM rather than a file on disk.
- Separate duties: whoever administers the database should not necessarily be able to export keys.
- Plan key rotation before the first encryption, including whether rotation requires re-encrypting existing data.
- Include the key retrieval procedure in the disaster recovery plan and exercise it during drills.
What compliance usually requires
Regimes such as PCI DSS, HIPAA and GDPR generally expect encryption at rest, and volume encryption with managed keys satisfies most of them. What auditors additionally ask for, and teams often lack:
- Documented key management, including rotation and access control.
- Evidence that backups are encrypted as well as the primary storage.
- A demonstrated ability to destroy data by destroying the key.
Performance
Modern CPUs implement AES in hardware, so volume encryption typically costs a few percent — small enough that it should be on by default. Application-level encryption costs far more, because it removes the ability to index the encrypted columns, which changes query plans rather than adding a constant factor. Apply it to the specific fields that justify it, not to everything.