This is the multi-page printable view of this section.
Operations
- 1: Encryption enforcement
- 2: Configure multi-tenancy
- 3: Backup with WAL encryption enabled
- 4: Restore encrypted backups
- 5: Upgrade pg_tde
- 6: Remove encryption from an encrypted table
- 7: Uninstall pg_tde
This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.
1 - Encryption enforcement
This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.
For pg_tde, encryption enforcement ensures that only encrypted storage is allowed for specific operations, tables, or the entire database. It prevents the accidental creation of unencrypted tables or indexes in environments where encryption is required for compliance, security, or policy enforcement.
What does enforcement do?
When enabled, encryption enforcement:
- Prevents creation of unencrypted tables or indexes
- Enforces consistent encryption usage across tenants, databases, or users
- Can be scoped globally, per database, or per role
Enforce encryption usage
Use the following techniques to enforce the secure use of pg_tde.
1. Enforce encryption across the server
To enforce encryption cluster-wide, set the pg_tde.enforce_encryption variable in postgresql.conf:
Only superusers can set or change this variable.
This ensures that no user, including superusers, can create unencrypted tables. Superusers can however explicitly override the variable in their session.
2. Enforce encryption for a specific database
To apply encryption enforcement only within a specific database, run:
This ensures encryption is enforced only when connected to that database.
3. Enforce encryption for a specific user
You can also enforce encryption on a per-user basis, run:
This ensures that the user example_user cannot create unencrypted tables, regardless of which database they connect to.
Override enforcement for trusted sessions
Superusers can override the variable at the session level:
This allows temporary creation of unencrypted tables in special cases, such as:
- Loading trusted, public reference datasets
- Benchmarking and test environments
- Migration staging before re-encryption
While superusers can disable enforcement in their session, they must do so explicitly. Enforcement defaults remain active to protect from accidental misconfiguration.
2 - Configure multi-tenancy
This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.
The steps below describe how to set up multi-tenancy with pg_tde. Multi-tenancy allows you to encrypt different databases with different keys. This provides granular control over data and enables you to introduce different security policies and access controls for each database so that only authorized users of specific databases have access to the data.
If you don’t need multi-tenancy, use the global key provider. See the configuration steps from the Configure pg_tde section.
For how to enable WAL encryption, refer to the Configure WAL Encryption section.
Considerations
You can use external key providers to manage encryption keys. The recommended approach is to use the Key Management Store (KMS). For more information, see Configure Key Management (KMS) .
If no error is reported when running the commands below, the operation completed successfully.
Enable extension
Load the pg_tde at startup time. The extension requires additional shared memory; therefore, add the pg_tde value for the shared_preload_libraries parameter and restart the postgresql cluster.
Use the ALTER SYSTEM command from
psqlterminal to modify theshared_preload_librariesparameter. This requires superuser privileges.Start or restart the
postgresqlcluster to apply the changes.On Debian and Ubuntu:
On RHEL and derivatives
Create the extension using the CREATE EXTENSION command. You must have the privileges of a superuser or a database owner to use this command. Connect to
psqlas a superuser for a database and run the following command:The
pg_tdeextension is created for the currently used database. To enable data encryption in other databases, you must explicitly run theCREATE EXTENSIONcommand against them.TipYou can have the
pg_tdeextension automatically enabled for every newly created database. Modify the templatetemplate1database as follows:
Key provider configuration
You must do these steps for every database where you have created the extension. For more information on configurations, please see the Configure Key Management (KMS) topic.
Set up a key provider.
The KMIP server setup is out of scope of this document.
Make sure you have obtained the root certificate for the KMIP server and the keypair for the client. The client key needs permissions to create / read keys on the server. Find the configuration guidelines for the HashiCorp Vault Enterprise KMIP Secrets Engine .
For testing purposes, you can use the Eviden KMS server which enables you to set up required certificates. To use a real KMIP server, make sure to obtain the valid certificates issued by the key management appliance.
where:
provider-nameis the name of the provider. You can specify any name, it’s for you to identify the provider.kmip-addris the IP address of a domain name of the KMIP serverportis the port to communicate with the KMIP server. Typically used port is 5696.server-certificateis the path to the certificate file for the KMIP server.client-certis the path to the client certificate.client-keyis the path to the client key.
Warning: This example is for testing purposes only:
The Vault server setup is out of scope of this document.
where:
urlis the URL of the Vault servermountis the mount point where the keyring should store the keyssecret_token_pathis a path to the file that contains an access token with read and write access to the above mount point- [optional]
ca_pathis the path of the CA file used for SSL verification
Warning: This example is for testing purposes only:
This setup is intended for development and stores the keys unencrypted in the specified data file.
**Warning:** This example is for testing purposes only: ```sql SELECT pg_tde_add_database_key_provider_file( 'file-keyring', '/tmp/pg_tde_test_local_keyring.per' ); ```Create a key
where:
name-of-the-keyis the name of the principal key. You will use this name to identify the key.provider-nameis the name of the key provider you added before. The principal key is associated with this provider and it is the location where it is stored and fetched from.
Warning: This example is for testing purposes only:
NoteThe key is auto-generated.
Use the key as principal key
where:
name-of-the-keyis the name of the principal key. You will use this name to identify the key.provider-nameis the name of the key provider you added before. The principal key will be associated with this provider.
Warning: This example is for testing purposes only:
3 - Backup with WAL encryption enabled
For Mimus, choose the backup client by WAL key history and use the client paired with the kernel. See the tested physical backup and restore sequence. Mimus procedure
Do not rotate encryption keys while a backup is running. This may result in an inconsistent backup and restore failure. This applies to all backup tools.
For more details, see Limitations of pg_tde.
To create a backup with WAL encryption enabled:
Copy the
pg_tdedirectory from the source server’s data directory, for example/var/lib/postgresql/data/pg_tde/, including thewal_keysand1664_providersfiles, to the backup destination directory wherepg_tde_basebackupwill write the backup.Also copy any external files referenced by your providers configuration (such as certificate or key files) into the same relative paths under the backup destination, so that they are located and validated by
pg_tde_basebackup -E.Run:
Where:
-D /path/to/backupspecifies the backup location where you have to copypg_tde.-E(or--encrypt-wal) enables WAL encryption and validates that the copiedpg_tdeand provider files are present and that the server key is accessible (required). The-Eoption accepts a cipher argument. The currently supported values areaes_128andaes_256. If-Eis not specified,pg_tde_basebackupattempts to determine the cipher from the server’s key. If no cipher can be determined,pg_tde_basebackupdefaults toaes_128.
- The
-Eflag only works with the-X streamoption (default). It is not compatible with-X noneor-X fetch. For more information, see the backup method compatibility with WAL encryption. - The
-Eflag is only supported with the plain output format (-F p). It cannot be used with the tar output format (-F t).
Key rotation during backups
Do not rotate encryption keys while a backup is in progress. This applies to all backup tools.
Backups created during key rotation may fail to start during WAL replay and may lead to corruption of encrypted data (tables, indexes, and other relations).
For example, you may see errors such as:
To ensure standby recoverability, plan key rotations outside backup windows or take a new full backup after rotation completes.
Restore a backup created with WAL encryption
When you want to restore a backup created with pg_tde_basebackup -E:
- Ensure all external files referenced by your providers configuration (such as certificates or key files) are also present and accessible at the same relative paths.
- Start PostgreSQL with the restored data directory.
Backup method compatibility with WAL encryption
Tar format (-F t):
- Works with
-X fetch. - Does not support
-X streamwhen WAL encryption is enabled. Usingpg_tde_basebackup -F t -X streamwill create a broken replica.
Streaming mode (-X stream):
- Must specify
-E(--encrypt-wal). - Without
-E, backups may contain decrypted WAL whilewal_encryption=onremains inpostgresql.confandpg_tde/wal_keysare copied. This leads to startup failures and compromised data in the backup.
Fetch mode (-X fetch):
- Compatible with encrypted WAL without requiring any additional flags.
None (-X none):
- Excludes WAL from the backup and is unaffected by WAL encryption.
If the source server has pg_tde/wal_keys, running pg_tde_basebackup with -X none or -X fetch produces warnings such as:
You can safely ignore the warnings with -X none or -X fetch, since no WAL streaming occurs.
4 - Restore encrypted backups
For Mimus, restore the matching kernel, startup libraries, provider metadata and historical keys along with the backup. Mimus procedure
To restore an encrypted backup created with an earlier key, ensure the key is still available in your Key Management System (KMS). The backup remains encrypted on disk, pg_tde uses the correct key to transparently access the data.
How pg_tde uses old keys to load backups
- KMS: stores the principal key(s) that were active when the backup was made.
- Encrypted backup: contains data encrypted with the key available at that time.
- Current server:
pg_tdeautomatically loads the backup if the key is accessible through the KMS.
The table (internal) keys are stored within the backup. At runtime, pg_tde retrieves the principal key(s) from the configured KMS and uses them to decrypt the internal keys, enabling access to the encrypted table data.
If the required key(s) get deleted or are missing, the backup cannot be read.
If the key(s) still exists but the KMS configuration has changed, you can use pg_tde_change_key_provider to update the configuration.
However, if the key(s) got deleted from all accessible KMS sources, the encrypted backup is unrecoverable.
5 - Upgrade pg_tde
Percona’s package upgrade steps apply to Percona PostgreSQL. For a major upgrade of a TDE-marked Mimus cluster use logical dump and restore.
The version of pg_tde available to you depends on your version of Percona Distribution for PostgreSQL.
To use a newer pg_tde release, first ensure that your Percona Distribution for PostgreSQL version includes it.
This document describes upgrading the pg_tde extension within the same PostgreSQL major version. For PostgreSQL major version upgrades on clusters that use pg_tde, use pg_tde_upgrade.
Before you start
pg_tde 2.2.0 is not compatible with Percona Distribution for PostgreSQL older than 17.10 or 18.4. Upgrade your distribution first before upgrading pg_tde.
Using pg_upgrade on an encrypted cluster is not supported and will result in data corruption. The server may start successfully but queries against encrypted tables will fail.
Procedure
Take a full backup before upgrading.
Upgrade the
pg_tdepackage via your package manager.Restart the
postgresqlservice.Connect to each database where
pg_tdeis installed and run:NoteThe catalog version of
pg_tdemay not change between patch releases. You can runALTER EXTENSION pg_tde UPDATEsafely regardless.Verify the upgrade:
6 - Remove encryption from an encrypted table
This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.
Method 1. Change the access method
If you encrypted a table with the tde_heap access method and need to remove the encryption from it, run the following command against the desired table (mytable in the example below):
Note that the SET ACCESS METHOD command drops hint bits and this may affect performance. Running a plain SELECT count(*) or VACUUM command on the entire table will check every tuple for visibility and set its hint bits. Therefore, after executing the ALTER TABLE command, run a simple count(*) on your tables:
Check that the table is not encrypted:
The output returns f meaning that the table is no longer encrypted.
Method 2. Create a new not encrypted table on the base of the encrypted one
Alternatively, you can create a new not encrypted table with the same structure and data as the initial table. For example, the original encrypted table is EncryptedCustomers. Use the following command to create a new table Customers:
The new table Customers inherits the structure and the data from EncryptedCustomers.
(Optional) If you no longer need the EncryptedCustomers table, you can delete it.
7 - Uninstall pg_tde
Mimus records TDE in the data directory. Retain the matching preload, tools and historical keys for recovery, including after dropping the SQL extension. To retire the dependency, migrate into a fresh cluster. Mimus procedure
If you no longer wish to use Transparent Data Encryption (TDE) in your deployment, you can remove the pg_tde extension.
To proceed, you must have one of the following privileges:
- Superuser privileges (to remove the extension globally), or
- Database owner privileges (to remove it from a specific database only)
To uninstall pg_tde, follow the steps below.
Step 1. Remove pg_tde from all databases
Before uninstalling, you must remove the extension from every database where it is loaded. If pg_tde was installed in templates, new databases inherit it. You must drop it from the templates first or future restores/creates will break.
a. Rewrite encrypted tables:
To rewrite an encrypted table back to its default storage method:
b. Remove the extension once all encrypted tables have been rewritten or dropped:
If there are any encrypted objects that were not previously decrypted or deleted, this command will fail and you have to follow the steps above for these objects.
Repeat step 1 for every database in your cluster.
Step 2. Turn off WAL encryption
If you are using WAL encryption, you need to turn it off before you uninstall the pg_tde library:
a. Run:
b. Restart the PostgreSQL cluster to apply the changes:
- On Debian and Ubuntu:
- On RHEL and derivatives:
Step 3. Uninstall the pg_tde shared library
This process removes the extension, but does not decrypt data automatically. Only uninstall the shared library after all encrypted data has been removed or decrypted and WAL encryption has been disabled.
Encrypted WAL pages will not be decrypted, so any postgres cluster needing to read them will need the pg_tde library loaded, and the WAL encryption keys available and in use.
At this point, the shared library is still loaded but no longer active. To fully uninstall pg_tde, complete the steps below.
a. Run SHOW shared_preload_libraries to view the current configuration of preloaded libraries.
For example:
b. Remove pg_tde from the list and apply the new setting using ALTER SYSTEM SET shared_preload_libraries=<your list of libraries>.
For example:
Your list of libraries will most likely be different than the above example. Take care not to remove other required extensions. Only delete pg_tde from the list.
If pg_tde is the only shared library in the list, and it was set via postgresql.conf you cannot disable it using the ALTER SYSTEM SET ... command. Instead:
- Remove the
shared_preload_librariesline frompostgresql.conf - Run
ALTER SYSTEM RESET shared_preload_libraries;
c. Restart the postgresql cluster to apply the changes:
On Debian and Ubuntu:
On RHEL and derivatives:
NoteThe service name may differ depending on your distribution and PostgreSQL version.nod
Step 4. (Optional but recommended) Clean up configuration
At this point it is safe to remove any configuration related to pg_tde from postgresql.conf and postgresql.auto.conf. Look for any configuration parameters prefixed with pg_tde. and remove or comment them out, as needed.
Troubleshooting: PANIC checkpoint not found on restart
This can happen if WAL encryption was not properly disabled before removing pg_tde from shared_preload_libraries, when the PostgreSQL server was not restarted after disabling WAL encryption (see step 3.c).
You might see this when restarting the PostgreSQL cluster:
This error means PostgreSQL is trying to read encrypted WAL without pg_tde loaded.
To resolve it follow these steps:
- Re-add
pg_tdetoshared_preload_libraries - Restart the PostgreSQL cluster
- Follow the instructions for turning off WAL encryption before uninstalling the shared library again
Two restarts are required to uninstall properly if WAL encryption was enabled:
- First to disable WAL encryption
- Second to remove the
pg_tdelibrary