Encryption at rest for PostgreSQL

How to choose between file system encryption, block device encryption and Percona pg_tde for self-hosted PostgreSQL, what each option protects against, and what a planned rollout involves.

On this page

Encryption at rest for PostgreSQL: what each layer protects

Choose the at-rest encryption layer by the threat you need to stop. File system or block device encryption protects data files, WAL and backups when disks, volumes or snapshots leave your control, but it is transparent to anyone who can log in to the database and read rows. Percona pg_tde encrypts table data inside PostgreSQL, so a stolen copy of the data directory is unreadable without the keys, and it can be combined with volume encryption when you want both layers. Neither option protects data in use, stops an authorized database user from reading the rows their role allows, or prevents a leak from an application, a logged query or a careless export.

PostgreSQL's own documentation does not describe built-in encryption of data files, so any encryption of the data directory comes from the operating system, the storage platform or a separate extension such as pg_tde. Treat that as a fact to verify on your version rather than an assumption. Confirm with the pg_tde project which PostgreSQL major versions and key providers it supports at the time you plan, and check the current release notes before you commit to a design. The choice also affects backups: a tool that copies files may copy ciphertext or plaintext depending on the layer, so the backup path needs its own review.

Write down the threats in scope before you pick a layer: lost or decommissioned disks, cloud snapshots shared across accounts, insiders with operating system access, and database users with read rights. For each one, record who holds the keys and where the key material lives, because at-rest encryption is only as strong as key custody. Ask your team to confirm how keys are rotated, who can revoke access, and how a restore works if the key service is unavailable. Those answers, more than the cipher choice, decide whether the layer protects you.

Which threats each encryption layer covers and misses

Each encryption layer answers a different threat, and none of them protects data from a user who can already read it through the database. The cards below set out what each layer stops, what it leaves open and what to verify in your own environment before you rely on it.

Stolen or decommissioned disks

Full-disk or file system encryption protects the bytes on a drive that leaves your control, such as a failed array sent for replacement or a server removed from a rack. Once the volume is unlocked, the operating system reads plaintext, so the protection only holds while the key stays out of the stolen machine. Check where the unlock key lives, whether it is stored on the same host, and how the decommissioning process wipes or destroys media. The key must not sit next to the data.

Backup media theft

Encrypted backups protect copies of the database that travel to tape, object storage or an off-site vault, where the storage operator may not be under your control. The encryption must happen before the copy leaves the database host, and the backup key must be stored separately from the backup set. Confirm that restore tests use the same keys and that your recovery procedure works if the key service is unavailable. Backups created without encryption stay readable even when the live cluster is protected.

Continuous archiving docs

Snapshots and cloud volume exposure

Hypervisor snapshots, storage replicas and cloud volume copies duplicate the data directory outside the database's own backup process. Volume-level encryption usually protects these copies, but it does not stop a user with access to the cloud account from attaching a snapshot to another instance and mounting it. Ask who can create, share or export snapshots, which keys encrypt them, and whether the key policy separates snapshot administrators from database administrators.

Privileged and database-level access

Encryption at rest does not hide data from anyone who can connect to PostgreSQL with a valid role. A superuser, a role with pg_read_all_data, or an application account running a plain SELECT receives decrypted rows, because the database must decrypt pages to serve queries. A pg_tde deployment changes what files contain on disk, not what an authorized session sees. Handle this threat with roles, row-level controls and audit logging, and treat encryption at rest as a separate control.

Memory and process-level access

Data is in plaintext in server memory while queries run, and a user with root on the database host can read process memory or the key material loaded for pg_tde. Disk encryption offers no protection in this case. Ask how the key provider releases keys to the server, how long they stay resident, and which operating-system accounts can attach debuggers or read the process. Restrict host administration and log privileged access to the host.

Key provider and key management risk

Every layer depends on keys, and losing the key means losing the data. Percona pg_tde uses external key providers, and OpenBao is one open-source option for storing and serving keys under its own access controls. Confirm which key provider you will use, who can administer it, how keys rotate, and how you restore access after a provider outage. Test key recovery before go-live, since an unrecoverable key is a more likely outage than a stolen disk.

OpenBao high availability

Choosing file system, block or pg_tde by environment

