Skip to content

Encrypt your first table with PG TDE

Configure a keyring provider, create an encrypted table using tde_heap, and verify transparent page encryption and startup protection.

Configure preloading and a local keyring

On an instance with pg_tde installed under /usr/mimus-19, add pg_tde to shared_preload_libraries, restart PostgreSQL, and register a local keyring file for your lab database:

sudo install -d -m 0700 -o postgres -g postgres /var/lib/mimus-keys

psql -X -d postgres -c "ALTER SYSTEM SET shared_preload_libraries = 'pg_tde';"
pg_ctl -D /var/lib/mimus/data restart

Now enable the extension and bind a principal key in postgres:

CREATE EXTENSION pg_tde WITH SCHEMA public;

SELECT pg_tde_add_database_key_provider_file(
    'lab_provider', '/var/lib/mimus-keys/lab.per');
SELECT pg_tde_create_key_using_database_key_provider(
    'lab_key', 'lab_provider');
SELECT pg_tde_set_key_using_database_key_provider(
    'lab_key', 'lab_provider');
Production key management

File providers are intended for local testing and development. Production deployments should store principal keys in HashiCorp Vault or a KMIP server; see Keys and WAL encryption.

Create and verify an encrypted table

Create a table with USING tde_heap plus an index and out-of-line text, then confirm encryption status:

CREATE TABLE public.ledger (
    id      integer PRIMARY KEY,
    memo    text NOT NULL,
    balance bigint NOT NULL
) USING tde_heap;

INSERT INTO public.ledger VALUES (1, repeat('confidential-', 200), 50000);
SELECT pg_tde_is_encrypted('public.ledger'::regclass);

pg_tde_is_encrypted returns t. Primary heap pages, the primary-key B-tree index, and the TOAST table are all encrypted on disk while remaining transparent to SQL, MySQL (pg_mysql), and TDS (Babelfish) queries.

Check the cluster startup guard

Inspect the cluster’s recorded feature lock:

SHOW mimus_required_features;
-- Returns: tde

Once tde is recorded in mimus_required_features, Mimus refuses to start or replay WAL against this data directory if pg_tde is omitted from shared_preload_libraries, preventing accidental startup without storage decryption hooks. For backup and offline page verification, continue to the PG TDE manual.

Scan to open this page
https://mimus.pgsty.com/docs/tutorials/encrypt-first-table/