This is the multi-page printable view of this section.
Command-line tools
- 1: Overview of pg_tde CLI tools
- 2: pg_tde_archive_decrypt
- 3: pg_tde_restore_encrypt
- 4: pg_tde_change_key_provider
- 5: pg_tde_checksums
- 6: pg_tde_waldump
- 7: pg_tde_upgrade
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 - Overview of pg_tde CLI tools
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 pg_tde extension provides a set of command-line utilities designed specifically for operating on encrypted data and clusters. These utilities exist in parallel with the standard PostgreSQL utilities but you must use them when working with data encrypted by pg_tde.
The standard PostgreSQL tools cannot operate on pg_tde-encrypted WAL or tables.
New pg_tde specific tools
These tools are introduced exclusively by pg_tde to support key rotation and WAL encryption workflows:
- pg_tde_change_key_provider: change the encryption key provider for a database
- pg_tde_archive_decrypt: decrypts WAL before archiving
- pg_tde_restore_encrypt: a custom restore command for making sure the restored WAL is encrypted
Tools for working with pg_tde-encrypted data
These tools are modified versions of standard PostgreSQL utilities that include pg_tde support. You must use the pg_tde_* variants when working with encrypted WAL or tables:
- pg_tde_checksums: verify data checksums
- pg_tde_waldump: inspect and decrypt WAL files
- pg_tde_basebackup: create base backups that include encrypted data
- pg_tde_resetwal: reset the WAL for clusters using
pg_tde - pg_tde_rewind: rewind clusters that use encrypted WAL
- pg_tde_upgrade: perform major version upgrades of clusters with
pg_tde
2 - pg_tde_archive_decrypt
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 pg_tde_archive_decrypt tool wraps an archive command and decrypts WAL files before archiving. It allows external tools to access unencrypted WAL data, which is required because WAL encryption keys in the two-key hierarchy are host-specific and may not be available on the replay host.
For more information on the encryption architecture and key hierarchy, see Architecture.
This tool is often used in conjunction with pg_tde_restore_encrypt to support WAL archive.
How it works
- Decrypts the WAL segment to a temporary file on a RAM disk (
/dev/shm) - Replaces
%pand%fin the archive command with the path and name of the decrypted file - Executes the archive command
To ensure security, encrypt the files stored in your WAL archive using tools like PgBackRest.
Usage
Parameter descriptions
DEST-NAME: name of the WAL file to send to the archiveSOURCE-PATH: path to the original encrypted WAL fileARCHIVE-COMMAND: archive command to wrap.%pand%fare replaced with the decrypted WAL file path and WAL file name, respectively.
Options
-V, --version: show version information, then exit-?, --help: show help information, then exit
Any %f or %p parameter in ARCHIVE-COMMAND has to be escaped as %%f or %%p respectively if used as archive_command in postgresql.conf.
Examples
Using cp
Using PgBackRest
A deployment with WAL encryption is not supported unless archive_command uses pg_tde_archive_decrypt and restore_command uses pg_tde_restore_encrypt.
Disable the following pgBackRest features in the applicable pgBackRest configuration section:
3 - pg_tde_restore_encrypt
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 placeholder descriptions now match the tool’s built-in help. See site errata.
The pg_tde_restore_encrypt tool wraps a normal restore command from the WAL archive and writes them to disk in a format compatible with pg_tde.
This command is often use together with pg_tde_archive_decrypt.
How it works
- Replaces
%fand%pin the restore command with the WAL file name and temporary file path (in/dev/shm) - Runs the restore command to fetch the unencrypted WAL from the archive and write it to the temp file
- Encrypts the temp file and writes it to the destination path in PostgreSQL’s data directory
Usage
Parameter descriptions
SOURCE-NAME: name of the WAL file to retrieve from the archiveDEST-PATH: path where the encrypted WAL file should be writtenRESTORE-COMMAND: restore command to wrap;%fand%pare replaced with the WAL file name and path to write the unencrypted WAL, respectively
Options
-V, --version: show version information, then exit-?, --help: show help information, then exit
Any %f or %p parameter in RESTORE-COMMAND has to be escaped as %%f or %%p respectively if used as restore_command in postgresql.conf.
Examples
Using cp
Using PgBackRest
A deployment with WAL encryption is not supported unless archive_command uses pg_tde_archive_decrypt and restore_command uses pg_tde_restore_encrypt.
Disable the following pgBackRest features in the applicable pgBackRest configuration section:
4 - pg_tde_change_key_provider
This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.
A tool for modifying the configuration of a key provider, possibly also changing its type.
This tool edits the configuration files directly, ignoring permissions or running postgres processes.
Its only intended use is to fix servers that can’t start up because of inaccessible key providers.
For example, you restore from an old backup and the address of the key provider changed in the meantime. You can use this tool to correct the configuration, allowing the server to start up.
Warning: Use this tool only when the server is offline. To modify the key provider configuration when the server is up and running, use the pg_tde_change_(global/database)_key_provider_<type> SQL functions.
Example usage
To modify the key provider configuration, specify all parameters depending on the provider type in the same way as you do when using the pg_tde_change_(global/database)_key_provider_<type> SQL functions.
The general syntax is as follows:
Parameter description
- [optional]
<datadir>is the data directory.pg_tdeuses the$PGDATAenvironment variable if this is not specified <provider_name>is the name you assigned to the key provider<new_provider_type>can be afile,vaultorkmip<dbOid>
Depending on the provider type, the additional parameters are:
5 - pg_tde_checksums
This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.
pg_tde_checksums is a PostgreSQL command-line utility used to enable, disable, or verify data checksums on a PostgreSQL data directory. The tool is modified to add support for working with encrypted tables.
6 - pg_tde_waldump
This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.
pg_tde_waldump displays a human-readable rendering of the Write-Ahead Log (WAL) for a PostgreSQL database cluster.
To read encrypted WAL records, pg_tde_waldump provides the following additional option:
-k, --keyring-path=PATHis the path to the directory containing the WAL keyring configuration files. This is typically thepg_tde/directory inside the PostgreSQL data directory. The following files are included:wal_keys1664_providers
pg_tde_waldump cannot read encrypted WAL unless --keyring-path is specified.
Since pg_tde 2.3.0, pg_tde_waldump recognizes the pg_tde custom resource manager, prints its WAL records correctly, and accepts it in the --rmgr filter.
7 - pg_tde_upgrade
This physical upgrade procedure applies to Percona PostgreSQL. For a major upgrade of a TDE-marked Mimus cluster, use logical dump and restore into a new cluster. Mimus procedure
pg_tde_upgrade is the supported method for performing PostgreSQL major version upgrades on clusters that use pg_tde.
Use this tool instead of pg_upgrade whenever the cluster uses pg_tde, including clusters with encrypted tables or encrypted WAL.
pg_tde_upgrade wraps pg_upgrade to simplify upgrading clusters with encrypted relations or WAL. It can also be run safely on clusters without pg_tde enabled.
When to use which upgrade procedure
| Scenario | Procedure |
|---|---|
Upgrade Percona PostgreSQL from one major version to another (for example from 17 to 18) on a cluster that uses pg_tde | Use this pg_tde_upgrade procedure |
Upgrade the pg_tde extension or package version within the same PostgreSQL major version | Follow the pg_tde upgrade procedure |
Upgrade PostgreSQL from one major version to another on a cluster that does not use pg_tde | Use pg_upgrade and follow the major upgrade procedure |
| Upgrade Percona PostgreSQL to a newer minor version within the same major version (for example from 18.3 to 18.4) | Follow the minor upgrade procedure |
Implementation
pg_tde_upgrade copies the pg_tde subdirectory from the old data directory to the new data directory and then runs pg_upgrade as normal except for using pg_tde_resetwal instead of pg_resetwal.
Ensure that pg_tde is included in shared_preload_libraries and that you have the right setting for pg_tde.wal_encrypt in the new cluster.
Usage
Use pg_tde_upgrade in place of pg_upgrade when performing a PostgreSQL major version upgrade on a cluster that uses pg_tde.
pg_tde_upgrade accepts the same command-line arguments as pg_upgrade.
Example:
For more information on how to perform the upgrade for minor versions, see Minor Upgrade of Percona Distribution for PostgreSQL .
For more information on how to perform the upgrade for the pg_tde package version, see Upgrade pg_tde.