On servers and virtual machines you manage directly, disk-level encryption is usually the first control to evaluate. Full-disk or volume encryption, set up through a volume manager such as LVM on top of dm-crypt, protects the data directory, WAL files and local backups once the host is powered off or the disk is removed. It is transparent to PostgreSQL, so it adds no changes to schema, queries or the server configuration. The trade-off is that anything running on the host after boot sees plaintext, so it does not stop a privileged user, a compromised operating system or someone with access to a running database from reading data.

  • Disk encryption is often enough when the main threat is lost or stolen disks, decommissioned storage or a hypervisor datastore read by an outsider, and the database host is administered by a small, controlled team.
  • pg_tde is worth evaluating when you need table or tablespace-level encryption, separate protection for specific data sets, or key handling that is independent of the operating system.
  • Plan the key location for dm-crypt keys, including how the host unlocks at boot and who can reach the key material.
  • Check replicas and standbys so each host and its backups carry the same encryption controls.
  • Confirm pg_tde's supported versions and key providers against the Percona documentation before choosing it, since the supplied sources do not cover its feature details.

Before deciding, confirm with your security team which threats the control must address and who holds administrative access to the database host.

Encryption options for PostgreSQL and when each fits

This table compares four encryption approaches for PostgreSQL data on disk, plus OpenBao as an optional key service. Read each row for what the layer protects, who holds the keys and what changes for operations and restores. The main takeaway is that disk-level encryption does not stop a user with live database access, so the choice depends on the threats you must cover and the key provider support you can confirm.

OptionWhat it protectsKey managementOperations and backups
File system encryptionData files and WAL on disk while the volume is lockedPassphrase or key on the host; confirm the unlock method at bootTransparent to PostgreSQL; backups read from the mounted volume are plaintext
Block device encryptionWhole disks or LUNs, including areas that file-level settings may missKeys held in the storage layer or host; confirm where recovery keys are storedIndependent of PostgreSQL version; confirm how snapshots and replicas inherit key scope
Percona pg_tdeTable and index data encrypted by the database engine, independent of disk layoutUses a key provider you configure; confirm supported providers in Percona's documentationCheck extension support for your PostgreSQL version and planned upgrade path
Encrypted backupsBackup copies stored off site or on shared mediaBackup keys held apart from database keys; confirm who can restoreRestores need the keys; test a restore on a clean host before relying on it
OpenBao as key serviceKeys and secrets held outside the database hostEncryption as a service and encrypted key/value storage; confirm pg_tde integrationAdds a high availability dependency; plan unseal and recovery before go-live
Threats left openLive server access, superusers, unencrypted backup copies and logsWhoever can decrypt decides exposure; review who holds unlock keysAssess each option against these gaps before choosing a design

How OpenBao fits as a key provider and secrets store

OpenBao is an open source secrets manager licensed under MPL-2.0, and it is a Sandbox project of the Open Source Security Foundation (OpenSSF) under Linux Foundation stewardship. Its documentation describes secure key/value storage that encrypts secrets before they are written to storage, along with encryption as a service, which lets applications send data to OpenBao for encryption without holding the key themselves. For a pg_tde deployment, that second capability is the reason to consider it: the master key used to protect PostgreSQL data files can be held by a service you run, not on the database server's disk. Whether pg_tde can use OpenBao as its key provider, and through which interface, must be confirmed against the pg_tde and OpenBao documentation for the exact versions you plan to run. Do not assume the integration exists until you have read the setup steps for both products.

Running a key service next to PostgreSQL adds a second stateful system to operate. OpenBao supports integrated storage (Raft) and PostgreSQL as its officially supported high availability backends. The OpenBao storage documentation describes PostgreSQL as easier to operate safely than Raft, which matters if your team already runs PostgreSQL well. Keep the key service's storage separate from the database it protects, or you create a loop where the database cannot start until the key service is reachable and the key service cannot be recovered without the database. Decide how many nodes you need, where they sit relative to the database, and what happens to database startup if the key service is unavailable after a reboot.

