Select a documentation version: <button class="button button-with-icon cloud-select-dropdown__button button-primary" aria-haspopup="true">18.3.0</button>

- [Current (18.4.0)](https://docs.cloud.google.com/alloydb/omni/containers/current/docs/migrate-tde-cluster.md.txt)
- [18.4.0](https://docs.cloud.google.com/alloydb/omni/containers/18.4.0/docs/migrate-tde-cluster.md.txt)
- [18.3.0](https://docs.cloud.google.com/alloydb/omni/containers/18.3.0/docs/migrate-tde-cluster.md.txt)
- [18.1.0](https://docs.cloud.google.com/alloydb/omni/containers/18.1.0/docs/migrate-tde-cluster.md.txt)

This guide describes how to migrate data between
[transparent data encryption-enabled](https://docs.cloud.google.com/alloydb/omni/containers/18.3.0/docs/transparent-data-encryption-omni.md.txt)
(TDE) and non-encrypted clusters using `pg_dump` and `pg_restore`.

Both migration directions---TDE to non-encrypted and the other way
around---are supported and use standard PostgreSQL logical backup tools.

Logical migration using `pg_dump` decodes the encrypted data on-the-fly at the
source and dumps it as unencrypted SQL statements. When you restore the data, the
destination cluster writes the data according to its own encryption settings.
The destination cluster encrypts the data if TDE is enabled, and it writes
as plain text if TDE is disabled.

> [!CAUTION]
> Caution: The generated SQL file contains unencrypted data from your database. Verify that the SQL file is stored securely and delete it after the restore process is complete.

## Before you begin

- Verify that you installed AlloyDB Omni. For more information, see [Install AlloyDB Omni using containers](https://docs.cloud.google.com/alloydb/omni/containers/18.3.0/docs/deploy-vm.md.txt).
- If you're migrating to a TDE-enabled database server, verify that you set up your key management provider. For more information, see [Create a TDE-enabled cluster](https://docs.cloud.google.com/alloydb/omni/containers/18.3.0/docs/create-tde-cluster.md.txt).

## Migrate a TDE-enabled database to a TDE-disabled database

1. Dump the database from the TDE-enabled database server to a file on the host.

   ### Docker

   ```bash
   docker exec -i TDE_CONTAINER_NAME pg_dump -U postgres -d DATABASE_NAME > /tmp/decrypted_dump.sql
   ```

   ### Podman

   ```bash
   podman exec -i TDE_CONTAINER_NAME pg_dump -U postgres -d DATABASE_NAME > /tmp/decrypted_dump.sql
   ```
2. Start a TDE-disabled AlloyDB Omni server by following the
   instructions in

   [Install AlloyDB Omni using Docker](https://docs.cloud.google.com/alloydb/omni/containers/18.3.0/docs/quickstart.md.txt#install-using-docker).

3. Restore the dump file to the non-encrypted database server.

   ### Docker

   ```bash
   docker exec -i NON_TDE_CONTAINER_NAME psql -U postgres -c "CREATE DATABASE DATABASE_NAME"
   docker exec -i NON_TDE_CONTAINER_NAME psql -U postgres -d DATABASE_NAME < /tmp/decrypted_dump.sql
   ```

   ### Podman

   ```bash
   podman exec -i NON_TDE_CONTAINER_NAME psql -U postgres -c "CREATE DATABASE DATABASE_NAME"
   podman exec -i NON_TDE_CONTAINER_NAME psql -U postgres -d DATABASE_NAME < /tmp/decrypted_dump.sql
   ```

## Migrate a TDE-disabled database to a TDE-enabled database

1. Use `pg_dump` to dump the database from the non-encrypted database server.

   ### Docker

   ```bash
   docker exec -i NON_TDE_CONTAINER_NAME pg_dump -U postgres -d DATABASE_NAME > /tmp/src_plaintext_dump.sql
   ```

   ### Podman

   ```bash
   podman exec -i NON_TDE_CONTAINER_NAME pg_dump -U postgres -d DATABASE_NAME > /tmp/src_plaintext_dump.sql
   ```
2. Start a TDE-enabled AlloyDB Omni server following the
   instructions in [Create a TDE-enabled cluster](https://docs.cloud.google.com/alloydb/omni/containers/18.3.0/docs/create-tde-cluster.md.txt).

3. Restore to the TDE-enabled database server. The data is transparently
   encrypted as it is written.

   ### Docker

   ```bash
   docker exec -i TDE_CONTAINER_NAME psql -U postgres -c "CREATE DATABASE DATABASE_NAME"
   docker exec -i TDE_CONTAINER_NAME psql -U postgres -d DATABASE_NAME < /tmp/src_plaintext_dump.sql
   ```

   ### Podman

   ```bash
   podman exec -i TDE_CONTAINER_NAME psql -U postgres -c "CREATE DATABASE DATABASE_NAME"
   podman exec -i TDE_CONTAINER_NAME psql -U postgres -d DATABASE_NAME < /tmp/src_plaintext_dump.sql
   ```

## What's next

- [Run and connect to AlloyDB Omni](https://docs.cloud.google.com/alloydb/omni/containers/18.3.0/docs/run-connect.md.txt).