Migrate from Cloud SQL for PostgreSQL to AlloyDB for PostgreSQL Stay organized with collections Save and categorize content based on your preferences.
This page describes how to migrate a Cloud SQL for PostgreSQL instance by copying a Cloud SQL backup into an AlloyDB for PostgreSQLfree trial cluster. Copying a Cloud SQL backup into an AlloyDB cluster enables you to quickly load data into Cloud SQL for PostgreSQL, which lets you evaluate or migrate into AlloyDB.
This page assumes familiarity with Cloud SQL. If you're new to AlloyDB, see theAlloyDB overview.
To learn how to migrate your data from Cloud SQL to AlloyDB usingcontinuous data replication, seeDatabase Migration Service for PostgreSQL to AlloyDB.
The following aren't supported:
- Cloud SQL Enterprise Plus edition instances
- Cross-project and cross-region restores
- Instances with Customer Managed Encryption Keys (CMEK)
- Instances with Identity and Access Management (IAM) group authentication
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.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the 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.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Make sure that billing is enabled for your Google Cloud project.
Enable the AlloyDB, Compute Engine, and Service Networking APIs.
- Make sure that you have the following:
- The necessary Identity and Access Management (IAM) permissions
- A Cloud SQL backup with a size that's less than 1TB
- A version of PostgreSQL supported by AlloyDB
Required roles
To get the permissions that you need to copy a Cloud SQL for PostgreSQL backup into an AlloyDB cluster, grant yourself the following IAM roles on your project:
- Cloud SQL Viewer(
roles/cloudsql.viewer
) or any custom role that includes thecloudsql.backupRuns.export
permission. - Cloud AlloyDB Admin(
roles/alloydb.admin
)
Copy a Cloud SQL backup into an AlloyDB cluster
Copying a Cloud SQL backup into an AlloyDBfree trialcluster restores the backup to the same version of PostgreSQL onAlloyDB, for example, a PostgreSQL 14 Cloud SQL backup restores to a PostgreSQL14 free trialcluster. Keep in mind that extension versions and PostgreSQL minor versions might bedifferent.
Copying a backup from Cloud SQL only supports the configuration of thoseitems supported in the AlloyDBfree trial cluster.
Note: You can't copy a backup if it's greater than1TB.To copy a Cloud SQL backup into an AlloyDBfreetrial cluster, follow these steps:
Console
- In the Google Cloud console, go to theClusters page.
- If you haven't already provisioned a cluster, clickStart a free trial. If you have an existing cluster, clickMigrate data.
- ClickCopy from Cloud SQL backup.
- In theCopy from Cloud SQL backup page, enable the required APIs. If you already enabled the APIs, you don't need to re-enable the APIs.
- In theSelect cluster type page, clickFree trial cluster. If you aren't eligible for a free trial cluster, this field is grayed out.
- ClickSelect Cluster Type.
- Select the Cloud SQL instance that you want to make a copy from and then clickSelect instance. You can filter Cloud SQL instances.
Only compatible database versions are displayed. Replicas don't have backups and aren't displayed in the list of available instances. - Select the backup you want to import from and then clickSelect backup. This page displays the most recent 1,000 backups.
- In theCreate your free cluster page, enter the cluster ID and your networking information.
- ClickStart a free trial.
After the operation completes, a primary instance is automatically created. You see a new AlloyDB cluster with the data that is copied from the Cloud SQL for PostgreSQL backup that you selected.
When you copy a Cloud SQL for PostgreSQL backup into an AlloyDB cluster, database flags and resource level permissions aren't automatically migrated. After the copy is complete, you must set up these flags and permissions manually.
You can check which database flags in Cloud SQL for PostgreSQL are supported in AlloyDB in theCreate your free cluster page.
gcloud
To use thegcloud CLI, you caninstall and initialize thegcloud CLI, or you can useCloud Shell.
gcloud beta alloydb clusters migrate-cloud-sql CLUSTER_ID
--cluster-id=CLUSTER_ID
\
--cloud-sql-backup-id=CLOUD_SQL_BACKUP_ID
\
--cloud-sql-instance-id=CLOUD_SQL_INSTANCE_ID
\
--cloud-sql-project-id=CLOUD_SQL_PROJECT_ID
--password=PASSWORD
\
--region=REGION
\
--database-version=DATABASE_VERSION
\
--subscription-type=TRIAL
Replace the following:
CLUSTER
: Cloud SQL for PostgreSQL cluster ID.CLOUD_SQL_BACKUP_ID
: CloudSQL backup ID to migrate from. This must be the backup ID.CLOUD_SQL_INSTANCE_ID
: CloudSQL instance ID to migrate from. This must be the instance ID.CLOUD_SQL_PROJECT_ID
: CloudSQL project to migrate from. This must be the project ID.PASSWORD
: initial PostgreSQL user password to set up during cluster creation.REGION
: location, for example,asia-east1
orus-east1
. See the full list of regions atregional locations.DATABASE_VERSION
: database version of the cluster. This must be one of:POSTGRES_14
,POSTGRES_15
, orPOSTGRES_16
. The database version must be same as the version of the Cloud SQL backup.SUBSCRIPTION_TYPE
: subscription type of the cluster. This must be one of:STANDARD
orTRIAL
.
gcloud beta alloydb operations describe
command to confirm the status of the backup operation:gcloud beta alloydb operations describe OPERATION_ID \ --region=REGION_ID \ --project=PROJECT_ID
Replace the following:
OPERATION_ID
: the name of the AlloyDB operation.REGION_ID
: the region in which the AlloyDB cluster is deployed.PROJECT_ID
: the project ID.
gcloud alloydb instances create
command tocreate a primary instance.REST API
- To get a list of backups for the instance from which you want to restore your backup, call the
backupsRuns.list
method:GET "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns"
Replace the following:
PROJECT_ID
: the project ID.INSTANCE_ID
: the instance ID.
Request JSON body:
{ "kind": string, "items": [ { object (BackupRun) } ], "nextPageToken": string }
To send your request, use one of these options:
curl (Linux, macOS, or Cloud Shell)
The following command assumes that you signed into the
gcloud CLI
with your user account by runninggcloud init
orgcloud auth login
, or by usingCloud Shell
, which automatically signs you into thegcloud CLI
.You can check the active account by running
gcloud auth list
.Save the request body in a file named
request.json
and execute the following command:curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ "https://sqladmin.googleapis.com//sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns"
PowerShell (Windows)
The following command assumes that you signed into the
gcloud CLI
with your user account by runninggcloud init
orgcloud auth login
, or by usingCloud Shell
, which automatically signs you into thegcloud CLI
.You can check the active account by running
gcloud auth list
.Save the request body in a file named
request.json
and execute the following command:$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -Uri "https://sqladmin.googleapis.com//sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns"|Select-Object -Expand Content
You receive a JSON response similar to the following:
Response
If successful, the response body contains a list of
The API response returns a list of backups for the instance as an array list, includingBackupRun
."id": string,
. - Call therestoreFromCloudSQL method:
POST https://alloydb.googleapis.com/v1beta/projects/PROJECT_ID/locations/REGION/clusters:restoreFromCloudSQL
Replace the following:
PROJECT_ID
: the project ID.REGION
: the region in which the AlloyDB cluster is deployed.
Request JSON body:
{ "clusterId": string, "cluster": { "databaseVersion": "POSTGRES_14/POSTGRES_15/POSTGRES_16","subscriptionType": "TRIAL" }, // Union field source can be only one of the following: "cloudsqlBackupRunSource": { object (CloudSQLBackupRunSource) } // End of list of possible types for union field source. }
To send your request, use one of these options:
curl (Linux, macOS, or Cloud Shell)
The following command assumes that you signed into the
gcloud CLI
with your user account by runninggcloud init
orgcloud auth login
, or by usingCloud Shell
, which automatically signs you into thegcloud CLI
.You can check the active account by running
gcloud auth list
.Save the request body in a file named
request.json
and execute the following command:curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://alloydb.googleapis.com/v1beta/projects/PROJECT_ID/locations/REGION/clusters:restoreFromCloudSQL"
PowerShell (Windows)
The following command assumes that you signed into the
gcloud CLI
with your user account by runninggcloud init
orgcloudauth login
, or by usingCloud Shell
, which automatically signs you into thegcloud CLI
.You can check the active account by running
gcloud auth list
.Save the request body in a file named
request.json
and execute the following command:$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://alloydb.googleapis.com/v1beta/projects/PROJECT_ID/locations/REGION/clusters:restoreFromCloudSQL"|Select-Object -Expand Content
You receive a JSON response similar to the following:
Response
If successful, the response body contains an instance of
Operation
.A new cluster is created in the specified project and location, with a volume restored from the backup pointed in theCloudSQLBackupRunSource message.
- When the cluster is in a
READY
state, create the primary instance by calling theprojects.locationsinstances.create
method:POST https://alloydb.googleapis.com/v1beta/{parent=projects/PROJECT_ID/locations/REGION/clusters/CLUSTER_ID}/instances
Replace the following:
PROJECT_ID
: the project ID.REGION
: the region in which the AlloyDB cluster is deployed.CLUSTER_ID
: the cluster ID.
Request JSON body:
{ "instanceId": "string", "instance": { "object": "Instance" } }
The request body contains an instance of
Instance
.To send your request, use one of these options:
curl (Linux, macOS, or Cloud Shell)
The following command assumes that you signed into the
gcloud CLI
with your user account by runninggcloud init
orgcloud auth login
, or by usingCloud Shell
, which automatically signs you into thegcloud CLI
.You can check the active account by running
gcloud auth list
.Save the request body in a file named
request.json
and execute the following command:curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://alloydb.googleapis.com/v1beta/projects/PROJECT_ID/locations/REGION/clusters/CLUSTER_ID/instances"
PowerShell (Windows)
The following command assumes that you signed into the
gcloud CLI
with your user account by runninggcloud init
orgcloud auth login
, or by usingCloud Shell
, which automatically signs you into thegcloud CLI
.You can check the active account by running
gcloud auth list
.Save the request body in a file named
request.json
and execute the following command:$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://alloydb.googleapis.com/v1beta/projects/PROJECT_ID/locations/REGION/clusters/CLUSTER_ID/instances"|Select-Object -Expand Content
You receive a JSON response similar to the following:
Response
If successful, the response body contains a newly created instance of
Operation
. - After the instance is updated to the
READY
state, connect to the instance and access the restored data from the Cloud SQL snapshot.
What's next
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-15 UTC.