Prepare an External Source for Migration
Turn on logical replication on a source database hosted by Amazon RDS, Amazon Aurora or Google Cloud SQL, so that the replication method of the Managed PostgreSQL migration can use it.
What the Source Needs
The replication method of
Migrate to Managed PostgreSQL
uses PostgreSQL logical replication. On the source, it needs:
wal_levelset tological.- A migration user allowed to replicate and to manage replication slots.
- A free replication slot for each database you migrate.
- A network path from the Managed PostgreSQL service to the source. The address the service connects from is described in Allow the target to reach the source.
A managed provider does not let you edit postgresql.conf or pg_hba.conf. Each one has its own
parameter for logical replication and its own grant for the migration user. The sections below
name them; the provider’s documentation is the reference for the exact steps, which change over
time. For a server you run yourself, follow
Prepare the source
on the migration page.
When a database does not meet the requirements, the migration uses the dump method for it. Run
the migration pre-check described on the migration page to see which method each database will
get before you start.
Amazon RDS for PostgreSQL
- Set the parameter
rds.logical_replicationto1in a custom DB parameter group attached to the instance, then reboot the instance so the change takes effect. - Give the migration user the
rds_replicationrole. - Allow the address of the Managed PostgreSQL service in the security group of the instance.
Reference: Logical replication for Amazon RDS for PostgreSQL.
Amazon Aurora PostgreSQL
- Set
rds.logical_replicationto1in a custom DB cluster parameter group, then reboot the writer instance. - Give the migration user the
rds_replicationrole. - Point the migration at the writer endpoint of the cluster.
Reference: Setting up logical replication for Aurora PostgreSQL.
Google Cloud SQL for PostgreSQL
Set the database flag
cloudsql.logical_decodingtoon. The instance restarts.Give the migration user the
REPLICATIONattribute:ALTER USER MIGRATION_USER WITH REPLICATION;Add the address of the Managed PostgreSQL service to the authorized networks of the instance.
Reference: Configure logical replication and decoding in Cloud SQL.
Check the Source
These queries are standard PostgreSQL and work on every provider. Run them on the source, connected as the migration user.
The WAL level, which must be logical:
SHOW wal_level;The free replication slots, which must be at least the number of databases you migrate:
SELECT current_setting('max_replication_slots')::int - count(*) AS free_slots
FROM pg_replication_slots;The replication attribute of the migration user, on Cloud SQL:
SELECT rolname, rolreplication FROM pg_roles WHERE rolname = 'MIGRATION_USER';On RDS and Aurora, membership of rds_replication:
SELECT pg_has_role('MIGRATION_USER', 'rds_replication', 'member');Parameters:
MIGRATION_USER: the user you pass to--pg-migration-username.
Then run the migration pre-check and start the migration, as described in Migrate to Managed PostgreSQL.
Warning
A logical replication slot that nobody reads keeps WAL on the source until its disk is full. After you stop or abandon a migration, check on the source that its slots are gone, as shown in Cut over and stop the migration.