# Configure pg_tde

> Preload the library, restart PostgreSQL, and enable the extension in a database.

---

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

---

> The packages and support matrix below belong to Percona PostgreSQL. Build pg_tde against the matching Mimus installation before enabling it. [Mimus procedure](/docs/patches/base/#components)

Before you can use `pg_tde` for data encryption, you must enable the extension and configure PostgreSQL to load it at startup. This setup ensures that the necessary hooks and shared memory are available for encryption operations.

> [!NOTE]
> To learn how to configure multi-tenancy, refer to the [Configure multi-tenancy](/docs/tde/upstream/how-to/multi-tenant-setup/) guidelines.

The `pg_tde` extension requires additional shared memory. You need to configure PostgreSQL to preload it at startup.

## 1. Configure shared_preload_libraries {#1-configure-sharedpreloadlibraries}

You can configure the `shared_preload_libraries` parameter in two ways:

* Add the following line to the `postgresql.conf` file:

    ```bash
    shared_preload_libraries = 'pg_tde'
    ```

* Use the [ALTER SYSTEM ](https://www.postgresql.org/docs/current/sql-altersystem.html) command. Run the following command in `psql` as a **superuser**:

    ```sql
    ALTER SYSTEM SET shared_preload_libraries = 'pg_tde';
    ```

## 2. Restart the PostgreSQL cluster {#2-restart-the-postgresql-cluster}

Restart the `postgresql` cluster to apply the configuration.

* On Debian and Ubuntu:

       ```sh
       sudo systemctl restart postgresql.service
       ```

* On RHEL and derivatives:

       ```sh
       sudo systemctl restart postgresql-17
       ```

## 3. Create the extension {#3-create-the-extension}

After restarting PostgreSQL, connect to `psql` as a **superuser** or **database owner** and run:

```sql
CREATE EXTENSION pg_tde;
```

See [CREATE EXTENSION ](https://www.postgresql.org/docs/current/sql-createextension.html) for more details.

> [!NOTE]
> The `pg_tde` extension is created only for the current database. To enable it for other databases, you must run the command in each individual database.

## 4. (Optional) Enable pg_tde by default {#4-optional-enable-pgtde-by-default}

To automatically have `pg_tde` enabled for all new databases, modify the `template1` database:

```sql
psql -d template1 -c 'CREATE EXTENSION pg_tde;'
```

> [!NOTE]
> It’s recommended to use an external key provider (KMS) to manage encryption keys. For configuration instructions, see [Next steps](#next-steps).

## Next steps {#next-steps}

[Configure Key Management (KMS) ](/docs/tde/upstream/global-key-provider-configuration/overview/)

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

---

Backlinks:

- [Debian / Ubuntu](/docs/tde/upstream/apt/)
- [Configure multi-tenancy](/docs/tde/upstream/how-to/multi-tenant-setup/)
- [Table access methods](/docs/tde/upstream/index/table-access-method/)
- [Get started](/docs/tde/upstream/install/)
- [Streaming replication](/docs/tde/upstream/replication/)
- [Verify encryption](/docs/tde/upstream/test/)
- [RHEL / Rocky / Alma](/docs/tde/upstream/yum/)
