This quickstart shows you how to use Database Migration Service to migrate data to Cloud SQL 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 and IP allowlist 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 Cloud SQL 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 Source 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.
- (Optional) If you plan to transfer sensitive information over a public network (by using IP allowlists), then we recommend using SSL/TLS encryption for the connection between the source and destination databases. Otherwise, keep the default value of None.
- 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 Cloud SQL 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 Cloud SQL 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.
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 Cloud SQL 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 Cloud SQL 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.
Define settings for the destination Cloud SQL instance
Provide a Destination Instance ID for the Cloud SQL instance. By default, the migration job ID is pre-populated in this field. You can keep this name or enter another name.
Provide an alphanumeric password for the destination Cloud SQL instance. This will be the password for the
postgres
administrator account in the instance.You can either enter the password manually or click GENERATE to have Database Migration Service create one for you automatically.
Choose the Database version for the destination instance from the list of supported Cloud SQL versions for the specified database engine.
Select the desired Google Cloud Zone for the new Cloud SQL instance (or leave as "Any").
Select the Public IP check box because, for this quickstart, you're using IP allowlist as the networking method. This method works by configuring the source database server to accept connections from the outgoing IP address of the Cloud SQL instance.
Select the Machine type for the Cloud SQL instance. The disk size must be equal to or greater than the source database size.
Define the Storage type and Storage capacity for the Cloud SQL instance.
Click CREATE & CONTINUE to create the new instance.
Click CREATE DESTINATION & CONTINUE in the subsequent dialog box. Creating the instance may take several minutes to complete.
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 IP allowlist as the networking method.
- If the source IP address isn't pre-populated in this field, then copy the Cloud SQL
instance's outgoing IP address from the console, and use
it to configure the network firewall for the source database server to
accept connections from this IP address.
- Update the
pg_hba.conf
file or Amazon RDS security groups to accept connections from this IP address. - In your firewall rules, create an Inbound (or Ingress) rule to allow connections on port 5432 from the destination Cloud SQL instance's connectivity IP address.
- Update the
- 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 Cloud SQL database instance.
- Go to the SQL Instances 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 Google Cloud Shell prompt, press Enter.
- Optional: If an Authorize Cloud Shell dialog box appears, then click Authorize.
- Connect to the destination Cloud SQL database instance.
- At the Enter password prompt, enter the password that you either provided or that Database Migration Service generated for you in Define settings for the destination Cloud SQL 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 cloudsqlexternalsync 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 Cloud SQL 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 Cloud SQL 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, Cloud SQL instance, 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-11-06 UTC.