Skip to content

This is the multi-page printable view of this section.

Return to the regular view of this page

Command-line tools

Reference pages for the pg_tde utilities used with encrypted data and WAL.

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.CENTER edition · Upstream source

1 - Overview of pg_tde CLI tools

Choose the pg_tde-aware utilities required for encrypted data and WAL.

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.

Note

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:

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

PG.CENTER edition · Upstream source

2 - pg_tde_archive_decrypt

Decrypt WAL while wrapping an archive command for tools that require plaintext WAL.

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.

Tip

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

  1. Decrypts the WAL segment to a temporary file on a RAM disk (/dev/shm)
  2. Replaces %p and %f in the archive command with the path and name of the decrypted file
  3. Executes the archive command
Note

To ensure security, encrypt the files stored in your WAL archive using tools like PgBackRest.

Usage

pg_tde_archive_decrypt [OPTION]
pg_tde_archive_decrypt DEST-NAME SOURCE-PATH ARCHIVE-COMMAND

Parameter descriptions

  • DEST-NAME: name of the WAL file to send to the archive
  • SOURCE-PATH: path to the original encrypted WAL file
  • ARCHIVE-COMMAND: archive command to wrap. %p and %f are 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
Note

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

archive_command='pg_tde_archive_decrypt %f %p "cp %%p /mnt/server/archivedir/%%f"'

Using PgBackRest

archive_command='pg_tde_archive_decrypt %f %p "pgbackrest --stanza=your_stanza archive-push %%p"'
Required configuration

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:

archive-async=n
archive-header-check=n
checksum-page=n

PG.CENTER edition · Upstream source

3 - pg_tde_restore_encrypt

Wrap a restore command and encrypt the retrieved WAL before PostgreSQL reads it.

This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.

Editorial correction

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.

Note

This command is often use together with pg_tde_archive_decrypt.

How it works

  1. Replaces %f and %p in the restore command with the WAL file name and temporary file path (in /dev/shm)
  2. Runs the restore command to fetch the unencrypted WAL from the archive and write it to the temp file
  3. Encrypts the temp file and writes it to the destination path in PostgreSQL’s data directory

Usage

pg_tde_restore_encrypt [OPTION]
pg_tde_restore_encrypt SOURCE-NAME DEST-PATH RESTORE-COMMAND

Parameter descriptions

  • SOURCE-NAME: name of the WAL file to retrieve from the archive
  • DEST-PATH: path where the encrypted WAL file should be written
  • RESTORE-COMMAND: restore command to wrap; %f and %p are 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
Note

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

restore_command='pg_tde_restore_encrypt %f %p "cp /mnt/server/archivedir/%%f %%p"'

Using PgBackRest

restore_command='pg_tde_restore_encrypt %f %p "pgbackrest --stanza=your_stanza archive-get %%f \"%%p\""'
Required configuration

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:

archive-async=n
archive-header-check=n
checksum-page=n

PG.CENTER edition · Upstream source

4 - pg_tde_change_key_provider

Change provider configuration in an offline data directory.

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:

pg_tde_change_key_provider [-D <datadir>] <dbOid> <provider_name> <new_provider_type> <provider_parameters...>

Parameter description

  • [optional] <datadir> is the data directory.pg_tde uses the $PGDATA environment variable if this is not specified
  • <provider_name> is the name you assigned to the key provider
  • <new_provider_type> can be a file, vault or kmip
  • <dbOid>

Depending on the provider type, the additional parameters are:

pg_tde_change_key_provider [-D <datadir>] <dbOid> <provider_name> file <filename>
pg_tde_change_key_provider [-D <datadir>] <dbOid> <provider_name> vault-v2 <url> <mount_path> <token_path> [<ca_path>]
pg_tde_change_key_provider [-D <datadir>] <dbOid> <provider_name> kmip <host> <port> <cert_path> <key_path> [<ca_path>] 

PG.CENTER edition · Upstream source

5 - pg_tde_checksums

Check or change checksums with pg_tde support on PostgreSQL 17 and later.

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.

PG.CENTER edition · Upstream source

6 - pg_tde_waldump

Inspect encrypted WAL with a pg_tde-aware version of pg_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=PATH is the path to the directory containing the WAL keyring configuration files. This is typically the pg_tde/ directory inside the PostgreSQL data directory. The following files are included:
    • wal_keys
    • 1664_providers
Note

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.

PG.CENTER edition · Upstream source

7 - pg_tde_upgrade

Upgrade PostgreSQL data directories that contain pg_tde-encrypted relations.

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

ScenarioProcedure
Upgrade Percona PostgreSQL from one major version to another (for example from 17 to 18) on a cluster that uses pg_tdeUse this pg_tde_upgrade procedure
Upgrade the pg_tde extension or package version within the same PostgreSQL major versionFollow the pg_tde upgrade procedure
Upgrade PostgreSQL from one major version to another on a cluster that does not use pg_tdeUse 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.

Note

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:

pg_tde_upgrade \
  --old-bindir ... \
  --new-bindir ... \
  --old-datadir ... \
  --new-datadir ...

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.

PG.CENTER edition · Upstream source