快速入門:使用ARM範本建立 適用於 PostgreSQL 的 Azure 資料庫 - 彈性伺服器實例

適用範圍:適用於 PostgreSQL 的 Azure 資料庫 - 彈性伺服器

適用於 PostgreSQL 的 Azure 資料庫 彈性伺服器是您用來在雲端中執行、管理及調整高可用性 PostgreSQL 資料庫的受控服務。 您可以使用 Azure Resource Manager 範本 (ARM 範本) 來布建 適用於 PostgreSQL 的 Azure 資料庫 彈性伺服器實例,以在伺服器上部署多部伺服器或多個資料庫。

Azure Resource Manager 範本是 JavaScript 物件表示法 (JSON) 檔案,可定義專案的基礎結構和組態。 範本使用宣告式語法。 您不需要撰寫程式設計命令順序來建立部署,即可描述預定的部署。

Azure Resource Manager 是 Azure 的部署與管理服務。 其提供一個管理層,讓您能夠在 Azure 帳戶中建立、更新及刪除資源。 您可使用存取控制、鎖定與標籤等管理功能,在部署之後保護及組織資源。 若要瞭解 Azure Resource Manager 範本,請參閱 範本部署概觀

必要條件

具有有效訂用帳戶的 Azure 帳戶。 免費建立一個

檢閱範本

適用於 PostgreSQL 的 Azure 資料庫 彈性伺服器實例是區域內一或多個資料庫的父資源。 它提供套用至其資料庫之管理原則的範圍:登入、防火牆、使用者、角色和設定。

建立 postgres-flexible-server-template.json 檔案,並將下列 JSON 腳本複製到其中。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "administratorLogin": {
      "type": "string"
    },
    "administratorLoginPassword": {
      "type": "secureString"
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    },
    "serverName": {
      "type": "string"
    },
    "serverEdition": {
      "type": "string",
      "defaultValue": "GeneralPurpose"
    },
    "skuSizeGB": {
      "type": "int",
      "defaultValue": 128
    },
    "dbInstanceType": {
      "type": "string",
      "defaultValue": "Standard_D4ds_v4"
    },
    "haMode": {
      "type": "string",
      "defaultValue": "ZoneRedundant"
    },
    "availabilityZone": {
      "type": "string",
      "defaultValue": "1"
    },
    "version": {
      "type": "string",
      "defaultValue": "16"
    },
    "virtualNetworkExternalId": {
      "type": "string",
      "defaultValue": ""
    },
    "subnetName": {
      "type": "string",
      "defaultValue": ""
    },
    "privateDnsZoneArmResourceId": {
      "type": "string",
      "defaultValue": ""
    }
  },
  "resources": [
    {
      "type": "Microsoft.DBforPostgreSQL/flexibleServers",
      "apiVersion": "2022-12-01",
      "name": "[parameters('serverName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('dbInstanceType')]",
        "tier": "[parameters('serverEdition')]"
      },
      "properties": {
        "version": "[parameters('version')]",
        "administratorLogin": "[parameters('administratorLogin')]",
        "administratorLoginPassword": "[parameters('administratorLoginPassword')]",
        "network": {
          "delegatedSubnetResourceId": "[if(empty(parameters('virtualNetworkExternalId')), json('null'), json(format('{0}/subnets/{1}', parameters('virtualNetworkExternalId'), parameters('subnetName'))))]",
          "privateDnsZoneArmResourceId": "[if(empty(parameters('virtualNetworkExternalId')), json('null'), parameters('privateDnsZoneArmResourceId'))]"
        },
        "highAvailability": {
          "mode": "[parameters('haMode')]"
        },
        "storage": {
          "storageSizeGB": "[parameters('skuSizeGB')]"
        },
        "backup": {
          "backupRetentionDays": 7,
          "geoRedundantBackup": "Disabled"
        },
        "availabilityZone": "[parameters('availabilityZone')]"
      }
    }
  ]
}

範本中定義了下列資源:

部署範本

從下列 PowerShell 程式代碼區塊中選取 [試用] 以開啟 Azure Cloud Shell。

$serverName = Read-Host -Prompt "Enter a name for the new Azure Database for PostgreSQL flexible server instance"
$resourceGroupName = Read-Host -Prompt "Enter a name for the new resource group where the server will exist"
$location = Read-Host -Prompt "Enter an Azure region (for example, centralus) for the resource group"
$adminUser = Read-Host -Prompt "Enter the Azure Database for PostgreSQL flexible server instance's administrator account name"
$adminPassword = Read-Host -Prompt "Enter the administrator password" -AsSecureString

New-AzResourceGroup -Name $resourceGroupName -Location $location # Use this command when you need to create a new resource group for your deployment
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName `
    -TemplateFile "postgres-flexible-server-template.json" `
    -serverName $serverName `
    -administratorLogin $adminUser `
    -administratorLoginPassword $adminPassword

Read-Host -Prompt "Press [ENTER] to continue ..."

檢閱已部署的資源

請遵循下列步驟來確認您的伺服器是否已在 Azure 中建立。

適用範圍:適用於 PostgreSQL 的 Azure 資料庫 - 彈性伺服器

  1. 在 Azure 入口網站 中,搜尋並選取 [適用於 PostgreSQL 的 Azure 資料庫 彈性伺服器]。
  2. 在資料庫清單中,選取您的新伺服器以檢視要管理伺服器的 [ 概觀 ] 頁面。

清除資源

若要移至後續步驟,請保留此資源群組、伺服器和單一資料庫。 後續步驟會示範如何使用不同的方法來連線和查詢資料庫。

刪除資源群組:

適用範圍:適用於 PostgreSQL 的 Azure 資料庫 - 彈性伺服器

在入口網站,選取您想要刪除的資源群組。

  1. 選取 [刪除資源群組]
  2. 若要確認刪除,請輸入資源群組的名稱。

下一步