# Enable TDE and encrypt a table

> Configure preload, create a database key and check the table and its primary key.

---

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

---

## Prepare a new database {#enable}

Use a matching Mimus 19.0.1 installation containing the `pg_tde` library, extension SQL and control file. On a new test cluster add `pg_tde` to `shared_preload_libraries` in `postgresql.conf`, retaining other required libraries. Restart with the matching server. Connect with `psql` as an administrator to the database in which you will create the table.

For this exercise, create a directory outside `PGDATA` named `/var/lib/mimus-keys` on the server, owned by the database service account with mode 0700. Use a fresh file name. The server will manage the keyring. File providers are suitable for local exercises; anyone who takes the backup and the readable keyring can recover the data.

## Create and verify {#table}

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

CREATE TABLE public.ledger (
    id integer PRIMARY KEY,
    balance integer NOT NULL
) USING tde_heap;
INSERT INTO public.ledger VALUES (1, 100);

SELECT id, balance FROM public.ledger;
SELECT pg_tde_is_encrypted('public.ledger'::regclass) AS table_encrypted,
       pg_tde_is_encrypted('public.ledger_pkey'::regclass) AS index_encrypted;
SHOW mimus_required_features;
```

Expect row `(1,100)`, two true values, and `tde` in the feature list. To convert an existing heap table use `ALTER TABLE ... SET ACCESS METHOD tde_heap` after configuring its database key. This rewrites storage. Allow for the table lock, disk space and backup window.

## Which objects are protected? {#coverage}

The encrypted table’s data, indexes and out-of-line TOAST values are covered. For a partitioned table, check each physical partition that stores rows. Native PG `CREATE TEMP TABLE` can use `tde_heap`. Babelfish table variables, `#` tables and temporary `SELECT INTO` use `heap` with enforcement off for the runtime login. [T-SQL temporary objects and plaintext on disk](/docs/mssql/temporary-storage/)

System catalogs, statistics, object names and query spill files remain readable. A normal heap table stays plaintext. Logical exports return readable data, so protect their storage and transport separately. Enable WAL encryption separately if WAL must also be protected. [Key and WAL configuration](/docs/tde/keys/)

To reorganize an encrypted table on Mimus, use native PostgreSQL 19 `REPACK` and verify the resulting table, index and TOAST storage. The external pg_repack extension is unsupported. [Storage compatibility](/docs/intro/scope/#storage)

---

Backlinks:

- [Extension and application compatibility](/docs/intro/scope/)
- [Create encrypted permanent tables over TDS](/docs/mssql/encrypted-tables/)
- [PG TDE](/docs/tde/)
- [Keys and WAL encryption](/docs/tde/keys/)
- [Back up, restore and migrate](/docs/tde/recovery/)
