チェックポイント
Create a connection profile for the PostgreSQL source instance
/ 50
Test the continuous migration of data
/ 50
Migrating to AlloyDB from PostgreSQL Using Database Migration Service
- GSP1084
- Overview
- Setup and requirements
- Task 1. Verify Data in the Source Instance for migration
- Task 2. Create a Database Migration Service connection profile for a stand-alone PostgreSQL database
- Task 3. Create and start a continuous migration job
- Task 4. Confirm data load in the AlloyDB for PostgreSQL Instance
- Task 5. Propagate a live update to the AlloyDB Instance
- Congratulations!
GSP1084
Overview
In Google Cloud, you can use Database Migration Service to migrate PostgreSQL databases to AlloyDB for PostgreSQL. To do this, AlloyDB requires the use of private services access. This access is implemented as a VPC peering connection between your VPC network and the underlying Google Cloud VPC network where your AlloyDB resources reside.
In this lab, you migrate a stand-alone PostgreSQL database (running on a virtual machine) to AlloyDB for PostgreSQL using a continuous Database Migration Service job with VPC peering for connectivity.
Migrating a database via Database Migration Service requires some preparation of the source database. Those tasks have been completed for you on the source environment with the most important being setting up the pglogical package on the source instance.
After you create and run the migration job, you confirm that an initial copy of your database has been successfully migrated to your AlloyDB for PostgreSQL instance. You also explore how continuous migration jobs apply data updates from your source database to your AlloyDB for PostgreSQL instance.
What you'll do
In this lab, you learn how to configure a continuous Database Migration Service job to migrate databases from a PostgreSQL instance to AlloyDB for PostgreSQL.
- Verify Data in the Source Instance for migration
- Create a profile for a source connection to a PostgreSQL instance (e.g., stand-alone PostgreSQL)
- Create and start a continuous migration job
- Confirm data load in the AlloyDB for PostgreSQL Instance
- Propagate a live update to the AlloyDB Instance
Setup and requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud console
-
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
- The Open Google Cloud console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username below and paste it into the Sign in dialog.
{{{user_0.username | "Username"}}} You can also find the Username in the Lab Details panel.
-
Click Next.
-
Copy the Password below and paste it into the Welcome dialog.
{{{user_0.password | "Password"}}} You can also find the Password in the Lab Details panel.
-
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Google Cloud console opens in this tab.
Activate Cloud Shell
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
- Click Activate Cloud Shell at the top of the Google Cloud console.
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
- (Optional) You can list the active account name with this command:
- Click Authorize.
Output:
- (Optional) You can list the project ID with this command:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Task 1. Verify Data in the Source Instance for migration
Verify Data in Source Instance
In this step connect to and verify data in the postgres database on the pg14-source VM Instance.
-
On the Navigation menu (), under Compute Engine click VM instances.
-
For the instance named pg14-source, in the Connect column, click SSH to open a terminal window.
-
Use the following command to launch the PostgreSQL (psql) client.
- You will be presented with the psql terminal prompt similar to as shown below.
- Input and run the following SQL command to see the HR related tables in the postgres database.
- Run the following queries to determine the row counts for each table.
- The source table row counts are as follows.
Name | Rows |
---|---|
countries | 25 |
departments | 27 |
employees | 107 |
jobs | 19 |
locations | 23 |
regions | 4 |
-
Type \q to exit the psql client.
-
Type exit to close the terminal window.
Task 2. Create a Database Migration Service connection profile for a stand-alone PostgreSQL database
In this task, you will create a connection profile for the PostgreSQL source instance.
Get the connectivity and deployment information for the PostgreSQL source instance
In this step, you identify the internal IP address of the source database instance that you will migrate to AlloyDB.
-
On the Navigation menu (), under Compute Engine click VM instances.
-
Locate the line for the instance pg14-source.
-
Copy the value for the Internal IP (e.g., 10.128.15.208).
Create a new connection profile for the PostgreSQL source instance
A connection profile stores information about the source database instance (e.g., stand-alone PostgreSQL) and is used by the Database Migration Service to migrate data from the source to your destination AlloyDB for PostgreSQL instance. After you create a connection profile, it can be reused across migration jobs.
In this step you will create a new connection profile for the PostgreSQL source instance.
-
In the Google Cloud Console, on the Navigation menu (), click Database Migration > Connection profiles.
-
Click + Create Profile.
-
For Database engine, select PostgreSQL.
-
For Connection profile name, enter pg14-source.
-
For Hostname or IP address, enter the internal IP for the PostgreSQL source instance that you copied in the previous task (e.g., 10.128.15.208)
-
For Port, enter 5432.
-
For Username, enter postgres.
-
For Password, enter Change3Me .
-
For Region select
. -
For all other values leave the defaults.
-
Click Create.
A new connection profile named pg14-source will appear in the Connections profile list.
- Click Check my progress to verify the objective.
Create a connection profile for the PostgreSQL source instance
Task 3. Create and start a continuous migration job
When you create a new migration job, you first define the source database instance using a previously created connection profile. Then you create a new destination database instance and configure connectivity between the source and destination instances.
In this task, you use the migration job interface to create a new AlloyDB for PostgreSQL cluster and set it as the destination for the continuous migration job from the PostgreSQL source instance.
Create a new continuous migration job
In this step you will create a new continuous migration job.
-
In the Google Cloud Console, on the Navigation menu (), click Database Migration > Migration jobs.
-
Click + Create Migration Job.
-
For Migration job name, enter postgres-to-alloydb.
-
For Source database engine, select PostgreSQL.
-
For Destination database engine, select AlloyDB for PostgreSQL.
-
For Destination region, select
. -
At the moment, Continuous is the only option available Migration job type for PostgreSQL to AlloyDB.
-
Leave the defaults for the other settings.
-
Click Save & Continue.
Define the source instance
In this step, you will define the source instance for the migration.
-
For Select source connection profile, select the pg14-source connection profile you created a few steps ago.
-
Click Save & Continue.
Create the destination instance
In this step, the DMS wizard will create the AlloyDB cluster and instance on your behalf.
-
For Type of destination cluster, there is the already option selected is New cluster.
-
Click Continue for Review the cluster configuration.
-
For Cluster ID, enter alloydb-target-cluster.
-
For Password, enter Change3Me.
-
For Network, select peering-network.
-
Click Continue.
-
For Instance ID, enter alloydb-target-instance.
-
Select 2 vCPU, 16 GB as your machine type.
-
Click Save & Continue.
-
On the pop-up window, Click Create Destination & Continue to continue.
-
While your AlloyDB instance and cluster are being created, you can choose VPC peering from the Connectivity method list of options.
-
Please wait until the cluster and instance are complete. The Configure & Continue link will be available once the database is available.
-
Click Configure & Continue.
Test and start the continuous migration job
In this step, you will test and start the migration job.
-
The Database Migration Service wizard will now be on the Test and create your migration job step.
-
Click Test Job.
-
After a successful test, click Create & Start Job.
If prompted to confirm, click Create & Start.
Review the status of the continuous migration job
In this step, you will confirm that the continuous migration job is running.
-
In the Google Cloud Console, on the Navigation menu (), click Database Migration > Migration jobs.
-
Click the migration job postgres-to-alloydb to see the details page.
-
Review the migration job status.
- If you have not started the job, the status will show as Not started. You can choose to start or delete the job.
- After the job has started, the status will show as Starting and then transition to Running Full dump in progress to indicate that the initial database dump is in progress.
- The job status will move to Running CDC in progress once the initial load is complete and DMS is available for continuous operations.
When the job status changes to Running CDC in progress, proceed to the next task.
Task 4. Confirm data load in the AlloyDB for PostgreSQL Instance
Check the AlloyDB for PostgreSQL Instance
-
On the Cloud Console Navigation menu (), under Databases click AlloyDB for PostgreSQL then Clusters to examine the cluster's details.
-
The cluster is named alloydb-target-cluster and the instance is named alloydb-target-instance.
-
Please make note of the Private IP address in the instances section. Copy the Private IP address to a text file so that you can paste the value in a later step.
-
On the Navigation menu (), under Compute Engine click VM instances.
-
For the instance named alloydb-client, in the Connect column, click SSH to open a terminal window.
-
Set the following environment variable, replacing ALLOYDB_ADDRESS with the Private IP address of the AlloyDB instance.
- Run the following command to store the Private IP address of the AlloyDB instance on the AlloyDB client VM so that it will persist throughout the lab.
- Connect to the psql client and run the following query to verify that the five source tables are now in the AlloyDB instance. You will be prompted to provide the postgres user's password (Change3Me) which was specified when the cluster was created.
- Run the following queries to determine the row counts for the migrated tables. The values will match the query outputs on the source instance.
- The target table row counts are as follows.
Name | Rows |
---|---|
countries | 25 |
departments | 27 |
employees | 107 |
jobs | 19 |
locations | 23 |
regions | 4 |
- Run the following query to verify the data in the regions table.
Task 5. Propagate a live update to the AlloyDB Instance
-
Because the Database Migration Service job is set in a continuous update configuration, any updates you make on the source instance will be applied to the AlloyDB target.
-
On the Navigation menu (), under Compute Engine click VM instances.
-
For the instance named pg14-source, in the Connect column, click SSH to open a terminal window.
-
Use the following command to launch the PostgreSQL (psql) client.
- You will be presented the psql terminal prompt. Input and run the following SQL command to add one row of data to the regions table.
- Confirm that the row was inserted locally.
Review data in the AlloyDB for PostgreSQL instance
- Return to the terminal shell for the alloydb-client. The psql client will still be open. Run the following query to verify that the Oceania row was added to the targeted AlloyDB instance.
- Click Check my progress to verify the objective.
Test the continuous migration of data
Congratulations!
You have now successfully migrated a stand-alone PostgreSQL database (running on a virtual machine) to AlloyDB for PostgreSQL using a continuous Database Migration Service job.
Manual Last Updated September 09, 2024
Lab Last Tested September 09, 2024
Copyright 2024 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.