This page has instructions for setting up AWS DMS to migrate data to CockroachDB from an existing, publicly-hosted database containing application data such as MySQL, Oracle, or PostgreSQL.
For a detailed tutorial about using AWS DMS and information about specific migration tasks, see the AWS DMS documentation site.
We have tested AWS DMS with CockroachDB as a target enough to claim preview-level support. If you encounter problems in CockroachDB, please open an issue with details to help us make progress toward full support.
For any issues related to AWS DMS, aside from its interaction with CockroachDB as a migration target, please reach out to AWS Support.
Using CockroachDB as a source database within AWS DMS is unsupported.
Before you begin
Ensure the following items are completed prior to starting this tutorial:
- Configure a source endpoint in AWS pointing to your source database.
- Configure a replication instance in AWS.
- Ensure you have a secure, publicly available CockroachDB cluster running v22.1 GA or later.
As of publishing, AWS DMS supports migrations from these relational databases (for a more accurate view of what's currently supported, see Sources for AWS DMS):
- Amazon Aurora
- Amazon DocumentDB (with MongoDB compatibility)
- Amazon S3
- IBM Db2 (LUW edition only)
- MariaDB
- Microsoft Azure SQL
- Microsoft SQL Server
- MongoDB
- MySQL
- Oracle
- PostgreSQL
- SAP ASE
Step 1. Create a target endpoint pointing to CockroachDB
- In the AWS Console, open AWS DMS.
- Open Endpoints in the sidebar. A list of endpoints will display, if any exist.
- In the top-right portion of the window, select Create endpoint.
- In the Endpoint type section, select Target endpoint.
- Supply an Endpoint identifier to identify the new target endpoint.
- For the Target engine dropdown, select PostgreSQL.
- For the Access to endpoint database radio button, select the Provide access information manually.
- Enter the Server name, Port, User name, Password, and Database name of your CockroachDB cluster.
Note:To connect to a CockroachDB Serverless cluster, use
{routing-id}.{database}
for the Database name. For more information, see Connect to a CockroachDB Serverless Cluster. - You can test the connection if needed under Test endpoint connection (optional).
- Create the endpoint by selecting Create endpoint.
Step 2. Create a database migration task
A database migration task, also known as a replication task, controls what data are moved from the source database to the target database.
Step 2.1. Task configuration
- While in AWS DMS, select Database migration tasks in the sidebar. A list of database migration tasks will display, if any exist.
- In the top-right portion of the window, select Create task.
- Supply a Task identifier to identify the replication task.
- Select the Replication instance and Source database endpoint you created prior to starting this tutorial.
- For the Target database endpoint dropdown, select the CockroachDB endpoint created in the previous section.
- Select the appropriate Migration type based on your needs.
Step 2.2. Task settings
- For the Editing mode radio button, keep Wizard selected.
- For the Target table preparation mode, select either Truncate or Do nothing.
- Manually create all schema objects in the target CockroachDB cluster. This step is required in order for the migration to populate data successfully.
Note:All tables must have a primary key associated with them. For more information, see Primary Key Constraint.
Drop tables on target is unsupported at this time.
When specifying a range of tables, you must ensure the following before data migration can successfully occur:
- The column names within each table being migrated from the source database to CockroachDB are identical.
- The column types for the columns within each table being migrated from the source database to CockroachDB are compatible.
Step 2.3. Table mappings
- For the Editing mode radio button, keep Wizard selected.
- Select Add new selection rule.
- In the Schema drop down, select Enter a schema.
- Supply the appropriate Source name (schema name), Table name, and Action.
Use %
as an example of a wildcard for all schemas in a PostgreSQL database. However, in MySQL, using %
as a schema name imports all the databases, including the metadata/system ones, as MySQL treats schemas and databases as the same.
Step 3. Verify the migration
Data should now be moving from source to target. You can analyze the Table Statistics page for information about replication.
- In AWS DMS, open Database migration tasks in the sidebar.
- Select the task you created in Step 2.
- Select Table statistics below the Summary section.
If your migration failed for some reason, you can check the checkbox next to the table(s) you wish to re-migrate and select Reload table data.
Optional configurations
AWS PrivateLink
If using CockroachDB Dedicated, you can enable AWS PrivateLink to securely connect your AWS application with your CockroachDB Dedicated cluster using a private endpoint. To configure AWS PrivateLink with CockroachDB Dedicated, see Network Authorization.
CloudWatch logs
You can Enable CloudWatch logs for extra insight about the replication. To enable CloudWatch logs:
- Edit the existing replication task.
- Under Task settings, select Enable CloudWatch logs. From here, you can specify logging levels for each event type:
BatchApplyEnabled
The BatchApplyEnabled
setting can improve replication performance and is recommended for larger workloads.
- Open the existing database migration task.
- Choose your task, and then choose Modify.
- From the Task settings section, switch the Editing mode from Wizard to JSON editor. Locate the
BatchApplyEnabled
setting and change its value totrue
. Information about theBatchApplyEnabled
setting can be found here.
Known limitations
- When using Truncate or Do nothing as a target table preparation mode, you cannot include tables with any hidden columns. You can verify which tables contain hidden columns by executing the following SQL query:
> SELECT table_catalog, table_schema, table_name, column_name FROM information_schema.columns WHERE is_hidden = 'YES';
- Drop tables on target is currently not supported and will error on import.
Troubleshooting common issues
Run the following query from within the target CockroachDB cluster to identify common problems with any tables that may be migrated:
> WITH
invalid_columns
AS (
SELECT
'Table '
|| table_schema
|| '.'
|| table_name
|| ' has column '
|| column_name
|| ' which is hidden. Either drop the column or mark it as not hidden for DMS to work.'
AS fix_me
FROM
information_schema.columns
WHERE
is_hidden = 'YES'
AND table_name NOT LIKE 'awsdms_%'
),
invalid_version
AS (
SELECT
'This cluster is on a version of CockroachDB which does not support AWS DMS. CockroachDB v21.2.13+ or v22.1+ is required.'
AS fix_me
WHERE
split_part(
substr(
substring(
version(),
e'v\\d+\\.\\d+.\\d+'
),
2
),
'.',
1
)::INT8
< 22
AND NOT
(
split_part(
substr(
substring(
version(),
e'v\\d+\\.\\d+.\\d+'
),
2
),
'.',
1
)::INT8
= 21
AND split_part(
substr(
substring(
version(),
e'v\\d+\\.\\d+.\\d+'
),
2
),
'.',
2
)::INT8
= 2
AND split_part(
substr(
substring(
version(),
e'v\\d+\\.\\d+.\\d+'
),
2
),
'.',
3
)::INT8
>= 13
)
),
has_no_pk
AS (
SELECT
'Table '
|| a.table_schema
|| '.'
|| a.table_name
|| ' has column '
|| a.column_name
|| ' has no explicit PRIMARY KEY. Ensure you are not using target mode "Drop tables on target" and that this table has a PRIMARY KEY.'
AS fix_me
FROM
information_schema.key_column_usage AS a
JOIN information_schema.columns AS b ON
a.table_schema = b.table_schema
AND a.table_name = b.table_name
AND a.column_name = b.column_name
WHERE
b.is_hidden = 'YES'
AND a.column_name = 'rowid'
AND a.table_name NOT LIKE 'awsdms_%'
)
SELECT fix_me FROM has_no_pk
UNION ALL SELECT fix_me FROM invalid_columns
UNION ALL SELECT fix_me FROM invalid_version;