发送反馈
使用 API 管理连接配置文件
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
概览
在本页中,您将学习如何使用 Database Migration Service API 管理 PostgreSQL 源数据库和 AlloyDB 目标数据库的连接配置文件。
您可以通过两种方式使用 Database Migration Service API。您可以进行 REST API 调用,也可以使用 Google Cloud CLI (CLI)。
如需查看有关使用 gcloud
管理 Database Migration Service 连接配置文件的概要信息,请点击此处 。
Database Migration Service 的某些 API 调用可能需要一些时间才能完成。由于 API 是异步的,因此即使操作仍在进行中,调用也会立即返回。如果后续 API 调用使用新创建的对象,则必须等到第一个操作完成后才能继续。
为 PostgreSQL 源数据库创建连接配置文件
以下代码显示了为 PostgreSQL 源数据库创建连接配置文件的请求。
REST
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
region :项目区域
connection-profile-id :连接配置文件 ID
connection-profile-display-name :连接配置文件显示名称
host-ip-address :来源 IP 地址
username :数据库用户名
password :数据库用户密码
HTTP 方法和网址:
POST https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id
请求 JSON 正文:
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id "
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$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://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id " | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{
"name": "projects/project-id /locations/region /operations/operation-1591973161667-5a7e422cb0ba4-3004980d-2ae97165",
"metadata": {
"@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata",
"createTime": "2020-06-12T14:46:01.744267779Z",
"target": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ",
"verb": "create",
"requestedCancellation": false,
"apiVersion": "v1"
},
"done": false
}
gcloud
如需查看有关使用 gcloud
创建 Database Migration Service 连接配置文件的概要信息,请点击此处 。
创建后,您可以调用 connectionProfiles/get
方法来查看连接配置文件的相关信息。
REST
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
region :项目区域
connection-profile-id :连接配置文件 ID
HTTP 方法和网址:
GET https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id "
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id " | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
gcloud
如需详细了解如何使用 gcloud
检索连接配置文件的相关信息,请点击此处 。
为 Cloud SQL for PostgreSQL 源数据库创建连接配置文件
以下示例展示了为 Cloud SQL for PostgreSQL 源数据库创建连接配置文件的请求。此示例使用 PostgreSQL 连接配置文件,因为它连接到 PostgreSQL 数据库引擎,而不是 Cloud SQL 管理层。
若要使用 Cloud SQL 在源数据库和副本之间创建配对,您必须提供 Cloud SQL 数据库的实例 ID。您可以使用 Cloud SQL Admin API 的 databases/list
方法找到实例 ID 值。
REST
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
region :项目区域
connection-profile-id :连接配置文件 ID
connection-profile-display-name :连接配置文件显示名称
host-ip-address :来源 IP 地址
username :数据库用户名
password :数据库用户密码
cloud-sql-instance-id :Cloud SQL 实例 ID
HTTP 方法和网址:
POST https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id
请求 JSON 正文:
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id "
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$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://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id " | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{
"name": "projects/project-id /locations/region /operations/operation-1591973161667-5a7e422cb0ba4-3004980d-2ae97165",
"metadata": {
"@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata",
"createTime": "2020-06-12T14:46:01.744267779Z",
"target": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ",
"verb": "create",
"requestedCancellation": false,
"apiVersion": "v1"
},
"done": false
}
gcloud
如需查看有关使用 gcloud
创建 Database Migration Service 连接配置文件的概要信息,请点击此处 。
为 AlloyDB for PostgreSQL 目标位置创建连接配置文件
以下代码显示了为 AlloyDB for PostgreSQL 目标创建连接配置文件的请求。Database Migration Service 会使用此请求中的信息创建新的 AlloyDB 实例。
REST
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
region :项目区域
connection-profile-id :连接配置文件 ID
connection-profile-display-name :连接配置文件显示名称
cluster-id :要创建的 AlloyDB 集群 ID
user :要为初始用户分配的用户名
password :要为初始用户提供的密码
vpc-network :AlloyDB 集群将连接到的 VPC 网络
instance-id :要创建的 AlloyDB 实例 ID
cpu-count :要为实例配置的 CPU 数量
Google Cloud 中存储的所有静态数据,是使用我们用于自己的加密数据的同一强化密钥管理系统进行加密的。这些密钥管理系统提供严格的密钥访问控制和审核机制,并使用 AES-256 加密标准加密用户的静态数据。无需进行任何设置、配置或管理。对于对加密材料的合规性或当地性没有特定要求的用户, Google Cloud的默认静态加密是最佳选择。
HTTP 方法和网址:
POST https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id
请求 JSON 正文:
{
"displayName": "connection-profile-display-name ",
"alloydb": {
"cluster_id": "cluster-id "
"settings": {
"initial_user": {
"user": "user ",
"password": "password ",
}
"vpc_network": "vpc-network ",
"primary_instance_settings": {
"id": "instance-id ",
"machine_config": {
"cpu_count": cpu-count
}
}
}
}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id "
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$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://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles?connectionProfileId=connection-profile-id " | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{
"name": "projects/project-id /locations/region /operations/operation-1591975557292-5a7e4b195623c-e350e3da-713dee7d",
"metadata": {
"@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata",
"createTime": "2020-06-12T15:25:57.430715421Z",
"target": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ",
"verb": "create",
"requestedCancellation": false,
"apiVersion": "v1"
},
"done": false
}
gcloud
如需查看有关使用 gcloud
创建 Database Migration Service 连接配置文件的概要信息,请点击此处 。
REST
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
region :项目区域
connection-profile-id :连接配置文件 ID
HTTP 方法和网址:
GET https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id "
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id " | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
gcloud
如需详细了解如何使用 gcloud
检索连接配置文件的相关信息,请点击此处 。
列出连接配置文件
以下代码展示了一个检索所有连接配置文件的相关信息的请求。
REST
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
region :项目区域
您还可以过滤 Database Migration Service 检索到的连接配置文件列表,如下所示:
orderBy:
使用此过滤条件可按字母顺序检索特定区域的所有连接配置文件列表。例如,orderBy=name
过滤条件会按名称的字母顺序返回所有连接个人资料。
pageSize:
使用此过滤条件可指定 Database Migration Service 在页面上检索和显示的连接配置文件的数量上限。例如,通过设置 pageSize=10
,Database Migration Service 最多会针对一个网页返回 10 个连接配置文件。
如果连接配置文件超过 10 个,则会显示在其他页面上。每个页面末尾都会显示 nextPageToken
参数和唯一标识符。使用该标识符检索以下页面的连接配置文件列表。
HTTP 方法和网址:
GET https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
gcloud
如需详细了解如何使用 gcloud
检索所有连接配置文件的相关信息,请点击此处 。
更新连接配置文件
以下示例展示了用于更新现有连接配置文件的用户名和密码字段的请求。通过在请求中使用 updateMask
参数,使只有这些字段需要包含在请求正文中。
REST
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
region :项目区域
connection-profile-id :连接配置文件 ID
username :数据库用户名
password :数据库用户密码
HTTP 方法和网址:
请求 JSON 正文:
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ ""
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method PATCH ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{
"name": "projects/project-id /locations/region /operations/operation-1591973161667-5a7e422cb0ba4-3004980d-2ae97165",
"metadata": {
"@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata",
"createTime": "2020-06-12T14:46:01.744267779Z",
"target": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ",
"verb": "update",
"requestedCancellation": false,
"apiVersion": "v1"
},
"done": false
}
gcloud
如需详细了解如何使用 gcloud
更新连接配置文件,请点击此处 。
删除连接配置文件
重要提示 :只有在与连接配置文件关联的迁移作业均处于非活动状态时,您才能删除该连接配置文件。如果连接配置文件中有正在进行的迁移作业,请提升 或删除 这些作业。
如需查看某个连接配置文件是否有任何与其关联的有效迁移作业,请运行以下命令:
GET
https://datamigration.googleapis.com/v1/projects/project-id /locations/region /migrationJobs?filter=state:STATE_NAME OR state:STATE_NAME AND source:projects/project-id /locations/region /connectionProfiles/connection-profile-id
例如:
GET
https://datamigration.googleapis.com/v1/projects/myproject/locations/myregion/migrationJobs?filter=state:RUNNING OR state:FAILED AND source:projects/myproject/locations/myregion/connectionProfiles/postgresql-to-alloydb-src1
迁移作业的各种状态如下:
NOT STARTED:
迁移作业已创建,但尚未开始。
STARTING:
迁移作业正在启动中。
RUNNING:
迁移作业正在运行,可用于将数据从源数据库迁移到目标数据库。
STOPPING:
迁移作业正在停止。
STOPPED:
迁移作业已暂停,并且不再将数据迁移到目标数据库。
RESUMING:
暂停的迁移作业正在运行。
FAILED:
迁移作业运行时出现问题。
RESTARTING:
Database Migration Service 会拍摄源数据库的新快照,将初始转储加载到目标数据库,并处理源数据库到目标数据库之间持续发生的数据更改。
如果用户的迁移作业处于上述任一状态,并且用户尝试删除连接配置文件,则删除操作将会失败。
REST
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
region :项目区域
connection-profile-id :连接配置文件 ID
HTTP 方法和网址:
DELETE https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X DELETE \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id "
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method DELETE ` -Headers $headers ` -Uri "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id " | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{
"name": "projects/project-id /locations/region /operations/operation-1591973161667-5a7e422cb0ba4-3004980d-2ae97165",
"metadata": {
"@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata",
"createTime": "2020-06-12T14:46:01.744267779Z",
"target": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ",
"verb": "delete",
"requestedCancellation": false,
"apiVersion": "v1"
},
"done": false
}
gcloud
如需详细了解如何使用 gcloud
删除连接配置文件,请点击此处 。
删除连接配置文件和关联的 AlloyDB 实例
以下示例展示了删除目标连接配置文件以及级联删除关联的 AlloyDB 实例的请求。
REST
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
region :项目区域
connection-profile-id :连接配置文件 ID
HTTP 方法和网址:
DELETE https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id ?force=true
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X DELETE \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id ?force=true"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method DELETE ` -Headers $headers ` -Uri "https://datamigration.googleapis.com/v1/projects/project-id /locations/region /connectionProfiles/connection-profile-id ?force=true" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{
"name": "projects/project-id /locations/region /operations/operation-1591973161667-5a7e422cb0ba4-3004980d-2ae97165",
"metadata": {
"@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata",
"createTime": "2020-06-12T14:46:01.744267779Z",
"target": "projects/project-id /locations/region /connectionProfiles/connection-profile-id ",
"verb": "create",
"requestedCancellation": false,
"apiVersion": "v1"
},
"done": false
}
gcloud
如需详细了解如何使用 gcloud
同时删除连接配置文件和关联的 AlloyDB 实例,请点击此处 。
发送反馈
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可 获得了许可,并且代码示例已根据 Apache 2.0 许可 获得了许可。有关详情,请参阅 Google 开发者网站政策 。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-04-17。
需要向我们提供更多信息?
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-04-17。"],[[["This page explains how to manage connection profiles for PostgreSQL source databases and AlloyDB destinations using the Database Migration Service API, which can be accessed through REST API calls or the Google Cloud CLI."],["You can create connection profiles for PostgreSQL source databases, including Cloud SQL for PostgreSQL, by using provided request examples and specific parameters such as project ID, region, and connection profile details."],["AlloyDB destination connection profiles can be created, and they support the creation of new AlloyDB instances, with options to specify cluster ID, user credentials, VPC network, instance ID, and CPU configuration."],["Connection profile information can be viewed, updated, and listed using the API, and it includes filtering and ordering options for efficient retrieval of information."],["Connection profiles can be deleted, but if there are active migration jobs associated with it, they must be promoted or deleted first, and if it's an AlloyDB instance it can also be cascade-deleted using the API."]]],[]]