Skip to content

Create replication.md quick walkthrough for pg_tde #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
72406c5
updated replication.md
Andriciuc May 8, 2025
dd248f4
Update replication.md
Andriciuc May 8, 2025
6d1f228
small fixes to text
Andriciuc May 8, 2025
486a1b0
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc May 19, 2025
449a781
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc May 20, 2025
e672241
Updated replication.md
Andriciuc May 21, 2025
55e2a57
Merge branch 'DOCS-create-replication.md' of https://github.com/perco…
Andriciuc May 21, 2025
d995bf3
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc May 21, 2025
6bf49ad
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc May 22, 2025
9e04c3d
updated replication.md with proper information
Andriciuc May 23, 2025
288fbe4
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc May 23, 2025
f27ba4d
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc May 23, 2025
7a94559
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc May 27, 2025
1451d7a
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 2, 2025
02333be
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 4, 2025
5edfd88
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 4, 2025
c736a0d
Update replication.md
Andriciuc Jun 4, 2025
2652ab2
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 5, 2025
f704afa
Update replication.md
Andriciuc Jun 5, 2025
be718a5
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 5, 2025
6bca4af
Update replication.md
Andriciuc Jun 6, 2025
963c6bc
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 6, 2025
6e24fb9
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 6, 2025
d6863a4
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 9, 2025
0572b97
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 9, 2025
81f82f7
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 9, 2025
15bd921
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 9, 2025
aea50a2
Update replication.md
Andriciuc Jun 9, 2025
f37eecf
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 11, 2025
ef2540d
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 11, 2025
3c7e6f3
Update replication.md
Andriciuc Jun 11, 2025
3af26a7
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 12, 2025
9716803
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 12, 2025
24af28d
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 13, 2025
ed3ef1a
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 13, 2025
b8fa9f2
Merge branch 'TDE_REL_17_STABLE' into DOCS-create-replication.md
Andriciuc Jun 16, 2025
d15fff3
Merge branch 'release-17.5.2' into DOCS-create-replication.md
Andriciuc Jun 16, 2025
a9fb88e
Merge branch 'release-17.5.2' into DOCS-create-replication.md
Andriciuc Jun 18, 2025
6ef6038
Merge branch 'release-17.5.2' into DOCS-create-replication.md
Andriciuc Jun 19, 2025
b877cef
Merge branch 'release-17.5.2' into DOCS-create-replication.md
Andriciuc Jun 20, 2025
23189d7
updated based on latest feedback
Andriciuc Jun 25, 2025
817d133
Merge branch 'release-17.5.2' into DOCS-create-replication.md
Andriciuc Jun 25, 2025
e1bd244
Merge branch 'release-17.5.2' into DOCS-create-replication.md
Andriciuc Jun 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 102 additions & 3 deletions contrib/pg_tde/documentation/docs/replication.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,103 @@
# Replication
# Streaming Replication with tde_heap

<!-- To add information on Replication affecting pg_tde for customers and how it interacts with it
Also, don't forget to add it to TOC>
This section outlines how to set up PostgreSQL streaming replication when the `pg_tde` extension, specifically the [`tde_heap`](index/table-access-method.md) access method, is enabled on the primary server.

Before you begin, ensure you have followed the [`pg_tde` setup instructions](setup.md).

!!! note
You do **not** need to run `CREATE EXTENSION` on the standby. It will be replicated automatically.

## 1. Configure the Primary

### Create a principal key

Use the [`pg_tde_set_server_key_using_global_key_provider`](functions.md#pg_tde_set_server_key_using_global_key_provider) function to create a principal key.

### Create the replication role

Create a replication role on the primary:

```sql
CREATE ROLE example_replicator WITH REPLICATION LOGIN PASSWORD 'example_password';
```

### Configure pg_hba.conf

To allow the replica to connect to the primary server, add the following line in `pg_hba.conf`:

```conf
host replication example_replicator standby_ip/32 scram-sha-256
```

Ensure that it is placed before the other host rules for replication and then **reload** the configuration:

```sql
SELECT pg_reload_conf();
```

## 2. Configure the Standby

### Perform a database backup

Run the base backup from your standby machine to pull the encrypted base backup:

```bash
export PGPASSWORD='example_password'
pg_basebackup \
-h primary_ip \
-D /var/lib/pgsql/data \
-U example_replicator \
--wal-method=stream \
--slot=tde_slot \
-C \
-c fast \
-v -P
```

### Configure postgresql.conf

After the base backup completes, add the following line to the standby's `postgresql.conf` file:

```ini
shared_preload_libraries = 'pg_tde'
```

## 3. Start and validate replication

Assuming that the primary and the standby are running on separate hosts, start the PostgreSQL service:

```bash
sudo systemctl start postgresql
```

!!! warning "Key management consistency **required** for replication"

If you're using a KMS provider, such as Vault or KMIP, make sure that both the primary and the standby have access to the **same** key management configuration, and that the paths to the configuration files are identical on both systems.

For example:

- If you configure Vault with a secret path: `/path/to/secret.file`, then that file **must** exist at the same path on both the primary and the standby.
- If you use the `keyring_file` provider, be aware that it stores key material in a local file and it is **not designed** for shared or concurrent use across multiple servers. It is **not recommended** in replication setups.

* On primary:

```sql
SELECT client_addr, state
FROM pg_stat_replication;
```

* On standby:

```sql
SELECT
pg_is_in_recovery() AS in_recovery,
pg_last_wal_receive_lsn() AS receive_lsn,
pg_last_wal_replay_lsn() AS replay_lsn;
```

!!! tip
Want to verify that everything is working? After creating an encrypted table on the primary, run the following command on the standby to confirm that the encryption is active and the keys are resolved:

```sql
SELECT pg_tde_is_encrypted('your_encrypted_table');
```
1 change: 1 addition & 0 deletions contrib/pg_tde/documentation/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ nav:
- "Architecture": architecture/index.md
- "GUC Variables": variables.md
- "Functions": functions.md
- "Streaming Replication with tde_heap": replication.md
- "TDE Operations":
- "pg_tde CLI Tools":
- "CLI Overview": command-line-tools/index.md
Expand Down