Share via


將 PostgreSQL 資料庫移轉至已啟用 Azure Arc 的 PostgreSQL 伺服器

本文件說明將現有 PostgreSQL 資料庫 (未裝載於已啟用 Azure Arc 的資料服務) 移轉至已啟用 Azure Arc 的 PostgreSQL 伺服器的步驟。

注意

作為預覽功能,本文所述的技術受限於 Microsoft Azure 預覽版增補使用規定

版本資訊中提供的最新更新。

考量

已啟用 Azure Arc 的 PostgreSQL 伺服器是 PostgreSQL 的社群版本。 因此,在 Azure Arc 外部的 PostgreSQL 上運作的任何工具,都應該使用已啟用 Azure Arc 的 PostgreSQL 伺服器。

因此,透過您今天針對 Postgres 使用的一組工具,您應該能夠:

  1. 從裝載於 Azure Arc 外部的執行個體備份您的 Postgres 資料庫
  2. 在已啟用 Azure Arc 的 PostgreSQL 伺服器中還原資料庫

您要做的事是:

  • 重設伺服器參數
  • 重設安全性內容:重新建立使用者、角色和重設權限...

若要執行此備份/還原作業,您可以使用任何能夠執行 Postgres 備份/還原的工具。 例如:

  • Azure Data Studio 及其 Postgres 擴充功能
  • pgcli
  • pgAdmin
  • pg_dump
  • pg_restore
  • psql
  • ...

範例

讓我們使用 pgAdmin 工具來說明這些步驟。 請考慮下列設定:

  • 來源:
    在裸機伺服器上內部部署執行、並名稱為 JEANYDSRV 的 Postgres 伺服器。 它是第 14 版,並裝載名為 MyOnPremPostgresDB 的資料庫,其中一個資料表 T1 具有 1 行資料列 Migrate-source

  • 目的地:
    在 Azure Arc 環境中執行的 Postgres 伺服器,且名稱為 postgres01。 其版本為 14。 除了標準 Postgres 資料庫之外,它沒有任何資料庫。
    Migrate-destination

備份內部部署來源資料庫

Migrate-source-backup

請加以設定:

  1. 提供檔案名稱:MySourceBackup
  2. 將格式設定為 [自訂]Migrate-source-backup-configure

備份成功完成:
Migrate-source-backup-completed

在已啟用 Azure Arc 的 PostgreSQL 伺服器中,於目的地系統上建立空的資料庫

注意

若要在 pgAdmin 工具中註冊 Postgres 執行個體,您必須在 Kubernetes 叢集中使用執行個體的公用 IP,並適當地設定連接埠和安全性內容。 執行下列命令之後,您會在 psql 端點行上找到這些詳細資料:

az postgres server-arc endpoint list -n postgres01 --k8s-namespace <namespace> --use-k8s

會傳回如下的輸出:

{
  "instances": [
    {
      "endpoints": [
    "Description": "PostgreSQL Instance",
    "Endpoint": "postgresql://postgres:<replace with password>@12.345.123.456:1234"
  },
  {
    "Description": "Log Search Dashboard",
    "Endpoint": "https://12.345.123.456:12345/kibana/app/kibana#/discover?_a=(query:(language:kuery,query:'custom_resource_name:\"postgres01\"'))"
  },
  {
    "Description": "Metrics Dashboard",
    "Endpoint": "https://12.345.123.456:12345/grafana/d/postgres-metrics?var-Namespace=arc3&var-Name=postgres01"
  }
],
"engine": "PostgreSql",
"name": "postgres01"
}
  ],
  "namespace": "arc"
}

讓我們將目的地資料庫命名為 RESTORED_MyOnPremPostgresDB

Migrate-destination-db-create

在 Arc 設定中還原資料庫

Migratre-db-restore

設定還原:

  1. 指向包含要還原之備份的檔案:MySourceBackup

  2. 將格式保持設定為 [自訂或 tar]Migrate-db-restore-configure

  3. 按一下 [還原]。

    還原成功。
    Migrate-db-restore-completed

確認在已啟用 Azure Arc 的 PostgreSQL 伺服器中已成功還原資料庫

請使用下列其中一個方法:

寄件者 pgAdmin

展開 Azure Arc 安裝程式中裝載的 Postgres 執行個體。 您會在已還原的資料庫中看到資料表,當您選取資料時,它會顯示與內部部署執行個體中相同的資料列:

Migrate-db-restore-verification

從 Azure Arc 設定內部的 psql

在 Arc 設定中,您可以使用 psql 來連線到 Postgres 執行個體、將資料庫內容設定為 RESTORED_MyOnPremPostgresDB,並查詢資料:

  1. 列出端點以協助形成 psql 連接字串:

    az postgres server-arc endpoint list -n postgres01 --k8s-namespace <namespace> --use-k8s
    
    {
      "instances": [
        {
          "endpoints": [
        "Description": "PostgreSQL Instance",
        "Endpoint": "postgresql://postgres:<replace with password>@12.345.123.456:1234"
      },
      {
        "Description": "Log Search Dashboard",
        "Endpoint": "https://12.345.123.456:12345/kibana/app/kibana#/discover?_a=(query:(language:kuery,query:'custom_resource_name:\"postgres01\"'))"
      },
      {
        "Description": "Metrics Dashboard",
        "Endpoint": "https://12.345.123.456:12345/grafana/d/postgres-metrics?var-Namespace=arc3&var-Name=postgres01"
      }
    ],
    "engine": "PostgreSql",
    "name": "postgres01"
    }
      ],
      "namespace": "arc"
    }
    
  2. 從您的 psql 連接字串使用 -d 參數來指出資料庫名稱。 使用下列命令時,系統會提示您輸入密碼:

    psql -d RESTORED_MyOnPremPostgresDB -U postgres -h 10.0.0.4 -p 32639
    

    psql 連接。

    Password for user postgres:
    psql (10.12 (Ubuntu 10.12-0ubuntu0.18.04.1), server 12.3 (Debian 12.3-1.pgdg100+1))
    WARNING: psql major version 10, server major version 12.
          Some psql features might not work.
    SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
    Type "help" for help.
    
    RESTORED_MyOnPremPostgresDB=#   
    
  3. 選取資料表,您會看到從內部部署 Postgres 執行個體還原的資料:

    RESTORED_MyOnPremPostgresDB=# select * from t1;
    
     col1 |    col2
    ------+-------------
        1 | BobbyIsADog
    (1 row)
    

注意

  • 目前,您無法將在內部部署或任何其他雲端中執行的現有 Postgres 執行個體「上架到 Azure Arc」。 換句話說,您無法在現有的 Postgres 執行個體上安裝某些類型的「Azure Arc 代理程式」,使其成為已啟用 Azure Arc 的 Postgres 設定。相反地,您必須建立新的 Postgres 執行個體,並將資料傳輸到其中。 您可以使用上述技術來執行這項操作,也可以使用您選擇的任何 ETL 工具。

* 在這些文件中,略過登入 Azure 入口網站建立適用於 PostgreSQL 的 Azure 資料庫等章節。 在 Azure Arc 部署中實作其餘步驟。 這幾節專屬於 Azure 雲端中以 PaaS 服務的形式提供的適用於 PostgreSQL 的 Azure 資料庫伺服器,但文件的其他部分則直接適用於已啟用 Azure Arc 的 PostgreSQL 伺服器。