使用 psql 連線至叢集 - 適用於 PostgreSQL 的 Azure Cosmos DB

適用於: Azure Cosmos DB for PostgreSQL (由 PostgreSQL 的超大規模 (Citus) 資料庫延伸模組提供)

此快速入門說明如何使用 Azure Cloud Shell (英文) 中的psql 連接字串來連線到 Azure Cosmos DB for PostgreSQL 叢集。

必要條件

連線

您的叢集具有名為 citus 的預設資料庫。 若要連線到該資料庫,您會使用連接字串和系統管理員密碼。

  1. 在 Azure 入口網站的叢集頁面上,選取 [連接字串] 功能表項目,然後複製 psql 連接字串。

    Screenshot that shows copying the psql connection string.

    psql 字串的格式為 psql "host=c-<cluster>.<uniqueID>.postgres.cosmos.azure.com port=5432 dbname=citus user=citus password={your_password} sslmode=require"。 請注意,主機名稱開頭為 c.,例如 c-mycluster.12345678901234.postgres.cosmos.azure.com。 此前置詞表示該叢集的協調器節點。 預設 dbnamecitus,且只能在叢集佈建時間進行變更。 user 可以是叢集上任何有效的 Postgres 角色

  2. 選取頂端功能表列中的 Cloud Shell 圖示來開啟 Azure Cloud Shell。

    Screenshot that shows the Cloud Shell icon.

    如果出現提示,請選擇要在其中儲存 Cloud Shell 資料的 Azure 訂用帳戶。

  3. 將 psql 連接字串貼到殼層中。

  4. 在連接字串中,以您的叢集密碼取代 {your_password},然後按 Enter。

    Screenshot that shows running psql in the Cloud Shell.

    當 psql 成功連線到資料庫時,您會看到新的 citus=> (或您的資料庫自訂名稱) 提示:

    psql (14.2, server 14.5)
    SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
    Type "help" for help.
    
    citus=>
    
  5. 執行測試查詢。 將下列命令貼到 psql 提示字元中,然後按 Enter。

    SHOW server_version;
    

    您應該會看到符合您在叢集建立期間所選取之 PostgreSQL 版本的結果。 例如:

     server_version
    ----------------
     14.5
    (1 row)
    

下一步

既然您已連線到叢集,下一個步驟就是建立資料表,並將其分區以進行水平調整。