# Validate Encryption with pg_tde

> Create or convert a table with tde_heap and verify its encryption status.

---

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

---

> This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see [PG TDE on Mimus](/docs/tde/).

After enabling the `pg_tde` extension for a database, you can begin encrypting data using the `tde_heap` table access method.

## Encrypt data in a new table {#encrypt-data-in-a-new-table}

1. Create a table in the database for which you have [enabled `pg_tde`](/docs/tde/upstream/setup/) using the `tde_heap` access method as follows:

    ```sql
    CREATE TABLE <table_name> (<field> <datatype>) USING tde_heap;
    ```

    **Warning:** Example for testing purposes only:

    ```sql
    CREATE TABLE albums (
        album_id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
        artist_id INTEGER,
        title TEXT NOT NULL,
        released DATE NOT NULL
    ) USING tde_heap;
    ```

    Learn more about table access methods and how you can enable data encryption by default in the [Table Access Methods and TDE](/docs/tde/upstream/index/table-access-method/) section.

2. To check if the data is encrypted, run the following function:

    ```sql
    SELECT pg_tde_is_encrypted('table_name');
    ```

    The function returns `true` or `false`.

3. (Optional) Rotate the principal key.

To re-encrypt the data using a new key, see [Principal key management](/docs/tde/upstream/functions/#principal-key-management).

## Encrypt existing table {#encrypt-existing-table}

You can encrypt an existing table. It requires rewriting the table, so for large tables, it might take a considerable amount of time.

Run the following command:

```sql
ALTER TABLE table_name SET ACCESS METHOD tde_heap;
```

> [!IMPORTANT]
> Using `SET ACCESS METHOD` drops hint bits which can impact query performance. To restore performance, run:
>
> ```sql
> SELECT count(*) FROM table_name;
> ```
>
> This forces PostgreSQL to check every tuple for visibility and reset the hint bits.

> [!TIP]
> Want to remove encryption later? See how to [decrypt your data](/docs/tde/upstream/how-to/decrypt/).

## Next steps {#next-steps}

[Configure WAL encryption ](/docs/tde/upstream/wal-encryption/)

[PG.CENTER edition](https://github.com/pgsty/doc.pg.center/blob/4410c32dc9186a22859008303f474b72a779f583/content/percona/test.md) · [Upstream source](https://github.com/percona/pg_tde/blob/5dd7a9e4e3599d88546f5de67ff0f4ef3fe51a9a/documentation/docs/test.md)

---

Backlinks:

- [A production checklist for pg_tde](/docs/tde/upstream/blog/guide/production-checklist/)
- [An early look at pg_tde](/docs/tde/upstream/blog/percona/early-project-update/)
- [FAQ](/docs/tde/upstream/faq/)
- [Features](/docs/tde/upstream/features/)
- [Local keyring](/docs/tde/upstream/global-key-provider-configuration/keyring/)
- [Default principal key](/docs/tde/upstream/global-key-provider-configuration/set-principal-key/)
- [Get started](/docs/tde/upstream/install/)
- [Beta](/docs/tde/upstream/release-notes/beta/)
