Preparing Postgres source databases
Configuring Postgres for EDB Data Migration Service (EDB DMS) requires administrative privileges. Create a change data capture (CDC) migration role with limited privileges for data migration.
Execute SQL statements with psql or a similar client.
To connect to the source database using psql
:
Where:
<PG_DB_NAME>
is the name of the Postgres database source to connect to.<PG_HOST>
is the Postgres database host.<PG_PORT>
is the Postgres database port.<PG_USERNAME>
is an administrative user who can create and grant roles, alter ownership of tables to migrate, and create a replication slot.
This command prompts you for the password associated with <PG_USERNAME>
.
Postgres database configuration
To prepare the source Postgres database configuration:
- Set the Postgres configuration.
- Create new roles and grant acccess for CDC migration.
- Grant usage of the source schemas to the CDC migration role.
- Grant
SELECT
on source tables to the CDC migration role. - Grant
CREATE
privileges on the source database to the CDC migration role.
Set the Postgres configuration
Ensure the following configuration entries for Postgres are set as follows:
Ensure
wal_level
is configured aslogical
.The CDC migration process leverages Postgres logical decoding. Setting
wal_level
tological
enables logical decoding of the Postgres write-ahead log (WAL).Ensure
max_wal_senders
is configured appropriately.If EDB Data Migration Service migration is the first streaming client for your database, set
max_wal_senders
to at least1
. Other streaming clients might be present. Consult your DBA for the appropriate value for streaming client connectivity.Ensure
max_replication_slots
is configured appropriately.max_replication_slots
must be at least1
for the CDC migration process. This value can be higher if your organization uses Postgres replication.See the Postgres replication documentation for more information.
Ensure
max_wal_size
is configured for adequate WAL LSN lifetime.Set the
max_wal_size
value large enough that production traffic is generating mostly timed checkpoints and not requested checkpoints based on WAL size.The streaming migration process also requires changes to be available in the WAL until they can be streamed to durable message storage in the cloud infrastructure of EDB DMS. Setting
max_wal_size
too small can affect performance. It can also interfere with the migration process by allowing Postgres LSNs to be dropped from the WAL before they can be streamed.For more information, see this EDB blog post on tuning
max_wal_size
and the Postgres WAL documentation.
Config validation script
The EDB DMS Reader installation (packaged as cdcreader
) comes with a helper script that validates the Postgres configuration and helps you identify any issues. After you configure the database, we recommend running the script and ensuring all checks passed.
Run the script without arguments to print the usage:
Create new roles and grant acccess for CDC migration
First, create a new role for CDC migration with LOGIN
and REPLICATION
abilities granted:
<MIGRATION_ROLE>
needs to own the source tables to autocreate Postgres publications. Because the source tables are already owned by another role, you create a role/user that can act as the new owner and grant the specified replication group role to both the current table owner and to <MIGRATION_ROLE>
:
Where:
<MIGRATION_ROLE>
is the name of the Postgres role or user to use for CDC migration database access.<ORIGINAL_OWNER>
is the original production owner of the table.<REPLICATION_GROUP>
is the name of a role used to own the source tables to migrate for publication autocreation.
Grant usage of the source schemas to the CDC migration role
To select tables in a schema, the user must grant usage on the schema in addition to granting SELECT
on the tables of the schema. This is necessary for all source schemas containing tables to be migrated.
You can grant usage on a schema using the following command:
Grant SELECT
on source tables to the CDC migration role
The new <MIGRATION_ROLE>
now has schema access, but still needs SELECT
access to the source tables of those schemas. You can grant access across a schema
or for each table.
For an entire schema's tables, use this command:
For each table, use:
Where:
<DB_SCHEMA>
is the database schema name for the tables to migrate.<MIGRATION_ROLE>
is the name of the Postgres role or user to use for CDC migration database access.<TABLE_NAME>
is the name of a table to migrate.
Grant CREATE
privileges on the source database to the CDC migration role
Since the pgoutput
plugin is being used, the migration user needs to be granted CREATE
privileges on the source database in order for Debezium to be able to create publications. The CREATE
privilege can be granted using the following command:
SSL configuration
Ensure you configure your source database server to accept SSL connections to allow the EDB DMS Reader to connect to it. You must create a server certificate and a server private key, for example, with OpenSSL, to enable this configuration.
Run the config validation script
Now that you have stepped through the entire configuration process, validate your Postgres configuration using the config validation script with the correct parameters. To illustrate, consider the following example:
- First, create an array that contains the name of all the tables that need to be migrated in <schema_name>.<table_name> format. In this example: