Skip to content

Commit c0ad12b

Browse files
authored
PG-1832 Document the archive and restore commands cont (#531)
Continued from #523 - add pg_tde archive and restore commands - update cli-tools.md with paragraphs explaining New and extended tools - update pg-tde-restore-encrypt tool with new information and better descriptions for clarity - update the Features topic button for better clarity
1 parent 9d6297f commit c0ad12b

File tree

4 files changed

+123
-6
lines changed

4 files changed

+123
-6
lines changed
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
# Overview of pg_tde CLI tools
22

3-
The `pg_tde` extension introduces new command-line utilities and extends some existing PostgreSQL tools to support encrypted WAL and tables. These include:
3+
The `pg_tde` extension introduces new command-line utilities and extends some existing PostgreSQL tools to support encrypted WAL and tables.
44

5-
* [pg_tde_change_key_provider](../command-line-tools/pg-tde-change-key-provider.md): change encryption key provider for a database
6-
* [pg_waldump](../command-line-tools/pg-waldump.md): inspect and decrypt WAL files
7-
* [pg_checksums](../command-line-tools/pg-tde-checksums.md): verify data checksums (non-encrypted files only)
5+
## New tools
6+
7+
These tools are introduced by `pg_tde` to support key rotation and WAL encryption workflows:
8+
9+
* [pg_tde_change_key_provider](./pg-tde-change-key-provider.md): change the encryption key provider for a database
10+
* [pg_tde_archive_decrypt](./pg-tde-archive-decrypt.md): decrypts WAL before archiving
11+
* [pg_tde_restore_encrypt](./pg-tde-restore-encrypt.md): a custom restore command for making sure the restored WAL is encrypted
12+
13+
## Extended tools
14+
15+
These existing PostgreSQL tools are enhanced to support `pg_tde`:
16+
17+
* [pg_checksums](./pg-tde-checksums.md): verify data checksums (non-encrypted files only)
18+
* [pg_waldump](./pg-waldump.md): inspect and decrypt WAL files
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# pg_tde_archive_decrypt
2+
3+
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.
4+
5+
!!! tip
6+
7+
For more information on the encryption architecture and key hierarchy, see [Architecture](../architecture/architcture.md).
8+
9+
This tool is often used in conjunction with [pg_tde_restore_encrypt](./pg-tde-restore-encrypt.md) to support WAL archive.
10+
11+
## How it works
12+
13+
1. Decrypts the WAL segment to a temporary file on a RAM disk (`/dev/shm`)
14+
2. Replaces `%p` and `%f` in the archive command with the path and name of the decrypted file
15+
3. Executes the archive command
16+
17+
!!! note
18+
19+
To ensure security, encrypt the files stored in your WAL archive using tools like `PgBackRest`.
20+
21+
## Usage
22+
23+
```bash
24+
pg_tde_archive_decrypt [OPTION]
25+
pg_tde_archive_decrypt DEST-NAME SOURCE-PATH ARCHIVE-COMMAND
26+
```
27+
28+
## Parameter descriptions
29+
30+
* `DEST-NAME`: name of the WAL file to send to the archive
31+
* `SOURCE-PATH`: path to the original encrypted WAL file
32+
* `ARCHIVE-COMMAND`: archive command to wrap. `%p` and `%f` are replaced with the decrypted WAL file path and WAL file name, respectively.
33+
34+
## Options
35+
36+
* `-V, --version`: show version information, then exit
37+
* `-?, --help`: show help information, then exit
38+
39+
!!! note
40+
41+
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`.
42+
43+
## Examples
44+
45+
### Using `cp`
46+
47+
```ini
48+
archive_command='pg_tde_archive_decrypt %f %p "cp %%p /mnt/server/archivedir/%%f"'
49+
```
50+
51+
### Using `PgBackRest`
52+
53+
```ini
54+
archive_command='pg_tde_archive_decrypt %f %p "pgbackrest --stanza=your_stanza archive-push %%p"'
55+
```
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# pg_tde_restore_encrypt
2+
3+
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`.
4+
5+
!!! note
6+
7+
This command is often use together with [pg_tde_archive_decrypt](./pg-tde-archive-decrypt.md).
8+
9+
## How it works
10+
11+
1. Replaces `%f` and `%p` in the restore command with the WAL file name and temporary file path (in `/dev/shm`)
12+
2. Runs the restore command to fetch the unencrypted WAL from the archive and write it to the temp file
13+
3. Encrypts the temp file and writes it to the destination path in PostgreSQL’s data directory
14+
15+
## Usage
16+
17+
```bash
18+
pg_tde_restore_encrypt [OPTION]
19+
pg_tde_restore_encrypt SOURCE-NAME DEST-PATH RESTORE-COMMAND
20+
```
21+
22+
## Parameter descriptions
23+
24+
* `SOURCE-NAME`: name of the WAL file to retrieve from the archive
25+
* `DEST-PATH`: path where the encrypted WAL file should be written
26+
* `RESTORE-COMMAND`: restore command to wrap; `%p` and `%f` are replaced with the WAL file name and path to write the unencrypted WAL, respectively
27+
28+
## Options
29+
30+
* `-V, --version`: show version information, then exit
31+
* `-?, --help`: show help information, then exit
32+
33+
!!! note
34+
35+
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`.
36+
37+
## Examples
38+
39+
### Using `cp`
40+
41+
```ini
42+
restore_command='pg_tde_restore_encrypt %f %p "cp /mnt/server/archivedir/%%f %%p"'
43+
```
44+
45+
### Using `PgBackRest`
46+
47+
```ini
48+
restore_command='pg_tde_restore_encrypt %f %p "pgbackrest --stanza=your_stanza archive-get %%f \"%%p\""'
49+
```

contrib/pg_tde/documentation/mkdocs.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,13 @@ nav:
193193
- "Functions": functions.md
194194
- "Streaming Replication with tde_heap": replication.md
195195
- "TDE operations":
196-
- "pg_tde CLI Tools":
196+
- "pg_tde CLI tools":
197197
- "Overview": command-line-tools/cli-tools.md
198198
- "pg_tde_change_key_provider": command-line-tools/pg-tde-change-key-provider.md
199-
- "pg_waldump": command-line-tools/pg-waldump.md
199+
- "pg_tde_archive_decrypt": command-line-tools/pg-tde-archive-decrypt.md
200+
- "pg_tde_restore_encrypt": command-line-tools/pg-tde-restore-encrypt.md
200201
- "pg_checksums": command-line-tools/pg-tde-checksums.md
202+
- "pg_waldump": command-line-tools/pg-waldump.md
201203
- "Uninstall pg_tde": how-to/uninstall.md
202204
- "Configure Multi-tenancy": how-to/multi-tenant-setup.md
203205
- "Encryption Enforcement": how-to/enforcement.md

0 commit comments

Comments
 (0)