快速入门:使用 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 门户在约 5 分钟内创建单个 Azure Database for PostgreSQL 服务器。This quickstart shows you how to create a single Azure Database for PostgreSQL server in about five minutes by using the Azure portal.

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

登录到 Azure 门户Sign in to the Azure portal

打开 Web 浏览器并转到门户Open your web browser and go to the portal. 输入登录到门户所需的凭据。Enter your credentials to sign in to the portal. 默认视图是服务仪表板。The default view is your service dashboard.

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

创建的 Azure Database for PostgreSQL 服务器中包含一组已配置的计算和存储资源An Azure Database for PostgreSQL server is created with a configured set of compute and storage resources. 将在 Azure 资源组中创建服务器。The server is created within an Azure resource group.

创建 Azure Database for PostgreSQL 服务器:To create an Azure Database for PostgreSQL server:

  1. 在门户左上角选择“创建资源”。Select Create a resource in the upper-left corner of the portal.

  2. 选择“数据库” > “用于 PostgreSQL 的 Azure 数据库”。Select Databases > Azure Database for PostgreSQL .

    显示菜单上的“Azure Database for PostgreSQL”的屏幕截图。

  3. 选择“单个服务器”部署选项。Select the Single server deployment option.

    为 Azure Database for PostgreSQL 选择单个服务器部署选项的屏幕截图。

  4. 用以下信息填写“基本”表单。Fill out the Basics form with the following information.


    设置Setting 建议的值Suggested value 说明Description
    订阅Subscription 订阅名称Your subscription name 要用于服务器的 Azure 订阅。The Azure subscription that you want to use for your server. 如果有多个订阅,请选择要计费的资源所在的订阅。If you have multiple subscriptions, choose the subscription in which you're billed for the resource.
    资源组Resource group myresourcegroupmyresourcegroup 新的资源组名称,或订阅中的现有资源组。A new resource group name or an existing one 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. (如果是从现有 Azure Database for PostgreSQL 服务器的异地备份创建服务器,则会选择“备份”。)(You would select Backup if you were creating a server from a geo-backup of an existing Azure Database for PostgreSQL server.)
    管理员用户名Admin username myadminmyadmin 连接到服务器时使用的自己的登录帐户。Your own login account to use when you connect to the server. 管理员登录名不能是 azure_superuserazure_pg_adminadminadministratorrootguestpublicThe admin login name can't be azure_superuser , azure_pg_admin , admin , administrator , root , guest , or public . 不能以 pg_ 开头。It can't start with pg_ .
    密码Password 你的密码Your password 服务器管理员帐户的新密码。A new password for the server admin account. 密码必须包含以下三个类别的 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 离用户最近的区域The region closest to your users 最靠近用户的位置。The location that's closest to your users.
    版本Version 最新主版本The latest major version 除非另有特定的要求,否则为最新 PostgreSQL 主版本。The latest PostgreSQL major version, unless you have specific requirements otherwise.
    计算 + 存储Compute + storage 常规用途第 5 代2 vCore5 GB7 天异地冗余General Purpose , Gen 5 , 2 vCores , 5 GB , 7 days , Geographically Redundant 新服务器的计算、存储和备份配置。The compute, storage, and backup configurations for your new server. 选择“配置服务器”。Select Configure server . 接下来,选择适当的定价层。Next, select the appropriate pricing tier. 有关详细信息,请参阅定价详细信息For more information, see pricing details. 若要在异地冗余存储中启用服务器备份,请从 备份冗余选项 中选择“异地冗余”。To enable your server backups in geo-redundant storage, select Geographically Redundant from the Backup Redundancy Options . 选择“确定”。Select OK .


    如果轻量级计算和 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.

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

  6. 在工具栏上选择“通知”图标(铃铛)以监视部署过程。On the toolbar, select the Notifications icon (a bell) to monitor the deployment process. 部署完成后,选择“转到资源”,打开服务器的“概览”页面 。After the deployment is complete, select Go to resource to open the server's Overview page.

将创建一个空数据库“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 server-level 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 连接到 Azure Database for PostgreSQL 服务器Connect to Azure Database for PostgreSQL server by using 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