Encryption at rest protects PostgreSQL data files or individual columns so disk-level theft or snapshot leaks reveal only ciphertext.
Sensitive columns like customer emails and order totals sit on disk in plain text by default. Disk theft, mis-configured backups, or cloud snapshot leaks can expose that data. Encrypting at rest renders stolen files useless.
PostgreSQL 16 lacks native Transparent Data Encryption (TDE). Most teams either ① encrypt the whole volume (LUKS, EBS-KMS, Azure Disk Encryption) or ② encrypt specific columns with pgcrypto
.The latter gives row-level granularity without kernel support.
Pick column encryption when only a few fields (credit cards, emails) require protection and you still need online index/partial search on non-encrypted columns. Full-disk encryption suffices for broad, coarse protection.
pgcrypto
adds functions like pgp_sym_encrypt()
and pgp_sym_decrypt()
. You store ciphertext (bytea) and decrypt only when needed.Keys can live in env variables, KMS, or separate key tables with tight ACLs.
Symmetric encryption adds CPU overhead proportional to row size. Indexes on encrypted columns are useless, so keep searchable data in plaintext or add hashed helper columns.
Create a new key, re-encrypt rows in batches inside a transaction, then revoke access to the old key.Using KMS-generated data keys simplifies rotation to a single update.
1. Install pgcrypto
extension. 2. Add a email_enc bytea
column. 3. Populate with UPDATE
using pgp_sym_encrypt()
. 4. Remove or null the plaintext column. 5. Decrypt in views or app queries.
• Keep keys outside the database process. • Use strong AES cipher (default 256-bit in pgcrypto). • Limit decryption to roles that truly need it.• Automate key rotation and audit decrypt usage.
Store encryption helper queries in a Galaxy Collection, endorse them once reviewed, and let the AI copilot generate rotation scripts whenever the schema changes.
.
No. You must call decrypt functions explicitly or wrap them in views. Applications need minor code changes.
Minimal in modern CPUs with AES-NI. I/O wait usually hides the overhead. Benchmarks show <5% impact in most workloads.
Yes. Use archive_command
that pipes through gpg
or rely on storage-layer encryption (S3 SSE-KMS, GCS CMEK) for archived files.