使用 Azure CLI 管理 Azure Database for PostgreSQL 单一服务器Manage an Azure Database for PostgreSQL Single server using the Azure CLI

本文介绍如何管理 Azure 中部署的单一服务器。This article shows you how to manage your Single servers deployed in Azure. 管理任务包括计算和存储缩放、管理员密码重置,以及查看服务器详细信息。Management tasks include compute and storage scaling, admin password reset, and viewing server details.

先决条件Prerequisites

如果没有 Azure 订阅,请在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin. 本文要求在本地运行 Azure CLI 2.0 或更高版本。This article requires that you're running the Azure CLI version 2.0 or later locally. 若要查看安装的版本,请运行 az --version 命令。To see the version installed, run the az --version command. 如果需要进行安装或升级,请参阅安装 Azure CLIIf you need to install or upgrade, see Install Azure CLI.

你将需要使用 az login 命令登录到你的帐户。You'll need to log in to your account using the az login command. 请注意 id 属性,该属性指的是 Azure 帐户的订阅 ID。Note the id property, which refers to Subscription ID for your Azure account.

az login

使用 az account set 命令选择帐户下的特定订阅。Select the specific subscription under your account using az account set command. 记下 az login 输出中的 id 值,以用作命令中订阅参数的值。Make a note of the id value from the az login output to use as the value for subscription argument in the command. 如果有多个订阅,请选择应计费的资源所在的相应订阅。If you have multiple subscriptions, choose the appropriate subscription in which the resource should be billed. 若要获取所有订阅,请使用 az account listTo get all your subscription, use az account list.

az account set --subscription <subscription id>

如果尚未创建服务器,请参考此快速入门创建一个。If you have not already created a sever , refer to this quickstart to create one.

缩放计算和存储Scale compute and storage

可以使用以下命令轻松地纵向扩展定价层、计算和存储。You can scale up your pricing tier , compute and storage easily using the following command. 可以参阅 az postgres server 概述,了解可执行的所有服务器操作You can see all the server operation you can perform az postgres server overview

az postgres server update --resource-group myresourcegroup --name mydemoserver --sku-name GP_Gen5_4 --storage-size 6144

下面是上述参数的详细信息:Here are the details for arguments above :

设置Setting 示例值Sample value 说明Description
namename mydemoservermydemoserver 输入 Azure Database for PostgreSQL 服务器的唯一名称。Enter a unique name for your Azure Database for PostgreSQL server. 服务器名称只能包含小写字母、数字和连字符 (-) 字符。The server name can contain only lowercase letters, numbers, and the hyphen (-) character. 必须包含 3 到 63 个字符。It must contain from 3 to 63 characters.
resource-groupresource-group myresourcegroupmyresourcegroup 提供 Azure 资源组的名称。Provide the name of the Azure resource group.
sku-namesku-name GP_Gen5_2GP_Gen5_2 输入定价层和计算配置的名称。Enter the name of the pricing tier and compute configuration. 请遵循简写约定 {pricing tier} {compute generation} {vCores}。Follows the convention {pricing tier} {compute generation} {vCores} in shorthand. 有关详细信息,请参阅定价层See the pricing tiers for more information.
storage-sizestorage-size 61446144 服务器的存储容量(以 MB 为单位)。The storage capacity of the server (unit is megabytes). 最小值为 5120,以 1024 为增量递增。Minimum 5120 and increases in 1024 increments.

重要

  • 存储可以纵向扩展(但不能纵向缩减)Storage can be scaled up (however, you cannot scale storage down)
  • 不支持从“基本”定价层纵向扩展到“常规用途”或“内存优化”定价层。Scaling up from Basic to General purpose or Memory optimized pricing tier is not supported. 可以使用 bash 脚本使用 PostgreSQL Workbench 进行手动纵向扩展You can manually scale up with either using a bash script or using PostgreSQL Workbench

管理服务器上的 PostgreSQL 数据库。Manage PostgreSQL databases on a server.

可以使用以下任何命令来创建、删除、列出和查看服务器上数据库的数据库属性You can use any of these commands to create, delete , list and view database properties of a database on your server

CmdletCmdlet 使用情况Usage 说明Description
az postgres db createaz postgres db create az postgres db create -g myresourcegroup -s mydemoserver -n mydatabasename 创建数据库Creates a database
az postgres db deleteaz postgres db delete az postgres db delete -g myresourcegroup -s mydemoserver -n mydatabasename 从服务器中删除数据库。Delete your database from your server. 此命令不会删除服务器。This command does not delete your server.
az postgres db listaz postgres db list az postgres db list -g myresourcegroup -s mydemoserver 列出服务器上的所有数据库lists all the databases on the server
az postgres db showaz postgres db show az postgres db show -g myresourcegroup -s mydemoserver -n mydatabasename 显示数据库的更多详细信息Shows more details of the database

更新管理员密码Update admin password

可以使用此命令更改管理员角色的密码You can change the administrator role's password with this command

az postgres server update --resource-group myresourcegroup --name mydemoserver --admin-password <new-password>

重要

请确保密码至少有 8 个字符,至多有 128 个字符。Make sure password is minimum 8 characters and maximum 128 characters. 密码必须包含以下类别中的三个类别的字符:英文大写字母、英文小写字母、数字和非字母数字字符。Password must contain characters from three of the following categories: English uppercase letters, English lowercase letters, numbers, and non-alphanumeric characters.

删除服务器Delete a server

如果只想删除 PostgreSQL 单一服务器,可运行 az postgres server delete 命令。If you would just like to delete the PostgreSQL Single server, you can run az postgres server delete command.

az postgres server delete --resource-group myresourcegroup --name mydemoserver

后续步骤Next steps