Using a PostgreSQL database as an AWS DMS source
You can migrate data from one or many PostgreSQL databases using AWS DMS. With a PostgreSQL database as a source, you can migrate data to either another PostgreSQL database or one of the other supported databases.
For information about versions of PostgreSQL that AWS DMS supports as a source, see Sources for AWS DMS.
AWS DMS supports PostgreSQL for these types of databases:
-
On-premises databases
-
Databases on an Amazon EC2 instance
-
Databases on an Amazon RDS DB instance
-
Databases on an DB instance based on Amazon Aurora PostgreSQL-Compatible Edition
-
Databases on an DB instance based on Amazon Aurora PostgreSQL-Compatible Serverless Edition
Note
DMS supports Amazon Aurora PostgreSQL—Serverless V1 as a source for Full load only. But you can use Amazon Aurora PostgreSQL—Serverless V2 as a source for Full load, Full load + CDC, and CDC only tasks.
You can use Secure Socket Layers (SSL) to encrypt connections between your PostgreSQL endpoint and the replication instance. For more information on using SSL with a PostgreSQL endpoint, see Using SSL with AWS Database Migration Service.
As an additional security requirement when using PostgreSQL as a source, the user account specified must be a registered user in the PostgreSQL database.
To configure a PostgreSQL database as an AWS DMS source endpoint, do the following:
-
Create a PostgreSQL user with appropriate permissions to provide AWS DMS access to your PostgreSQL source database.
Note
-
If your PostgreSQL source database is self-managed, see Working with self-managed PostgreSQL databases as a source in AWS DMS for more information.
-
If your PostgreSQL source database is managed by Amazon RDS, see Working with AWS-managed PostgreSQL databases as a DMS source for more information.
-
-
Create a PostgreSQL source endpoint that conforms with your chosen PostgreSQL database configuration.
-
Create a task or set of tasks to migrate your tables.
To create a full-load-only task, no further endpoint configuration is needed.
Before you create a task for change data capture (a CDC-only or full-load and CDC task), see Enabling CDC using a self-managed PostgreSQL database as a AWS DMS source or Enabling CDC with an AWS-managed PostgreSQL DB instance with AWS DMS.
Topics
Working with self-managed PostgreSQL databases as a source in AWS DMS
Working with AWS-managed PostgreSQL databases as a DMS source
Enabling change data capture (CDC) using logical replication
Using native CDC start points to set up a CDC load of a PostgreSQL source
Migrating from Babelfish for Amazon Aurora PostgreSQL using AWS DMS
Removing AWS DMS artifacts from a PostgreSQL source database
Additional configuration settings when using a PostgreSQL database as a DMS source
Endpoint settings and Extra Connection Attributes (ECAs) when using PostgreSQL as a DMS source
Working with self-managed PostgreSQL databases as a source in AWS DMS
With a self-managed PostgreSQL database as a source, you can migrate data to either another PostgreSQL database, or one of the other target databases supported by AWS DMS. The database source can be an on-premises database or a self-managed engine running on an Amazon EC2 instance. You can use a DB instance for both full-load tasks and change data capture (CDC) tasks.
Prerequisites to using a self-managed PostgreSQL database as an AWS DMS source
Before migrating data from a self-managed PostgreSQL source database, do the following:
-
Make sure that you use a PostgreSQL database that is version 9.4.x or higher.
-
For full-load plus CDC tasks or CDC-only tasks, grant superuser permissions for the user account specified for the PostgreSQL source database. The user account needs superuser permissions to access replication-specific functions in the source. DMS user account needs SELECT permissions on all columns to migrate tables successfully. In the case of missing permissions on columns, DMS creates target table using regular DMS data type mappings which leads to metadata differences and task failures.
-
Add the IP address of the AWS DMS replication server to the
pg_hba.confconfiguration file and enable replication and socket connections. An example follows.# Replication Instance host all all 12.3.4.56/32 md5 # Allow replication connections from localhost, by a user with the # replication privilege. host replication dms 12.3.4.56/32 md5PostgreSQL's
pg_hba.confconfiguration file controls client authentication. (HBA stands for host-based authentication.) The file is traditionally stored in the database cluster's data directory. -
If you're configuring a database as a source for logical replication using AWS DMS see Enabling CDC using a self-managed PostgreSQL database as a AWS DMS source
Note
Some AWS DMS transactions are idle for some time before the DMS engine uses
them again. By using the parameter
idle_in_transaction_session_timeout in PostgreSQL versions
9.6 and higher, you can cause idle transactions to time out and fail.
Don't end idle transactions when you use AWS DMS.
Enabling CDC using a self-managed PostgreSQL database as a AWS DMS source
AWS DMS supports change data capture (CDC) using logical replication. To enable
logical replication of a self-managed PostgreSQL source database, set the
following parameters and values in the postgresql.conf
configuration file:
-
Set
wal_level = logical. -
Set
max_replication_slotsto a value greater than 1.Set the
max_replication_slotsvalue according to the number of tasks that you want to run. For example, to run five tasks you set a minimum of five slots. Slots open automatically as soon as a task starts and remain open even when the task is no longer running. Make sure to manually delete open slots. Note that DMS automatically drops replication slots when the task is deleted, if DMS created the slot. -
Set
max_wal_sendersto a value greater than 1.The
max_wal_sendersparameter sets the number of concurrent tasks that can run. -
The
wal_sender_timeoutparameter ends replication connections that are inactive longer than the specified number of milliseconds. The default for an on-premises PostgreSQL database is 60000 milliseconds (60 seconds). Setting the value to 0 (zero) disables the timeout mechanism, and is a valid setting for DMS.When setting
wal_sender_timeoutto a non-zero value, a DMS task with CDC requires a minimum of 10000 milliseconds (10 seconds), and fails if the value is less than 10000. Keep the value less than 5 minutes to avoid causing a delay during a Multi-AZ failover of a DMS replication instance.
Some parameters are static, and you can only set them at server start. Any
changes to their entries in the configuration file (for a self-managed database)
or DB parameter group (for an RDS for PostgreSQL database) are ignored until the
server is restarted. For more information, see the PostgreSQL
documentation
For more information about enabling CDC, see Enabling change data capture (CDC) using logical replication.
Working with AWS-managed PostgreSQL databases as a DMS source
You can use an AWS-managed PostgreSQL DB instance as a source for AWS DMS. You can perform both full-load tasks and change data capture (CDC) tasks using an AWS-managed PostgreSQL source.
Prerequisites for using an AWS-managed PostgreSQL database as a DMS source
Before migrating data from an AWS-managed PostgreSQL source database, do the following:
-
We recommend that you use an AWS user account with the minimum required permissions for the PostgreSQL DB instance as the user account for the PostgreSQL source endpoint for AWS DMS. Using the master account is not recommended. The account must have the
rds_superuserrole and therds_replicationrole. Therds_replicationrole grants permissions to manage logical slots and to stream data using logical slots.Make sure to create several objects from the master user account for the account that you use. For information about creating these, see Migrating an Amazon RDS for PostgreSQL database without using the master user account.
-
If your source database is in a virtual private cloud (VPC), choose the VPC security group that provides access to the DB instance where the database resides. This is needed for the DMS replication instance to connect successfully to the source DB instance. When the database and DMS replication instance are in same VPC, add the appropriate security group to its own inbound rules.
Note
Some AWS DMS transactions are idle for some time before the DMS engine uses
them again. By using the parameter
idle_in_transaction_session_timeout in PostgreSQL versions
9.6 and higher, you can cause idle transactions to time out and fail.
Don't end idle transactions when you use AWS DMS.
Enabling CDC with an AWS-managed PostgreSQL DB instance with AWS DMS
AWS DMS supports CDC on Amazon RDS PostgreSQL databases when the DB instance is configured to use logical replication. The following table summarizes the logical replication compatibility of each AWS-managed PostgreSQL version.
|
PostgreSQL version |
AWS DMS full load support |
AWS DMS CDC support |
|---|---|---|
|
Aurora PostgreSQL version 2.1 with PostgreSQL 10.5 compatibility (or lower) |
Yes |
No |
|
Aurora PostgreSQL version 2.2 with PostgreSQL 10.6 compatibility (or higher) |
Yes |
Yes |
|
RDS for PostgreSQL with PostgreSQL 10.21 compatibility (or higher) |
Yes |
Yes |
To enable logical replication for an RDS PostgreSQL DB instance
-
Use the AWS master user account for the PostgreSQL DB instance as the user account for the PostgreSQL source endpoint. The master user account has the required roles that allow it to set up CDC.
If you use an account other than the master user account, make sure to create several objects from the master account for the account that you use. For more information, see Migrating an Amazon RDS for PostgreSQL database without using the master user account.
-
Set the
rds.logical_replicationparameter in your DB CLUSTER parameter group to 1. This static parameter requires a reboot of the DB instance to take effect. As part of applying this parameter, AWS DMS sets thewal_level,max_wal_senders,max_replication_slots, andmax_connectionsparameters. These parameter changes can increase write ahead log (WAL) generation, so only setrds.logical_replicationwhen you use logical replication slots. -
The
wal_sender_timeoutparameter ends replication connections that are inactive longer than the specified number of milliseconds. The default for an AWS-managed PostgreSQL database is 30000 milliseconds (30 seconds). Setting the value to 0 (zero) disables the timeout mechanism, and is a valid setting for DMS.When setting
wal_sender_timeoutto a non-zero value, a DMS task with CDC requires a minimum of 10000 milliseconds (10 seconds), and fails if the value is between 0 and 10000. Keep the value less than 5 minutes to avoid causing a delay during a Multi-AZ failover of a DMS replication instance. -
Ensure the value of the
max_worker_processesparameter in your DB Cluster Parameter Group is equal to, or higher than the total combined values ofmax_logical_replication_workers,autovacuum_max_workers, andmax_parallel_workers. A high number of background worker processes might impact application workloads on small instances. So, monitor performance of your database if you setmax_worker_processeshigher than the default value. -
When using Aurora PostgreSQL as a source with CDC, set
synchronous_committoON.
To use PostgreSQL MultiAZ DB Cluster Read Replica for CDC (ongoing replication)
-
Set the
rds.logical_replicationandsync_replication_slotsparameters in your DB CLUSTER parameter group to 1. This static parameters require a reboot of the DB instance to take effect. -
Run the following command to create the
awsdms_ddl_audittable on Writer and to replace theobjects_schemawith the name of the schema to use:CREATE TABLE objects_schema.awsdms_ddl_audit ( c_key bigserial primary key, c_time timestamp, -- Informational c_user varchar(64), -- Informational: current_user c_txn varchar(16), -- Informational: current transaction c_tag varchar(24), -- Either 'CREATE TABLE' or 'ALTER TABLE' or 'DROP TABLE' c_oid integer, -- For future use - TG_OBJECTID c_name varchar(64), -- For future use - TG_OBJECTNAME c_schema varchar(64), -- For future use - TG_SCHEMANAME. For now - holds current_schema c_ddlqry text -- The DDL query associated with the current DDL event ); -
Run the following command to create the
awsdms_intercept_ddlfunction and to replace theobjects_schemawith the name of the schema to use:CREATE OR REPLACE FUNCTION objects_schema.awsdms_intercept_ddl() RETURNS event_trigger LANGUAGE plpgsql SECURITY DEFINER AS $$ declare _qry text; BEGIN if (tg_tag='CREATE TABLE' or tg_tag='ALTER TABLE' or tg_tag='DROP TABLE' or tg_tag = 'CREATE TABLE AS') then SELECT current_query() into _qry; insert into objects_schema.awsdms_ddl_audit values ( default,current_timestamp,current_user,cast(TXID_CURRENT()as varchar(16)),tg_tag,0,'',current_schema,_qry ); delete from objects_schema.awsdms_ddl_audit; end if; END; $$; -
Run the following command to create the
awsdms_intercept_ddlevent trigger:CREATE EVENT TRIGGER awsdms_intercept_ddl ON ddl_command_end EXECUTE PROCEDURE objects_schema.awsdms_intercept_ddl();Ensure that all the users and roles that access these events have the necessary DDL permissions. For example:
grant all on public.awsdms_ddl_audit to public; grant all on public.awsdms_ddl_audit_c_key_seq to public; -
Create replication slot on Writer:
SELECT * FROM pg_create_logical_replication_slot('dms_read_replica_slot', 'test_decoding', false, true); -
Ensure the replication slot is available on Reader:
select * from pg_catalog.pg_replication_slots where slot_name = 'dms_read_replica_slot'; slot_name |plugin |slot_type|datoid|database|temporary|active|active_pid|xmin|catalog_xmin|restart_lsn|confirmed_flush_lsn|wal_status|safe_wal_size|two_phase|inactive_since |conflicting|invalidation_reason|failover|synced| ---------------------+-------------+---------+------+--------+---------+------+----------+----+------------+-----------+-------------------+----------+-------------+---------+-----------------------------+-----------+-------------------+--------+------+ dms_read_replica_slot|test_decoding|logical | 5|postgres|false |false | | |3559 |0/180011B8 |0/180011F0 |reserved | |true |2025-02-10 15:45:04.083 +0100|false | |false |false | -
Create DMS source endpoint for Read Replica and set logical replication slot name via the Extra Connection Attribute:
slotName=dms_read_replica_slot; -
Create and start the CDC/FL+CDC task.
Note
For CDC/FL+CDC migrations DMS considers task start time as a CDC start position. All older LSNs from replication slot are ignored.
Migrating an Amazon RDS for PostgreSQL database without using the master user account
In some cases, you might not use the master user account for the Amazon RDS PostgreSQL DB instance that you are using as a source. In these cases, you create several objects to capture data definition language (DDL) events. You create these objects in the account other than the master account and then create a trigger in the master user account.
Note
If you set the CaptureDdls endpoint setting to
false on the source endpoint, you don't have to
create the following table and trigger on the source database.
Use the following procedure to create these objects.
To create objects
-
Choose the schema where the objects are to be created. The default schema is
public. Ensure that the schema exists and is accessible by theaccount.OtherThanMaster -
Log in to the PostgreSQL DB instance using the user account other than the master account, here the
account.OtherThanMaster -
Create the table
awsdms_ddl_auditby running the following command, replacingin the following code with the name of the schema to use.objects_schemaCREATE TABLEobjects_schema.awsdms_ddl_audit ( c_key bigserial primary key, c_time timestamp, -- Informational c_user varchar(64), -- Informational: current_user c_txn varchar(16), -- Informational: current transaction c_tag varchar(24), -- Either 'CREATE TABLE' or 'ALTER TABLE' or 'DROP TABLE' c_oid integer, -- For future use - TG_OBJECTID c_name varchar(64), -- For future use - TG_OBJECTNAME c_schema varchar(64), -- For future use - TG_SCHEMANAME. For now - holds current_schema c_ddlqry text -- The DDL query associated with the current DDL event ); -
Create the function
awsdms_intercept_ddlby running the following command, replacingin the code following with the name of the schema to use.objects_schemaCREATE OR REPLACE FUNCTIONobjects_schema.awsdms_intercept_ddl() RETURNS event_trigger LANGUAGE plpgsql SECURITY DEFINER AS $$ declare _qry text; BEGIN if (tg_tag='CREATE TABLE' or tg_tag='ALTER TABLE' or tg_tag='DROP TABLE' or tg_tag = 'CREATE TABLE AS') then SELECT current_query() into _qry; insert intoobjects_schema.awsdms_ddl_audit values ( default,current_timestamp,current_user,cast(TXID_CURRENT()as varchar(16)),tg_tag,0,'',current_schema,_qry ); delete fromobjects_schema.awsdms_ddl_audit; end if; END; $$; -
Log out of the
account and log in with an account that has theOtherThanMasterrds_superuserrole assigned to it. -
Create the event trigger
awsdms_intercept_ddlby running the following command.CREATE EVENT TRIGGER awsdms_intercept_ddl ON ddl_command_end EXECUTE PROCEDUREobjects_schema.awsdms_intercept_ddl(); -
Make sure that all users and roles that access these events have the necessary DDL permissions. For example:
grant all on public.awsdms_ddl_audit to public; grant all on public.awsdms_ddl_audit_c_key_seq to public;
When you have completed the procedure preceding, you can create the AWS DMS
source endpoint using the account.OtherThanMaster
Note
These events are triggered by CREATE TABLE, ALTER
TABLE, and DROP TABLE statements.
Enabling change data capture (CDC) using logical replication
You can use PostgreSQL's native logical replication feature to enable change data capture (CDC) during database migration for PostgreSQL sources. You can use this feature with a self-managed PostgreSQL and also an Amazon RDS for PostgreSQL SQL DB instance. This approach reduces downtime and help ensure that the target database is in sync with the source PostgreSQL database.
AWS DMS supports CDC for PostgreSQL tables with primary keys. If a table does not have a primary key, the write-ahead logs (WAL) don't include a before image of the database row. In this case, DMS can't update the table. Here, you can use additional configuration settings and use table replica identity as a workaround. However, this approach can generate extra logs. We recommend that you use table replica identity as a workaround only after careful testing. For more information, see Additional configuration settings when using a PostgreSQL database as a DMS source.
Note
REPLICA IDENTITY FULL is supported with a logical decoding plugin, but
isn't supported with a pglogical plugin. For more information, see pglogical documentation
For full load and CDC and CDC only tasks, AWS DMS uses logical replication slots to retain WAL logs for replication until the logs are decoded. On restart (not resume) for a full load and CDC task or a CDC task, the replication slot gets recreated.
Note
For logical decoding, DMS uses either test_decoding or pglogical plugin. If
the pglogical plugin is available on a source PostgreSQL database, DMS creates a
replication slot using pglogical, otherwise a test_decoding plugin is used. For more
information about the test_decoding plugin, see PostgreSQL
Documentation
If the database parameter max_slot_wal_keep_size is set to a non default value,
and the restart_lsn of a replication slot falls behind the current LSN by more than
this size, the DMS task fails due to removal of required WAL files.
Configuring the pglogical plugin
Implemented as a PostgreSQL extension, the pglogical plugin is a logical replication system and model for selective data replication. The following table identifies source PostgreSQL database versions that support the pglogical plugin.
|
PostgreSQL source |
Supports pglogical |
|---|---|
|
Self-managed PostgreSQL 9.4 or higher |
Yes |
|
Amazon RDS PostgreSQL 9.5 or lower |
No |
|
Amazon RDS PostgreSQL 9.6 or higher |
Yes |
|
Aurora PostgreSQL 1.x till 2.5.x |
No |
|
Aurora PostgreSQL 2.6.x or higher |
Yes |
|
Aurora PostgreSQL 3.3.x or higher |
Yes |
Before configuring pglogical for use with AWS DMS, first enable logical replication for change data capture (CDC) on your PostgreSQL source database.
-
For information about enabling logical replication for CDC on self-managed PostgreSQL source databases, see Enabling CDC using a self-managed PostgreSQL database as a AWS DMS source
-
For information about enabling logical replication for CDC on AWS-managed PostgreSQL source databases, see Enabling CDC with an AWS-managed PostgreSQL DB instance with AWS DMS.
After logical replication is enabled on your PostgreSQL source database, use the following steps to configure pglogical for use with DMS.
To use the pglogical plugin for logical replication on a PostgreSQL source database with AWS DMS
-
Create a pglogical extension on your source PostgreSQL database:
-
Set the correct parameter:
-
For self-managed PostgreSQL databases, set the database parameter
shared_preload_libraries= 'pglogical'. -
For PostgreSQL on Amazon RDS and Amazon Aurora PostgreSQL-Compatible Edition databases, set the parameter
shared_preload_librariestopglogicalin the same RDS parameter group.
-
-
Restart your PostgreSQL source database.
-
On the PostgreSQL database, run the command,
create extension pglogical;
-
-
Run the following command to verify that pglogical installed successfully:
select * FROM pg_catalog.pg_extension
You can now create a AWS DMS task that performs change data capture for your PostgreSQL source database endpoint.
Note
If you don't enable pglogical on your PostgreSQL source database,
AWS DMS uses the test_decoding plugin by default. When pglogical
is enabled for logical decoding, AWS DMS uses pglogical by default. But you
can set the extra connection attribute, PluginName to use the
test_decoding plugin instead.
Using native CDC start points to set up a CDC load of a PostgreSQL source
To enable native CDC start points with PostgreSQL as a source, set the
slotName extra connection attribute to the name of an existing
logical replication slot when you create the endpoint. This logical replication slot
holds ongoing changes from the time of endpoint creation, so it supports replication
from a previous point in time.
PostgreSQL writes the database changes to WAL files that are discarded only after AWS DMS successfully reads changes from the logical replication slot. Using logical replication slots can protect logged changes from being deleted before they are consumed by the replication engine.
However, depending on rate of change and consumption, changes being held in a
logical replication slot can cause elevated disk usage. We recommend that you set
space usage alarms in the source PostgreSQL instance when you use logical
replication slots. For more information on setting the slotName extra
connection attribute, see Endpoint settings and Extra Connection Attributes (ECAs) when using PostgreSQL as a DMS source.
The following procedure walks through this approach in more detail.
To use a native CDC start point to set up a CDC load of a PostgreSQL source endpoint
-
Identify the logical replication slot used by an earlier replication task (a parent task) that you want to use as a start point. Then query the
pg_replication_slotsview on your source database to make sure that this slot does not have any active connections. If it does, resolve and close them before proceeding.For the following steps, assume that your logical replication slot is
abc1d2efghijk_34567890_z0yx98w7_6v54_32ut_1srq_1a2b34c5d67ef. -
Create a new source endpoint that includes the following extra connection attribute setting.
slotName=abc1d2efghijk_34567890_z0yx98w7_6v54_32ut_1srq_1a2b34c5d67ef; -
Create a new CDC-only task using the console, AWS CLI or AWS DMS API. For example, using the CLI you might run the following
create-replication-taskcommand.aws dms create-replication-task --replication-task-identifier postgresql-slot-name-test --source-endpoint-arn arn:aws:dms:us-west-2:012345678901:endpoint:ABCD1EFGHIJK2LMNOPQRST3UV4 --target-endpoint-arn arn:aws:dms:us-west-2:012345678901:endpoint:ZYX9WVUTSRQONM8LKJIHGF7ED6 --replication-instance-arn arn:aws:dms:us-west-2:012345678901:rep:AAAAAAAAAAA5BB4CCC3DDDD2EE --migration-type cdc --table-mappings "file://mappings.json" --cdc-start-position "4AF/B00000D0" --replication-task-settings "file://task-pg.json"In the preceding command, the following options are set:
-
The
source-endpoint-arnoption is set to the new value that you created in step 2. -
The
replication-instance-arnoption is set to the same value as for the parent task from step 1. -
The
table-mappingsandreplication-task-settingsoptions are set to the same values as for the parent task from step 1. -
The
cdc-start-positionoption is set to a start position value. To find this start position, either query thepg_replication_slotsview on your source database or view the console details for the parent task in step 1. For more information, see Determining a CDC native start point.
To enable custom CDC start mode when creating a new CDC-only task using the AWS DMS console, do the following:
In the Task settings section, for CDC start mode for source transactions, choose Enable custom CDC start mode.
For Custom CDC start point for source transactions, choose Specify a log sequence number. Specify the system change number or choose Specify a recovery checkpoint, and provide a Recovery checkpoint.
When this CDC task runs, AWS DMS raises an error if the specified logical replication slot does not exist. It also raises an error if the task isn't created with a valid setting for
cdc-start-position. -
When using native CDC start points with the pglogical plugin and you want to use a new replication slot, complete the setup steps following before creating a CDC task.
To use a new replication slot not previously created as part of another DMS task
-
Create a replication slot, as shown following:
SELECT * FROM pg_create_logical_replication_slot('replication_slot_name', 'pglogical'); -
After the database creates the replication slot, get and note the restart_lsn and confirmed_flush_lsn values for the slot:
select * from pg_replication_slots where slot_name like 'replication_slot_name';Note that the Native CDC Start position for a CDC task created after the replication slot can't be older than the confirmed_flush_lsn value.
For information about the restart_lsn and confirmed_flush_lsn values, see pg_replication_slots
-
Create a pglogical node.
SELECT pglogical.create_node(node_name := 'node_name', dsn := 'your_dsn_name'); -
Create two replication sets using the
pglogical.create_replication_setfunction. The first replication set tracks updates and deletes for tables that have primary keys. The second replication set tracks only inserts, and has the same name as the first replication set, with the added prefix 'i'.SELECT pglogical.create_replication_set('replication_slot_name', false, true, true, false); SELECT pglogical.create_replication_set('ireplication_slot_name', true, false, false, true); -
Add a table to the replication set.
SELECT pglogical.replication_set_add_table('replication_slot_name', 'schemaname.tablename', true); SELECT pglogical.replication_set_add_table('ireplication_slot_name', 'schemaname.tablename', true); -
Set the extra connection attribute (ECA) following when you create your source endpoint.
PluginName=PGLOGICAL;slotName=slot_name;
You can now create a CDC only task with a PostgreSQL native start point using the
new replication slot. For more information about the pglogical plugin, see the
pglogical 3.7 documentation
Migrating from PostgreSQL to PostgreSQL using AWS DMS
When you migrate from a database engine other than PostgreSQL to a PostgreSQL database, AWS DMS is almost always the best migration tool to use. But when you are migrating from a PostgreSQL database to a PostgreSQL database, PostgreSQL tools can be more effective.
Using PostgreSQL native tools to migrate data
We recommend that you use PostgreSQL database migration tools such as
pg_dump under the following conditions:
-
You have a homogeneous migration, where you are migrating from a source PostgreSQL database to a target PostgreSQL database.
-
You are migrating an entire database.
-
The native tools allow you to migrate your data with minimal downtime.
The pg_dump utility uses the COPY command to create a schema and data dump of
a PostgreSQL database. The dump script generated by pg_dump loads data into a
database with the same name and recreates the tables, indexes, and foreign keys.
To restore the data to a database with a different name, use the
pg_restore command and the -d parameter.
If you are migrating data from a PostgreSQL source database running on EC2 to an Amazon RDS for PostgreSQL target, you can use the pglogical plugin.
For more information about importing a PostgreSQL database into Amazon RDS for PostgreSQL or Amazon Aurora PostgreSQL-Compatible Edition, see https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Procedural.Importing.html.
Using DMS to migrate data from PostgreSQL to PostgreSQL
AWS DMS can migrate data, for example, from a source PostgreSQL database that is on premises to a target Amazon RDS for PostgreSQL or Aurora PostgreSQL instance. Core or basic PostgreSQL data types most often migrate successfully.
Note
When replicating partitioned tables from a PostgreSQL source to PostgreSQL target, you don’t need to mention the parent table as part of the selection criteria in the DMS task. Mentioning the parent table causes data to be duplicated in child tables on the target, possibly causing a PK violation. By selecting child tables alone in the table mapping selection criteria, the parent table is automatically populated.
Data types that are supported on the source database but aren't supported on the target might not migrate successfully. AWS DMS streams some data types as strings if the data type is unknown. Some data types, such as XML and JSON, can successfully migrate as small files but can fail if they are large documents.
When performing data type migration, be aware of the following:
-
In some cases, the PostgreSQL NUMERIC(p,s) data type does not specify any precision and scale. For DMS versions 3.4.2 and earlier, DMS uses a precision of 28 and a scale of 6 by default, NUMERIC(28,6). For example, the value 0.611111104488373 from the source is converted to 0.611111 on the PostgreSQL target.
-
A table with an ARRAY data type must have a primary key. A table with an ARRAY data type missing a primary key gets suspended during full load.
The following table shows source PostgreSQL data types and whether they can be migrated successfully.
| Data type | Migrates successfully | Partially migrates | does not migrate | Comments |
|---|---|---|---|---|
| INTEGER | X | |||
| SMALLINT | X | |||
| BIGINT | X | |||
| NUMERIC/DECIMAL(p,s) | X | Where 0<p<39 and 0<s | ||
| NUMERIC/DECIMAL | X | Where p>38 or p=s=0 | ||
| REAL | X | |||
| DOUBLE | X | |||
| SMALLSERIAL | X | |||
| SERIAL | X | |||
| BIGSERIAL | X | |||
| MONEY | X | |||
| CHAR | X | Without specified precision | ||
| CHAR(n) | X | |||
| VARCHAR | X | Without specified precision | ||
| VARCHAR(n) | X | |||
| TEXT | X | |||
| BYTEA | X | |||
| TIMESTAMP | X | Positive and negative infinity values are truncated to '9999-12-31 23:59:59' and '4713-01-01 00:00:00 BC' respectively. | ||
| TIMESTAMP WITH TIME ZONE | X | The time zone offset is always normalized to UTC. The original offset literal is not retained. | ||
| DATE | X | |||
| TIME | X | |||
| TIME WITH TIME ZONE | X | |||
| INTERVAL | X | |||
| BOOLEAN | X | |||
| ENUM |