The unseal material is the most consequential operational item. OpenBao starts sealed, and its unseal keys or auto-unseal configuration must be recoverable, but they must not sit beside the encrypted data or be known to one administrator alone. Plan how unseal keys are split and held, how auto-unseal depends on another system, and how the root token is handled. Back up the OpenBao storage and its configuration on a schedule and test restoring them, because losing the key service can make encrypted PostgreSQL data unreadable even when the database files and WAL archives are intact. Ask your implementation partner and your security team to document who can unseal, how that is audited, and how a restore is rehearsed.

Setup sequence for encrypting PostgreSQL data at rest

This sequence takes encryption at rest from a threat model to a production rollout, with a check at each stage so the team can show that data on disk is unreadable, backups restore with the expected keys, and key access is controlled.

  1. Write the threat model and classify data

    The security lead and data owners list which databases, tables and backups hold regulated or sensitive data, which threats the encryption must address (stolen disks, decommissioned storage, copied backup files, a compromised host operating system), and which threats are out of scope. The output is a short document that names each threat and the control expected to address it. The step is done when each data class has an owner and each threat is marked as covered, partly covered or not covered by encryption at rest. Confirm this with the people who approve the design before any layer is chosen, because it determines whether file system encryption, pg_tde or both are sufficient.

  2. Choose the encryption layer

    The platform team compares file system or block device encryption with Percona pg_tde, using the threat model as the test. Block-level encryption protects data when a disk or volume is removed from the system, but the database sees plaintext once the volume is mounted. pg_tde encrypts table data inside PostgreSQL, so the key provider and the database's access controls become part of the design. Record which layer covers each data class, who holds the keys, and whether backups will be encrypted separately. Confirm with the vendor and the pg_tde documentation that the PostgreSQL major version and distribution you run are supported, since support depends on the build you deploy. The step is complete when the choice is written down with its known gaps.

  3. Select and deploy the key provider

    The infrastructure and security teams select the key provider and deploy it in infrastructure you control. OpenBao is an open-source option that the DeployOpen team can deploy and configure, and its documentation describes encryption as a service, dynamic secrets and several auth methods, including AppRole for servers. Decide the high availability design before go-live, because the database cannot start or decrypt data without its key provider. Confirm which providers the pg_tde release you chose supports, and test what happens when the provider is unreachable. The check is that a test cluster can start with the key fetched from the provider, and that the provider's own storage, unseal material and admin access are documented and backed up.

  4. Configure encryption on a test cluster

    Engineers build a test cluster with the same PostgreSQL major version, extensions and configuration as production, then enable the chosen encryption. For pg_tde, this means creating the key provider and principal key, creating encrypted tables or setting the default encryption for new objects, and checking which existing objects must be rewritten or migrated. For block encryption, it means building the encrypted volume and confirming the data directory sits on it. Load representative data, including the tables that hold sensitive fields, and record the steps so production can repeat them exactly. The check is that the cluster starts, queries succeed, and every object expected to be encrypted appears as encrypted in the catalog or on the volume.

  5. Verify data files are unreadable on disk

    A tester stops the test cluster and inspects the data directory and the raw volume without using the database. They search the files for known plaintext values from the loaded data, such as a unique test string, and compare file contents with a copy taken before encryption. Include WAL files, temporary files and any dump the team creates, because sensitive values often appear outside table files. The step is done when no test string is readable in the encrypted files and the expected encrypted objects match the catalog. If plaintext appears, stop the rollout, find the path that wrote it, and repeat the test. Record the results as evidence for the compliance and security teams.

  6. Rehearse encrypted backup and restore

    The operations team takes a base backup and archives WAL from the test cluster, then restores both to a separate host. Confirm that the restored cluster can read the key from the provider, that point-in-time recovery reaches the chosen target, and that the restored data matches checksums or row counts from the source. Test an encrypted dump or file-level encrypted backup the same way, and confirm the backup decrypts with the expected key rather than only restoring the file. Also confirm what happens when the key is unavailable, and that backups are not restorable by people who should not have key access. The check is a documented restore that succeeds with the expected key and fails cleanly without it.

  7. Roll out with key rotation and access review

    The team applies the tested steps to production in a planned window, verifies the same checks on production data files and a fresh backup, and schedules key rotation under the procedure the test cluster proved. Rotation procedures should state which keys are retired, how old backups stay readable, and who approves the change. Review who can read the key provider, operate the database host and access backup storage, and remove standing access that is not needed. The step is complete when rotation has been run once on the test cluster, the access list is signed off by the data owner, and the runbook records the owner for each key and backup set. Confirm details of rotation and key-provider behavior with the vendor documentation for your chosen versions before relying on them.

