提供意見
使用 API 管理連線設定檔
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
總覽
本頁說明如何使用資料庫移轉服務 API,管理 PostgreSQL 來源資料庫和 AlloyDB 目的地的連線設定檔。
您可以透過兩種方式使用資料庫移轉服務 API。您可以發出 REST API 呼叫,也可以使用 Google Cloud CLI (CLI)。
如要查看使用 gcloud
管理資料庫遷移服務連線設定檔的概略資訊,請按這裡 。
資料庫移轉服務的部分 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
建立資料庫遷移服務連線設定檔的概略資訊,請按這裡 。
建立完成後,您可以呼叫 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
擷取連結設定檔的相關資訊,請按這裡 。
為 PostgreSQL 適用的 Cloud SQL 來源資料庫建立連線設定檔
以下是為 PostgreSQL 適用的 Cloud SQL 來源資料庫建立連線設定檔的要求。這個範例使用 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
建立資料庫遷移服務連線設定檔的概略資訊,請按這裡 。
為 AlloyDB for PostgreSQL 目的地建立連線設定檔
以下是建立 AlloyDB for PostgreSQL 目的地連線設定檔的要求。資料庫遷移服務會使用這項要求中的資訊,建立新的 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 的靜態資料,都會透過強化版金鑰管理系統進行加密。這個系統與 Google 加密自家資料時使用的系統相同,這些金鑰管理系統提供嚴格的金鑰存取權控管和稽核機制,並使用 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
建立資料庫遷移服務連線設定檔的概略資訊,請按這裡 。
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 :專案區域
您也可以篩選資料庫遷移服務擷取的連線設定檔清單,如下所示:
orderBy:
使用這個篩選器,即可依字母順序擷取特定地區的所有連線設定檔清單。舉例來說,orderBy=name
篩選器會依名稱依序傳回所有連線設定檔。
pageSize:
使用這個篩選器,指定資料庫遷移服務在頁面上擷取及顯示的連線設定檔上限。舉例來說,設定 pageSize=10
後,資料庫遷移服務會針對一個網頁傳回最多 10 個連線設定檔。
如果連線設定檔超過 10 個,則會顯示在其他頁面。每個頁面的結尾都會顯示 nextPageToken
參數和不重複 ID。使用 ID 擷取下列頁面的連線設定檔清單。
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:
資料庫移轉服務會擷取來源資料庫的新快照,將初始資料傾印載入目的地資料庫,並處理從來源資料庫到目的地資料庫的資料變更。
如果使用者有任何處於上述狀態的遷移工作,且嘗試刪除連線設定檔,則會失敗。
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 執行個體,請按這裡 。
提供意見
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權 ,程式碼範例則為阿帕契 2.0 授權 。詳情請參閱《Google Developers 網站政策 》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-05-15 (世界標準時間)。
想進一步說明嗎?
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-05-15 (世界標準時間)。"],[[["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."]]],[]]