# 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.

---

LLMS index: [llms.txt](/llms.txt)

---

## Configure preloading and a local keyring {#provider}

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:

```sh
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`:

```sql
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');
```

> [!IMPORTANT] 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](/docs/tde/keys/).

## Create and verify an encrypted table {#encrypt}

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

```sql
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 {#guard}

Inspect the cluster's recorded feature lock:

```sql
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](/docs/tde/).

---

Backlinks:

- [Tutorials](/docs/tutorials/)