Questions buyers ask before outsourcing PostgreSQL encryption

What drives the cost of encrypting PostgreSQL data at rest?

The biggest cost drivers are the encryption layer you choose, the number of clusters in scope, the key provider, the size of your backup estate and how much compliance evidence you need. File system or block device encryption is usually the smallest design job because the database itself does not change, while Percona pg_tde adds a key provider decision, key rotation design and testing of every cluster. Each cluster needs its own inventory, configuration, restore test and runbook, so the count of clusters and backup sets often matters more than the cipher. Ask any partner for a quote that lists the layers in scope, the clusters and backup sets covered, the key provider and who operates it, the evidence delivered, and which items are one-time work and which recur, such as key rotation, retesting after upgrades and support retainers.

How long does a planned PostgreSQL encryption rollout take?

Duration depends on the layer chosen, the number of clusters, whether data must be re-encrypted in place or moved to a new cluster, and how long your change windows and approval cycles are. A block or file system change can often be planned around maintenance windows, while a pg_tde rollout usually requires a tested migration path, a key provider in place and a rehearsal on a copy of production data. Restore testing of encrypted backups takes time because it must complete end to end, not just start. Your partner should give a duration only after the written scope, the environment inventory and your approval process are known, and the quote should name which milestones depend on your teams rather than on the implementer.

What does our team need to provide for the work?

You will need storage administrators who can confirm how volumes, file systems and snapshots are built, DBAs who own the clusters, backup operators who can run and restore backups, and security staff who approve key handling and sign off on the design. A test environment that mirrors production layout is essential, because encryption changes can affect startup, replication, backup duration and performance. You will also need access to the key provider or the team that runs it, a documented change process and a named owner for final acceptance. Confirm these owners before the scope is signed, since delays in access or approvals are the most common reason a plan slips.

Can our own team implement PostgreSQL encryption at rest without a partner?

Yes, a capable team with storage, PostgreSQL and security skills can do it, and the decision usually comes down to available capacity and the cost of mistakes. The hard parts are not the commands but the decisions: which threats the design must cover, where keys are stored, how rotation works, how backups are encrypted and whether a restore has been proven. Teams that build it alone should still write down the threat model, test restores with the keys held in the same way production holds them and get an independent review of the result. A partner can be used for the whole project, for the design review only, or for retesting after changes.

What should a quote for PostgreSQL encryption include?

A useful quote lists the scope in writing: the clusters, replicas, backup repositories and file systems covered, and the layers used for each. It should name the encryption method for each layer, the key provider and who operates it, the key rotation and recovery approach, and the verification steps, including restore tests of encrypted backups. Deliverables should be explicit, such as design documents, configuration changes, runbooks, test results and handover sessions. Ask which items are fixed, which depend on your environment, what assumptions the price rests on and what support or retesting is included after go-live. DeployOpen plans most engagements as fixed scope, with scope, deliverables and timelines agreed in writing before work starts.

Which threats does encryption at rest cover and which does it leave open?

Encryption at rest protects data on disk and in backups when the media, snapshot or backup file is taken without the keys. It does not protect data from a user or application that can connect to a running database and query it, from a superuser who can read decrypted data in memory, or from an attacker who has both the data and the key material. File system or block encryption usually protects the disk layer and does not change what the database process sees once it is unlocked, while pg_tde is designed to encrypt table data at the database layer and depends on how its key provider is secured. Access control, TLS for connections and audit logging remain necessary alongside encryption. Confirm the exact coverage of each option against its documentation and your own threat model before signing off.

What does DeployOpen not do for encryption at rest work?

DeployOpen plans, implements, hardens, backs up, documents and supports self-hosted platforms in your own infrastructure, and it prepares systems, controls and evidence for compliance assessments. It does not issue audit reports, attestations or certifications, because independent auditors and certification bodies do that work. It also does not guarantee that a given control will satisfy a particular examiner or make your organization compliant on its own. Ask for the evidence package in writing, check it against the requirements your assessor uses, and bring the assessor in early so that the design choices are accepted before build time is spent.

