Database Migration Service supports continuous migrations from source databases to Cloud SQL destination databases.
Supported source databases for PostgreSQL include:
Configuring your source requires configuring both the source instance and underlying source databases.
To configure your source instance, follow these steps:
postgres
database. If you don't have this database, then create it.Install the pglogical
package on the source instance and make sure that it's included in the shared_preload_libraries
variable. See Install the pglogical
package on the source instance for your environment.
Verify the extensions in your source instance. Database Migration Service doesn't migrate extensions that are unsupported by Cloud SQL. The presence of these extensions doesn't block the migration but to ensure a smooth migration process, please verify that your objects or applications don't reference any unsupported extensions. We recommend removing these extensions and references from your source database before you proceed.
For sources that use the pg_cron
extension: The pg_cron
extension (or any cron
settings associated with the extension) isn't migrated by Database Migration Service, but it is supported in Cloud SQL for PostgreSQL destinations. If you use the pg_cron
extension in your source databases, you can re-install it on your destination instance after the migration is complete.
Database Migration Service migrates all databases under your source instance other than the following databases:
template0
and template1
template0
, template1
, and rdsadmin
template0
and template1
azure_maintenance
, azure_sys
, template0
, template1
Do the following on each database in your source instance that isn't mentioned above:
For PostgreSQL version 9.4 sources only, install the following pglogical
extensions on each database in your source instance:
CREATE EXTENSION IF NOT EXISTS pglogical;
CREATE EXTENSION IF NOT EXISTS pglogical_origin;
For all other versions, install only the pglogical
extension on each database in your source instance: CREATE EXTENSION IF NOT EXISTS pglogical
.
For tables that don't have primary keys, Database Migration Service supports migration of the initial snapshot and INSERT
statements during the CDC phase. You should migrate UPDATE
and DELETE
statements manually.
The USER you're using to connect to the source instance (which will be configured as the user in the Connection Profiles page) must have certain privileges on each of the migrated databases, as well as the default postgres
database. You can create a new user or reuse an existing one. To set these privileges, connect to the instance and run the following commands:
GRANT USAGE on SCHEMA SCHEMA to USER
on all schemas (aside from the information schema and schemas starting with "pg_") on each database to migrate.GRANT USAGE on SCHEMA pglogical to PUBLIC;
on each database to migrate.GRANT SELECT on ALL TABLES in SCHEMA pglogical to USER
on all databases to get replication information from source databases.GRANT SELECT on ALL TABLES in SCHEMA SCHEMA to USER
on all schemas (aside from the information schema and schemas starting with "pg_") on each database to migrate.GRANT SELECT on ALL SEQUENCES in SCHEMA SCHEMA to USER
on all schemas (aside from the information schema and schemas starting with "pg_") on each database to migrate.GRANT rds_replication to USER
ALTER USER USER with REPLICATION
rolepglogical
package on the source instanceThis section describes how to configure the pglogical
package and the applicable parameters, depending on your source instance.
shared_preload_libraries
must include pglogical
.
To set this parameter, run the ALTER SYSTEM SET shared_preload_libraries = 'pglogical,[any other libraries in your instance]';
command.
wal_level
to logical
.To set this parameter, run the ALTER SYSTEM SET wal_level = 'logical';
command.
Set wal_sender_timeout
to 0
.
To set this parameter, run the ALTER SYSTEM SET wal_sender_timeout = 0;
command, where 0
disables the timeout mechanism that's used to terminate inactive replication connections.
max_replication_slots defines the maximum number of replication slots the source instance can support. It must be set to at least the number of subscriptions expected to connect, plus some reserves for table synchronization.
Database Migration Service requires one slot for each database that's migrated (which is all of the databases under the source instance).
For example, if there are 5 databases on the source instance and if there are 2 migration jobs created for the source, then the number of replication slots must be at least 5 * 2 = 10, plus the number of replication slots already used by you. If you plan to use adjusted data dump parallelism settings, make sure to increase the number of replication slots and verify your configuration by running the migration job test when you create the migration job.
To set this parameter, run the ALTER SYSTEM SET max_replication_slots = #;
command, where # represents the maximum number of replication slots.
max_wal_senders should be set to at least the same as max_replication_slots
, plus the number of senders already used on your instance.
For example, if the max_replication_slots
parameter is set to 10
, and you're already using 2 senders, then the number of WAL sender processes running at the same time would be 10 + 2 = 12. If you plan to use adjusted data dump parallelism settings, make sure to increase the number of senders and verify your configuration by running the migration job test when you create the migration job.
ALTER SYSTEM SET max_wal_senders = #;
command, where # represents the number of WAL sender processes running simultaneously. max_worker_processes
already used on your instance. If you plan to use adjusted data dump parallelism settings, make sure to increase the number of worker processes and verify your configuration by running the migration job test when you create the migration job.
To set this parameter, run the ALTER SYSTEM SET max_worker_processes = #;
command, where # represents the number of databases that will be migrated.
To configure your Microsoft Azure Database for PostgreSQL source, follow these steps:
For PostgreSQL version 9.4 sources only, install the following pglogical
extensions on each database in your source instance:
CREATE EXTENSION IF NOT EXISTS pglogical;
CREATE EXTENSION IF NOT EXISTS pglogical_origin;
For all other versions, install the pglogical
extension on each database in your source instance: CREATE EXTENSION IF NOT EXISTS pglogical
.
Configure the required server parameters on your source by using the Microsoft Azure portal. For more information, see Configure server parameters in Azure Database for PostgreSQL and Server parameters in Azure Database for PostgreSQL in the Microsoft documentation.
Configure the following parameters:
shared_preload_libraries
to include pglogical
.azure.extensions
to include pglogical
.wal_level
to logical
.Set max_replication_slots
to at least the number of subscriptions expected to connect, plus some reserves for table synchronization.
The max_replication_slots
parameter defines the maximum number of replication slots the source instance can support.
Database Migration Service requires one slot for each database that's migrated (which is all of the databases under the source instance).
For example, if there are 5 databases on the source instance and if there are 2 migration jobs created for the source, then the number of replication slots must be at least 5 * 2 = 10, plus the number of replication slots already used by you. If you plan to use adjusted data dump parallelism settings, make sure to increase the number of replication slots and verify your configuration by running the migration job test when you create the migration job.
Set max_wal_senders
to at least the same as max_replication_slots
, plus the number of senders already used on your instance.
For example, if the max_replication_slots
parameter is set to 10
, and you're already using 2 senders, then the number of WAL sender processes running at the same time would be 10 + 2 = 12.
If you plan to use adjusted data dump parallelism settings, make sure to increase the number of senders and verify your configuration by running the migration job test when you create the migration job.
Set max_worker_processes
to at least the same number of databases that Database Migration Service is going to migrate (which is all of the databases under the source instance), plus the number of max_worker_processes
already used on your instance.
If you plan to use adjusted data dump parallelism settings, make sure to increase the number of worker processes and verify your configuration by running the migration job test when you create the migration job.
Check the value of your require_secure_transport
setting.
By default, Microsoft Azure databases require SSL/TLS encryption for all incoming connections. Depending on the require_secure_transport
value, use one of the following encryption settings when you create the source connection profile:
require_secure_transport
is set to on
, select Basic, TLS, or mTLS.require_secure_transport
is set to off
, select None.Install the pglogical
extension on your source database.
For more information, see Using PostgreSQL extensions with Amazon RDS for PostgreSQL in the Amazon RDS documentation.
Configure the source instance using parameter groups.
shared_preload_libraries
parameter includes pglogical
.rds.logical_replication
parameter to 1. This will enable WAL logs at the 'logical' level.wal_sender_timeout
parameter to 0. This will disable the timeout mechanism that's used to terminate inactive replication connections.Set the max_replication_slots parameter. This parameter defines the maximum number of replication slots the source instance can support. It must be set to at least the number of subscriptions expected to connect, plus some reserves for table synchronization.
Database Migration Service requires one slot for each database that's migrated (which is all of the databases under the source instance).
For example, if there are 5 databases on the source instance and if there will be 2 migration jobs created for the source, then the number of replication slots must be at least 5 * 2 = 10, plus the number of replication slots already used by you. If you plan to use adjusted data dump parallelism settings, make sure to increase the number of replication slots and verify your configuration by running the migration job test when you create the migration job.
The default value for this parameter is 10.
Set the max_wal_senders parameter to at least the same as max_replication_slots
, plus the number of senders already used on your instance.
For example, if the max_replication_slots
parameter is set to 10
, and you're already using 2 senders, then the number of WAL sender processes running at the same time would be 10 + 2 = 12. If you plan to use adjusted data dump parallelism settings, make sure to increase the number of senders and verify your configuration by running the migration job test when you create the migration job.
The default value for this parameter is 10.
Set the max_worker_processes source parameter to at least the same number of databases that Database Migration Service is going to migrate (which is all of the databases under the source instance), plus the number of max_worker_processes
already used on your instance. If you plan to use adjusted data dump parallelism settings, make sure to increase the number of worker processes and verify your configuration by running the migration job test when you create the migration job.
The default value for this parameter is 8.
Attach the parameter group to the instance. If you're creating a new instance, then you can find this option under Additional Configuration.
Otherwise, modify the instance to attach the parameter group.
To apply the configuration changes, restart the source instance.
Enable logical replication and decoding for the source database by configuring the following flags:
cloudsql.logical_decoding
and cloudsql.enable_pglogical
flags to on
. Set the max_replication_slots flag. This flag defines the maximum number of replication slots that the source instance can support. It must be set to at least the number of subscriptions expected to connect, plus some reserves for table synchronization.
Database Migration Service requires one slot for each database that's migrated (which is all of the databases under the source instance).
For example, if there are 5 databases on the source instance and if there will be 2 migration jobs created for the source, then the number of replication slots must be at least 5 * 2 = 10, plus the number of replication slots already used by you. If you plan to use adjusted data dump parallelism settings, make sure to increase the number of replication slots and verify your configuration by running the migration job test when you create the migration job.
The default value for this flag is 10.
Set the max_wal_senders flag to at least the same as max_replication_slots
, plus the number of senders already used on your instance.
For example, if the max_replication_slots
flag is set to 10
, and you're already using 2 senders, then the number of WAL sender processes running at the same time would be 10 + 2 = 12. If you plan to use adjusted data dump parallelism settings, make sure to increase the number of senders and verify your configuration by running the migration job test when you create the migration job.
The default value for this flag is 10.
Set the max_worker_processes source flag to at least the same number of databases that Database Migration Service is going to migrate (which is all of the databases under the source instance), plus the number of max_worker_processes
already used on your instance. If you plan to use adjusted data dump parallelism settings, make sure to increase the number of worker processes and verify your configuration by running the migration job test when you create the migration job.
The default value for this flag is 8.
Set the wal_sender_timeout
parameter to 0
:
ALTERSYSTEMSETwal_sender_timeout=0;
The value 0
disables the timeout mechanism that terminates inactive replication connections.
If you're migrating from a PostgreSQL version earlier than 9.6, then the replication delay metric isn't available by default. The following alternatives allow you to track this metric to ensure minimal downtime when you promote the database:
Option 1: Enable Database Migration Service to track the replication delay by granting access to a specific query. Using a user with the SUPERUSER
privilege, perform the following:
Define the following function to allow Database Migration Service to query for the replication delay.
CREATEORREPLACEFUNCTIONpg_stat_replication_user() RETURNSTABLE( pidinteger, usesysidoid, usernamename, application_nametext, client_addrinet, client_hostnametext, client_portinteger, backend_starttimestampwithtimezone, backend_xminxid, statetext, sent_locationpg_lsn, write_locationpg_lsn, flush_locationpg_lsn, replay_locationpg_lsn, sync_priorityinteger, sync_statetext ) LANGUAGESQL SECURITYDEFINER AS$$SELECT* FROMpg_catalog.pg_stat_replication;$$;
Grant the EXECUTE
permission to the USER by running the following commands:
REVOKE EXECUTE ON FUNCTION pg_stat_replication_user() FROM public;
GRANT EXECUTE ON FUNCTION pg_stat_replication_user() to {replication_user};
Option 2: Grant the SUPERUSER
privilege directly to the USER used to connect to the source instance. This will allow Database Migration Service to read the replication delay directly.
Option 3: Track the replication delay independently by using the following query:
SELECTcurrent_timestamp,application_name, pg_xlog_location_diff(pg_current_xlog_location(),pg_stat_replication.sent_location)ASsent_location_lag, pg_xlog_location_diff(pg_current_xlog_location(),pg_stat_replication.write_location)ASwrite_location_lag, pg_xlog_location_diff(pg_current_xlog_location(),pg_stat_replication.flush_location)ASflush_location_lag, pg_xlog_location_diff(pg_current_xlog_location(),pg_stat_replication.replay_location)ASreplay_location_lag FROMpg_stat_replication WHEREapplication_namelike'cloudsql%';
In this option, Database Migration Service won't reflect the replication delay metric in the graphs or API responses.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-04-17 UTC.