This quickstart shows you how to use Database Migration Service to migrate data to AlloyDB for PostgreSQL. The resources created in this quickstart typically cost less than one dollar (USD), assuming you complete the steps, including the clean up, in a timely manner.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Database Migration Service API.
- Make sure that you have the Database Migration Admin role assigned to your user account.
Requirements
Database Migration Service offers a variety of source database options and connectivity methods. Different sources work better with some connectivity methods than with others. In this quickstart, we assume that you're using a standalone PostgreSQL database in an environment where you can configure your network to add an inbound firewall rule. The source database can be on-premises or in a cloud provider. Because we can't know the specifics of your environment, we can't provide detailed steps when it comes to your networking configuration.
In this quickstart, you'll select PostgreSQL for the Source database engine, AlloyDB for PostgreSQL for the Destination database engine and VPC peering as the networking method.
Create a connection profile
By creating a connection profile, you're creating a record that contains information about the source database. Database Migration Service uses the information in the connection profile to migrate data from your source database to the destination AlloyDB database instance.Go to the Database Migration Service Connection profiles page in the Google Cloud console.
Go to the Database Migration Service Connection Profiles Page
Click CREATE PROFILE.
Open the Database engine drop-down list and select the classification type of your source database.
The options are:
- A standalone PostgreSQL instance (PostgreSQL)
- An existing Cloud SQL for PostgreSQL instance (Cloud SQL for PostgreSQL)
- An Amazon RDS instance for PostgreSQL (Amazon RDS for PostgreSQL)
For this quickstart, select PostgreSQL.
- Supply the following information:
- In the Connection profile name field, enter a name for the connection profile for your source database, such as
My Connection Profile
. - Keep the auto-generated Connection profile ID.
- Enter Connectivity information:
- If you're replicating from a self-hosted database, then enter the Hostname or IP address (domain or IP) and Port to access the host. (The default PostgreSQL port is 5432.)
- If you're replicating from a Cloud SQL database, then select the Cloud SQL instance from the drop-down list.
- Enter a Username and Password to authenticate to your source instance.
- In the Connection profile name field, enter a name for the connection profile for your source database, such as
In the Connection profile region section of the page, select the region where you want to save the connection profile.
- Click CREATE.
Create a migration job
Database Migration Service uses migration jobs to migrate data from your source database instance to the destination AlloyDB database instance.Creating a migration job includes:
- Defining settings for the job
- Selecting the connection profile that you created for your source database (source connection profile)
- Defining settings for the destination AlloyDB database instance
- Setting up connectivity between the source and destination database instances
- Testing the migration job to ensure that the connection information you provided for the job is valid
Define settings for the migration job
Go to the Database Migration Service Migration jobs page in the Google Cloud console.
Click CREATE MIGRATION JOB.
In the Migration job name field, enter a name for the migration job, such as
My Migration Job
.Keep the auto-generated Migration job ID.
Open the Source database engine drop-down list and select the classification type of your source database. In this quickstart, select AlloyDB for PostgreSQL.
Select the Destination region where the destination instance is to be created.
Set the Migration job type to "Continuous" because you want ongoing changes in your source database to be migrated to the destination AlloyDB database instance.
Review the required prerequisites that are generated automatically to reflect how the environment must be prepared for a migration job. These prerequisites can include how to configure the source database and how to connect it to the destination AlloyDB database instance. It's best to complete these prerequisites at this step, but you can complete them at any time before you test the migration job or start it. For more information about these prerequisites, see Configure your source.
Click SAVE & CONTINUE.
Specify information about the source connection profile
Open the Select source connection profile drop-down list and select the connection profile that you created.
Click SAVE & CONTINUE.
Create a destination AlloyDB cluster
Clusters are the top-level resource in AlloyDB. To create a destination cluster:
- Choose a cluster type. Database Migration Service currently supports Highly available AlloyDB clusters. They can serve data from more than one zone in a region, with no read pools.
- Click CONTINUE.
- Configure your cluster:
- In the Cluster ID field, enter an ID for your cluster.
- In the Password field, enter a password for the default
postgres
user. You will need the password to log in to your database. - In the Network field, select a network path to define which resources are available when setting the migration connectivity. Clusters can only be configured with a private IP network path. If you plan to connect to the source database via VPC peering, select the VPC where it resides.
- Optionally, select an allocated IP range name to specify IP addresses your instance can connect with.
- Click CONTINUE.
- Configure your primary instance. A primary instance determines a cluster's compute capacity and supports read and write operations:
- In the Instance ID field, enter an ID for your primary instance.
- Select a machine type.
- Optional: Set flags for your instance. You can use flags to customize your instance. For information on supported flags, see AlloyDB documentation. For each flag:
- Click ADD FLAG.
- Select a flag from the New database flag list.
- Provide a value for the flag.
- Click DONE.
- Click SAVE & CONTINUE.
- Confirm your choice by clicking CREATE DESTINATION & CONTINUE.
- Wait for the creation of the destination instance to finish.
Set up connectivity
- Choose the networking method that you'd like to use to establish connectivity between the source and destination databases. For this quickstart, use the Connectivity method drop-down list to select VPC peering as the networking method. Review the VPC network of your source database. Click CONFIGURE & CONTINUE to complete the connection profile configuration.
Test and create the migration job
Review the settings you chose for the migration job.
Click TEST JOB to verify that the source has been configured correctly, that the source and destination instances are able to communicate with each other, and that the migration job is valid.
Verify that you see the "Tests passed successfully!" status.
If the test fails, then you can address the problem in the appropriate part of the flow, and return to re-test.
Click CREATE & START JOB to create the migration job and start it immediately.
Click START in the subsequent dialog box.
In the Migration jobs page, verify that your migration job has a status of "Starting". After a few minutes, confirm that the status changes to "Running".
Verify the migration job
In this section, you confirm that Database Migration Service used the migration job to migrate data from your source database instance to the destination AlloyDB database instance.
- Go to the AlloyDB Clusters page in the Google Cloud console.
- Click the read replica entry of your migration job.
- Click the Activate Cloud Shell icon that appears in the upper-right region of the page.
- At the Cloud Shell prompt, press Enter.
- Optional: If an Authorize Cloud Shell dialog box appears, then click Authorize.
- At the Enter password prompt, enter the password that you either provided or that Database Migration Service generated for you in Define and create the destination AlloyDB instance.
- At the postgres prompt, enter
\list
to list the databases and verify that you see your source database instance. - At the postgres prompt, enter
\connect SOURCE_DB_NAME
because you want to see the tables associated with this database instance. The name of the prompt changes frompostgres
to SOURCE_DB_NAME. - At the SOURCE_DB_NAME prompt, enter
\dt
to see the tables of this instance. - At the SOURCE_DB_NAME prompt, enter
GRANT alloydbexternalsync to USER;
because you want to give this user permission to access the data in the tables of this instance. - At the SOURCE_DB_NAME prompt, enter
SELECT * from TABLE_NAME;
to see the information that's replicated from a table in your source database instance. - Verify that you see the correct information in the table.
This confirms that Database Migration Service migrated the data.
Promote the migration job
You're ready to promote the migration job. As a result, the destination AlloyDB database instance replaces the source database instance as the primary database.
Return to the Migration jobs page.
Click the migration job that you want to promote. The Migration job details page appears.
Wait for the replication delay to trend toward zero.
Stop all writes to the source database.
Wait until the replication delay is at zero.
Click the migration job that you want to promote. This job should have a status of "Running".
Click PROMOTE to promote the migration job.
Click PROMOTE again in the subsequent dialog box.
Verify that the migration job has a status of "Promote in progress". After a few minutes, confirm that the status changes to "Completed".
Your new AlloyDB database instance is ready to use.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
- Use the Google Cloud console to delete your migration job, connection profile, AlloyDB cluster, and project if you don't need them.
What's next
- Read more about how to manage connection profiles.
- Read more about migration job statuses.
- Read more about migration job metrics.
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 2024-09-10 UTC.