Security and operational risks of encryption at rest

Encryption at rest protects data on disk and in backups, but it adds keys, providers and new failure modes to the database. The cards below cover the risks that most often turn a sound design into a data loss event or a false sense of safety. Each one should be tested in your environment before go-live.

Key loss and unrecoverable backups

If the key that decrypts a data directory or backup is lost, the data is lost with it, even when the files are intact. Backups are only useful if the keys needed to decrypt them are stored separately and are restorable under the same conditions. Ask who holds copies of each key, where they are kept, and whether a restore has been run from a cold start using only those copies. Test this on a non-production cluster before relying on it.

Keys stored on the same host

A key kept in the same server, directory or configuration file as the encrypted data offers little protection against someone who obtains the host or a disk image. Separate the key provider from the database host where your design allows it, and confirm which key material a stolen disk, snapshot or backup would expose. The key provider's own storage, backups and network path become part of your threat model.

Rotation without downtime

Key rotation changes which key protects new writes and, depending on the method, may require re-encrypting existing data. Find out whether your chosen method rotates keys online, how long a rotation takes on your data volume, and whether replicas and backups need the new key before the old one is retired. Plan a rotation drill that includes restoring a backup taken before the rotation.

Monitoring the key provider

When the key provider is unavailable, a PostgreSQL server that depends on it may fail to start or stop serving encrypted data. Monitor provider reachability, lease or token expiry, certificate validity and failed key requests, and alert before the database is affected. Decide in advance whether a provider outage should stop the database or leave it in a degraded state, and document the restart procedure.

Performance and I/O effects

Encryption adds CPU work to reads and writes, and key lookups add latency when the provider is remote. The effect depends on hardware acceleration, workload shape and whether the design encrypts at the file system, block device or database layer. Measure throughput, latency and checkpoint duration on representative data before choosing an option, and repeat the test after upgrades or changes to the storage stack.

Access to keys and key material

Anyone who can read a key, a key provider token or the database's key configuration can decrypt the data, which makes key access the strongest control in the design. Restrict key administration to a small named group, separate key custody from database administration, and log every key read and change. PostgreSQL authentication through pg_hba.conf, TLS and least-privilege roles still apply, because they control who can query decrypted data and reach the server. Encryption at rest does not replace them.

How encryption layers and key providers fit around PostgreSQL

The diagram starts at the PostgreSQL server, which handles pages in plaintext in its own memory. With pg_tde, pages pass through the encryption layer before they reach the data directory, so files on disk hold ciphertext. The file system or block layer below can add a separate encryption step for the whole volume. WAL archives and backups leave the host on their own path and need encryption before they are stored. The key provider sits behind its own trust boundary, so check who can reach the key service, how data keys are issued and where plaintext may still appear.

Layers, plaintext points and the key trust boundary around a self-hosted PostgreSQL server.

How DeployOpen scopes and delivers PostgreSQL encryption at rest

DeployOpen works on a fixed-scope basis. Before any work starts, the written scope, deliverables and timeline are agreed, and that document decides which encryption layers are in play: file system or block device encryption, pg_tde with its key provider, encrypted backups, or a combination. For this topic the scope should name the storage platform, the PostgreSQL major version, the key provider (for example, an OpenBao instance that the client already operates or plans to run), the backup tool and the restore test the client expects. Work is performed inside the client's own cloud accounts, data centers or air-gapped networks, so keys, backup targets and database hosts never move to a DeployOpen-owned environment.

Deliverables for this kind of engagement are the configuration and the evidence around it. DeployOpen documents where each key lives, who can unwrap it, how the key provider is reached and what happens if it is unavailable, and it writes the step-by-step recovery procedure for a lost key, a restored backup and a failed key provider. Those documents are what your security and operations teams will need to review. Ongoing work such as key rotation, PostgreSQL minor and major upgrades that touch encrypted clusters, and periodic restore tests can be placed under a retainer. Confirm with DeployOpen in writing which of these items sit inside the initial fixed scope and which recur.

DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports, attestations or certifications. Independent auditors and certification bodies perform those assessments. Ask your assessor early which encryption evidence they will request, such as key custody records, access logs and tested restores, and plan the engagement so that evidence is produced during delivery rather than reconstructed afterward.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.