使用 psql 连接到群集 - 适用于 PostgreSQL 的 Azure Cosmos DB

适用对象: Azure Cosmos DB for PostgreSQL(由 PostgreSQL 的 Citus 数据库扩展提供支持)

本快速入门演示如何在 Azure CLI 中使用 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.chinacloudapi.cn port=5432 dbname=citus user=citus password={your_password} sslmode=require"。 请注意,主机名以 c. 开头,例如 c-mycluster.12345678901234.postgres.cosmos.azure.cn。 此前缀指示群集的协调器节点。 dbname 的默认值为 citus,只能在预配群集时更改。 user 可以是群集上任何有效的 Postgres 角色

  2. 打开本地 CLI。

  3. 将 psql 连接字符串粘贴到 CLI 终端中。

  4. 在连接字符串中,将 {your_password} 替换为群集密码,然后按 Enter。

    Screenshot that shows running psql in the Azure CLI.

    当 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)
    

后续步骤

现在,你已连接到群集,下一步是创建表并将其分片以进行水平缩放。