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.