快速入门:使用 Azure 门户创建 Azure Database for PostgreSQL 服务器Quickstart: Create an Azure Database for PostgreSQL server by using the Azure portal

用于 PostgreSQL 的 Azure 数据库是一种托管服务,可用于在云中运行、管理和缩放具有高可用性的 PostgreSQL 数据库。Azure Database for PostgreSQL is a managed service that you use to run, manage, and scale highly available PostgreSQL databases in the cloud. 本快速入门介绍如何创建单个 Azure Database for PostgreSQL 服务器并与其连接。This quickstart shows you how to create a single Azure Database for PostgreSQL server and connect to it.


需要一个 Azure 订阅。An Azure subscription is required. 如果没有 Azure 订阅,请在开始前创建一个试用 Azure 帐户If you don't have an Azure subscription, create a trial Azure account before you begin.

创建 Azure Database for PostgreSQL 服务器Create an Azure Database for PostgreSQL server

转到 Azure 门户创建 Azure Database for PostgreSQL 单一服务器数据库。Go to the Azure portal to create an Azure Database for PostgreSQL Single Server database. 搜索并选择 Azure Database for PostgreSQL 服务器。Search for and select Azure Database for PostgreSQL servers.

查找 Azure Database for PostgreSQL。

  1. 选择 添加Select Add.

  2. 在“创建 Azure Database for PostgreSQL”页面上,选择“单一服务器”。On the Create a Azure Database for PostgreSQL page , select Single server.


  3. 现在将以下内容输入“基本信息”窗体。Now enter the Basics form with the following information.


    设置Setting 建议的值Suggested value 描述Description
    订阅Subscription 订阅名称your subscription name 选择所需的 Azure 订阅。select the desired Azure Subscription.
    资源组Resource group myresourcegroupmyresourcegroup 新的资源组,或订阅中的现有资源组。A new or an existing resource group from your subscription.
    服务器名称Server name mydemoservermydemoserver 用于标识用于 PostgreSQL 的 Azure 数据库服务器的唯一名称。A unique name that identifies your Azure Database for PostgreSQL server. 域名 postgres.database.chinacloudapi.cn 将追加到所提供的服务器名称后面。The domain name postgres.database.chinacloudapi.cn is appended to the server name that you provide. 服务器名称只能包含小写字母、数字和连字符 (-) 字符。The server can contain only lowercase letters, numbers, and the hyphen (-) character. 必须包含 3 到 63 个字符。It must contain 3 to 63 characters.
    数据源Data source None 选择“无”,从头开始创建新的服务器 。Select None to create a new server from scratch. 仅当从现有服务器的异地备份进行还原时,才选择“备份”。Select Backup only if you were restoring from a geo-backup of an existing server.
    管理员用户名Admin username myadminmyadmin 输入服务器管理员用户名。Enter your server admin username. 它不能以 pg_ 开头,并且不允许以下值:azure_superuser、azure_pg_admin、admin、administrator、root、guest 或 public 。It can't start with pg_ and these values are not allowed: azure_superuser, azure_pg_admin, admin, administrator, root, guest, or public.
    密码Password 你的密码your password 服务器管理员用户的新密码。A new password for the server admin user. 密码必须包含以下三个类别的 8 到 128 个字符:英文大写字母、英文小写字母、数字(0 到 9)和非字母数字字符(例如 !、$、#、%)。It must contain 8 to 128 characters from three of the following categories: English uppercase letters, English lowercase letters, numbers (0 through 9), and non-alphanumeric characters (for example, !, $, #, %).
    位置Location 你所需的位置your desired location 从下拉列表中选择一个位置。Select a location from the dropdown list.
    版本Version 最新主版本The latest major version 除非另有特定的要求,否则为最新 PostgreSQL 主版本。The latest PostgreSQL major version, unless you have specific requirements otherwise.
    计算 + 存储Compute + storage 使用默认值use the defaults 默认定价层是“常规用途”,其中包含 4 个 vCore 和 100 GB 存储 。The default pricing tier is General Purpose with 4 vCores and 100 GB storage. 备份保留期设置为 7 天,并提供“异地冗余”备份选项 。Backup retention is set to 7 days with Geographically Redundant backup option.
    了解定价并按需更新默认值。Learn about the pricing and update the defaults if needed.


    如果轻量级计算和 I/O 足以满足工作负荷要求,请考虑使用“基本”定价层。Consider using the Basic pricing tier if light compute and I/O are adequate for your workload. 请注意,在“基本”定价层中创建的服务器以后不能扩展到“常规用途”或“内存优化”定价层。Note that servers created in the Basic pricing tier can't later be scaled to General Purpose or Memory Optimized.

  4. 选择“查看 + 创建”,查看所选内容。Select Review + create to review your selections. 选择“创建”以预配服务器。Select Create to provision the server. 此操作可能需要几分钟时间。This operation might take a few minutes.


    将创建一个空数据库“postgres”。An empty database, postgres, is created. 你还会发现一个 azure_maintenance 数据库,用于将托管服务进程与用户操作分开。You'll also find an azure_maintenance database that's used to separate the managed service processes from user actions. 你不能访问 azure_maintenance 数据库。You can't access the azure_maintenance database.


配置防火墙规则Configure a firewall rule

默认情况下,你创建的服务器不可公开访问。By default, the server that you create is not publicly accessible. 需要向你的 IP 地址授予权限。You need to give permissions to your IP address. 请转到 Azure 门户中的服务器资源,然后从左侧菜单中为服务器资源选择“连接安全性”。Go to your server resource in the Azure portal and select Connection security from left-side menu for your server resource. 如果你不确定如何找到资源,请参阅打开资源If you're not sure how to find your resource, see Open resources.


选择“添加当前客户端 IP 地址”,然后选择“保存” 。Select Add current client IP address, and then select Save. 你可以添加更多 IP 地址或提供一个 IP 范围,从该范围中的 IP 地址连接到服务器。You can add more IP addresses or provide an IP range to connect to your server from those IP addresses. 有关详细信息,请参阅 Azure Database for PostgreSQL 中的防火墙规则For more information, see Firewall rules in Azure Database for PostgreSQL.


若要避免连接问题,请检查你的网络是否允许通过端口 5432 进行出站通信。To avoid connectivity issues, check if your network allows outbound traffic over port 5432. Azure Database for PostgreSQL 使用该端口。Azure Database for PostgreSQL uses that port.

通过 psql 连接到服务器Connect to the server with psql

可以使用 psqlpgAdmin,它们都是热门 PostgreSQL 客户端。You can use psql or pgAdmin, which are popular PostgreSQL clients.

  1. 通过服务器的“概述”部分,记录新创建的服务器的服务器名称、服务器管理员登录名、密码和订阅 ID。Make a note of your server name, server admin login name, password, and subscription ID for your newly created server from the Overview section of your server.


  2. 运行以下命令。Run the following command. 将值替换为实际的服务器名称和管理员用户登录名。Replace values with your actual server name and admin user login name. 以管理员用户的身份使用空数据库 postgres,格式如下:<admin-username>@<servername>Use the empty database postgres with admin user in this format: <admin-username>@<servername>.

    psql --host=mydemoserver.postgres.database.chinacloudapi.cn --port=5432 --username=myadmin@mydemoserver --dbname=postgres
  3. 在同一个 Shell 终端中,创建一个名为“guest”的数据库。In the same Shell terminal, create a database called guest.

    postgres=> CREATE DATABASE guest;
  4. 切换为与新创建的“guest”数据库的连接。Switch connections to the newly created guest database.

    \c guest
  5. 键入 \q,再按 Enter 键关闭 psql。Type \q, and then select the Enter key to close psql.

清理资源Clean up resources

现在已成功在资源组中创建了 Azure Database for PostgreSQL 服务器。You've successfully created an Azure Database for PostgreSQL server in a resource group. 如果将来不再需要这些资源,可以通过删除资源组或 PostgreSQL 服务器来删除它们。If you don't expect to need these resources in the future, you can delete them by deleting either the resource group or the PostgreSQL server.

若要删除资源组,请执行以下操作:To delete the resource group:

  1. 在 Azure 门户中,搜索并选择“资源组”。In the Azure portal, search for and select Resource groups.
  2. 在资源组列表中,选择你的资源组的名称。In the resource group list, choose the name of your resource group.
  3. 在资源组的“概述”页面中,选择“删除资源组” 。On the Overview page of your resource group, select Delete resource group.
  4. 在确认对话框中,输入资源组的名称,然后选择“删除”。In the confirmation dialog box, enter the name of your resource group, and then select Delete.

若要删除服务器,请在服务器的“概述”页面上选择“删除”按钮 :To delete the server, select the Delete button on the Overview page of your server:


后续步骤Next steps